windrose icon indicating copy to clipboard operation
windrose copied to clipboard

Grid under bar plot

Open cgadal opened this issue 5 years ago • 1 comments

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.

cgadal avatar Dec 03 '19 10:12 cgadal

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:

image

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

weber-s avatar Sep 10 '20 12:09 weber-s

Closing this as answered. Please re-open if you disagree,

ocefpaf avatar Sep 22 '22 12:09 ocefpaf

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?

blaylockbk avatar Jul 15 '23 06:07 blaylockbk

Hello, What's your version of matplotlib and windrose ? It works fine on matplotlib==3.3.4 and windrose==1.9.0

weber-s avatar Jul 17 '23 07:07 weber-s

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?

MonkeyKingz avatar Jul 31 '23 12:07 MonkeyKingz

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.

cgadal avatar Aug 02 '23 09:08 cgadal

Thank you very much @Cgadal ! Problem solved :)

MonkeyKingz avatar Aug 02 '23 10:08 MonkeyKingz