'Mplstereonet azimuth labels
For my thesis I use the mplstereonet package to plot stereographic projections of points and planes obtained by using the ObsPy package. For my application I want to use azimuth labels that plot at a given angle outside of the circle. I am not using axis labels since they may overlap with possible data points in the centre of the circle.
The arguments of the set_azimuth_ticks function are:
- positions of ticks around the circle in degrees
- labels of ticks
- distance of ticks from the circle. 1 is on, 0.9 is inside and 1.1 is outside the circle.
This is the code I use alongside my result: I obtain this result:
As you can see the labels are way too far from the circle.
import mplstereonet
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111, projection='stereonet')
ax.grid()
ax.set_azimuth_ticks([0],['N'], frac = 0.9)
Solution 1:[1]
I'm noticing a difference in behaviour between a python3.7 environment (which places the labels where I expect them) and a python 3.9 environment where they are too far out as the original poster observed. As a workaround, I am using this:
import mplstereonet as mpls
fig, ax = mpls.subplots(figsize=[5, 5])
ax.set_azimuth_ticks([])
just to remove the unsightly, bizarrely far away labels.
Solution 2:[2]
I was experiencing same issue as OP even in python3.7. My workaround, if labels are desired, uses ax.text with ax.transAxes transformation to position labels wrt plot axes. Remove bad labels as previous answer and add the following:
...
label = np.arange(0,360,45)
labx= 0.5-0.55*np.cos(np.radians(label+90))
laby= 0.5+0.55*np.sin(np.radians(label+90))
for i in range(len(label)):
ax.text(labx[i],laby[i],str(int(label[i]))+'\N{DEGREE SIGN}', \
transform=ax.transAxes, ha='center', va='center')
Create a function with the code above if additional flexibility is needed. If you're plotting color bar or plot title you'll need to pad elements appropriately.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Caleb Pollock |