Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
cfinch opened this Issue · 8 comments

4 participants

@cfinch

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

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

@efiring
Owner

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

@amill676

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

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
Owner

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

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 tacaswell added this to the v1.4.0 milestone
@tacaswell
Owner

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.

@tacaswell tacaswell closed this
@cfinch

The issue is resolved for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.