joferkington / mplstereonet

Stereonets for matplotlib
MIT License
188 stars 65 forks source link

Problem with ax.set_azimuth_ticks() #41

Open GlacialGeo opened 3 years ago

GlacialGeo commented 3 years ago

I was updating some stereonet subplots in Jupyter (that used to look fine) and after running the cell the degrees around the stereonets did not plot correctly as they used to. Instead of plotting around the edge of the stereonets, they plotted all around the frame of the four subplots. I then tried on a single stereonet and it was better, but the degrees were positioned quite far away from the edge of the stereonet and I could not adjust that position.

kaibro94 commented 3 years ago

I encountered exactly the same issue today, and I am using Spyder. The last time I used mplstereonet was in December 2020 and back then the error did not occur. Here is an example of the ticks and labels: grafik

JNDanielson commented 2 years ago

Ok, took me a while to figure out what was going on. I can suggest two workarounds to fix this issue:

  1. If "ax" is your stereonet axis, add the line "ax._polar.set_position(ax.get_position())" before calling plt.show()
  2. Downgrade matplotlib to version <3.4.0

mplstereonet makes a hidden polar axis within the stereonet axis as a bit of a kludge to add azimuth tick labels.

I think the issue is in mplstereonet/stereonet_axes.py line 291. Prior to matplotlib 3.4.0, fig.add_axes() used to detect if you were attempting to create Axes with the same keyword arguments as already-existing Axes in the current Figure, and if so, it would return the existing Axes. Now it will create a new axis. So changes to the size of the stereonet axis aren't matched by changes in the polar axis anymore. Workaround 1 manually matches any size changes that have occurred in the parent axis.

The matplotlib functionality change is documented here: https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.4.0.html#changes-to-behavior-of-axes-creation-methods-gca-add-axes-add-subplot