windrose
windrose copied to clipboard
Grid under bar plot
How do I put the grid lines under the bar plot ?
I have tried to play with the zorders, as well as with a.set_axisbelow(True)
, but it did not change anything.
Hello,
Windrose changes the base Zorder for every drawing to default to -1000, in order to have the grid on. Otherwise, strange things happen for the yticklabels:
the ax.set_axisbelow(True)
simply put all axis zorder to 0.5, which is still faaar from the -1000...
So if you want to put the grid behind, you have to put to a zorder value lower than -1000.
If you look at the set_axisbelow code, you will see that it is simply a wrapper around axis.set_zorder
. So simply write it yourself after your plot
for axis in ax._get_axis_list():
axis.set_zorder(-2000) # or every thing lower than -1000
self.stale = True
Closing this as answered. Please re-open if you disagree,
this solution seems incomplete;
import numpy as np
N = 500
ws = np.random.random(N) * 6
wd = np.random.random(N) * 360
from windrose import WindroseAxes
ax = WindroseAxes.from_ax()
ax.bar(wd, ws, normed=True, opening=0.8, edgecolor="white")
ax.set_legend()
for axis in ax._get_axis_list():
axis.set_zorder(-2000) # or every thing lower than -1000
gives the error AttributeError: 'WindroseAxes' object has no attribute '_get_axis_list'
Am I missing something?
Hello, What's your version of matplotlib and windrose ? It works fine on matplotlib==3.3.4 and windrose==1.9.0
Hello, Im having the same issue. Im using matplotlib 3.7.2 and windrose 1.7.0 since anaconda(spyder) doesn't have the windrose 1.9.0. Can someone help?
It seems that ax._get_axis_list()
has been removed in recent versions of matpotlib
.
Use instead:
import numpy as np
import matplotlib.pyplot as plt
N = 500
ws = np.random.random(N) * 6
wd = np.random.random(N) * 360
from windrose import WindroseAxes
ax = WindroseAxes.from_ax()
a = ax.bar(wd, ws, normed=True, opening=0.8, edgecolor="white")
ax.set_legend()
for axis in [ax.get_xaxis(), ax.get_yaxis()]:
axis.set_zorder(-2000)
plt.show()
Note that this pushed the whole xaxis
at zorder = -2000
, not only just the gridlines. Interestingly, this should only affect the gridlines:
for line in ax.get_xgridlines() + ax.get_ygridlines():
line.set_zorder(-2000)
line.set_color('r')
but in fact, does not change the zorder of the gridlines. It will however change their colour (you can also change any line properties this way.
Thank you very much @Cgadal ! Problem solved :)