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

Crash when creating polar plot with log scale on radial axis #1847

Closed
cfinch opened this issue Mar 22, 2013 · 8 comments
Closed

Crash when creating polar plot with log scale on radial axis #1847

cfinch opened this issue Mar 22, 2013 · 8 comments
Milestone

Comments

@cfinch
Copy link

cfinch commented Mar 22, 2013

matplotlib will crash when a log scale is used for the radial axis of a polar plot, unless very specific commands are used to create the plot. The following code will cause a crash:

import numpy as np
import matplotlib.pyplot as plt

theta = np.arange(0.0, 2 * np.pi, 0.05)
r = np.arange(0.1, 100.0, 100.0 / len(theta))

plt.figure()
ax = plt.subplot(111, polar=True, projection='polar')
ax.set_rlim((0.1, 100.0))
ax.set_rscale('log')
plt.polar(theta, r)

plt.savefig('test.pdf', format='pdf')
plt.show()

However, if ax.set_rlim((0.1, 100.0)) is changed to ax.set_rlim((0., 100.0)) the plot is created and there is no error or warning. The plot will also crash if the set_rlim method is not called before set_rscale. Using set_ylim or set_yscale results in the same behavior.

Note that this issue is not specific to a particular backend, as it occurs when saving the figure as a PDF or displaying it in a window with gtkagg.

Other users have this problem; see http://stackoverflow.com/questions/14919407/how-to-use-log-scale-on-polar-axis-in-matplotlib

@amill676
Copy link

Any progress on this? This is pretty frustrating, as the polar log plots seem to be useless.

@efiring
Copy link
Member

efiring commented Dec 15, 2013

Your example does not crash for me, running 1.4.x. What versions have you tried?

@amill676
Copy link

I was able to get the code running, but the problem I was running into was discussed in one of the followups of that stack overflow discussion. The log polar plots were plotting 'negative' radii. However, I updated to the latest matplotlib, and it doesn't appear to be doing this anymore, although how set_rlim/set_rmax/set_rmin exactly affects the scaling of the plot seems kind of convoluted. However, with enough toying I can get the results I want.

@amill676
Copy link

In fact, it seems that set_rlim(0,1) will result in limits (u, 1), where u > 0 (.01 in my case), but set_rmin(0), set_rmax(1) will give the intended behavior.

@efiring
Copy link
Member

efiring commented Dec 15, 2013

With a log scale on the radial axis, a lower limit of zero makes no sense at all; what is the intended behavior to which you refer?

@amill676
Copy link

From what I've seen, setting the lower limit to 0 and the maximum limit to some value > 0 will give a plot that goes from the lowest data value given to the maximum limit supplied. But when setting rmin to something less than the lowest data value given, the bounds are no longer obeyed. So in that sense, I guess by a lower limit of 0 I just meant fitting the bound to the lower range of the data. Which has seemed hard to achieve otherwise. Unless I'm missing something

@tacaswell
Copy link
Member

Reading through this again, it looks like the original problem has been (mysteriously?) fixed. From reading this + the SO thread I am having trouble sorting out exactly what is wrong so I am closing this issue.

@amill676 @cfinch If you are still having problems please open a new issue.

@cfinch
Copy link
Author

cfinch commented Jul 24, 2014

The issue is resolved for me.

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

No branches or pull requests

6 participants