Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

range doesn't work, or am I making a mistake? #223

Closed
astronom-v-cube opened this issue Mar 19, 2023 · 4 comments · Fixed by #224
Closed

range doesn't work, or am I making a mistake? #223

astronom-v-cube opened this issue Mar 19, 2023 · 4 comments · Fixed by #224

Comments

@astronom-v-cube
Copy link

Greetings. I tried to use the range parameter according to the documentation:

A list where each element is either a length 2 tuple containing lower and upper bounds or a float in range (0., 1.) giving the fraction of samples to include in bounds, e.g., [(0.,10.), (1.,5), 0.999, etc.]. If a fraction, the bounds are chosen to be equal-tailed.

My array is called ranges and looks like this, for example: ranges = [(1000000, 1e+08), (3e+08, 7e+09), (0, 360), (0, 1000), (100000, 10000000)].
When I try to use a variable as a function corner.corner argument, I get an error:

Traceback (most recent call last):
  File "d:\Документы\solar_radio_diagnostics\using.py", line 66, in <module>
    gen.Generating(ngenerations=0, nchildren=5, sigmacoeff=2, points=2**5, method='new_random_first_gen', do_plot = True, refx = recoverable_params)
  File "d:\Документы\solar_radio_diagnostics\generatingModels.py", line 178, in Generating
    self.corner_plot(self.x, self.r, 0, ngenerations, nchildren, sigmacoeff, points, method)
  File "d:\Документы\solar_radio_diagnostics\generatingModels.py", line 43, in corner_plot
    corner.corner(data = x, weights = (1/r).ravel(), titles = titles, fig = corner_figure, truths = truths, title_fmt=None, show_titles = True, range=ranges) 
  File "C:\Users\astro\AppData\Roaming\Python\Python310\site-packages\corner\corner.py", line 226, in corner
    return corner_impl(
  File "C:\Users\astro\AppData\Roaming\Python\Python310\site-packages\corner\core.py", line 186, in corner_impl
    range=np.sort(range[i]),
  File "<__array_function__ internals>", line 180, in sort
  File "C:\Users\astro\AppData\Roaming\Python\Python310\site-packages\numpy\core\fromnumeric.py", line 1004, in sort
    a.sort(axis=axis, kind=kind, order=order)
numpy.AxisError: axis -1 is out of bounds for array of dimension 0

When substituting an array directly as an argument to a function call (range=[(1000000, 1e+08), (3e+08, 7e+09), (0, 360), (0, 1000), (100000, 10000000)]), I do not get an error, however, there is also no result.

My code, if necessary, you can see here

@dfm
Copy link
Owner

dfm commented Mar 21, 2023

Please put together a minimal, reproducible example that demonstrates the problem. Thanks!

@astronom-v-cube
Copy link
Author

astronom-v-cube commented Mar 26, 2023

Yes, I should have done it right away, sorry. The problem is that I couldn't reproduce this bug right away. Now, by the method of many attempts, I was able to find a situation where it manifests itself.
The root of the problem is exactly how to call figure, as an argument or as a variable.

import numpy as np
import corner
import matplotlib.pyplot as plt

data = np.random.normal(1, 300, size=(3000000, 4))
ranges = [(0, 800), (0, 900), (0, 750), (0, 350)]

fig_no_bug = corner.corner(data, range = ranges) 
plt.show()

fig_bug = plt.figure()
corner.corner(data, range = ranges, fig = fig_bug) 
plt.show()

The first method of calling works, the range is respected:
image

The second method of calling does not work, the range is not respected:
image

Another problem seems to be the use of the float type in range (360. and 360). However, this is easily solved by switching to int.

@dfm
Copy link
Owner

dfm commented Mar 27, 2023

Thanks for this example! I can reproduce the issue and I believe I know how to fix it. But...

Another problem seems to be the use of the float type in range (360. and 360). However, this is easily solved by switching to int.

Can you say more about what this issue is here? There shouldn't be any problems with using floats.

dfm added a commit that referenced this issue Mar 27, 2023
@dfm dfm closed this as completed in #224 Mar 27, 2023
dfm added a commit that referenced this issue Mar 27, 2023
* fixing #223

* removing hanging comments

* updating test
@dfm
Copy link
Owner

dfm commented Mar 27, 2023

This issue has been closed because the primary issue with range not being respected when a blank figure is an argument has been fixed in #224. But please feel free to provide more info about the data type problem you found or open a new issues. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants