Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
This code is copy-pasted fromthis SO question.
Bug report
Bug summary
Creating a secondary axis and calling the.grid()
method on it does not draw a grid. If it should not draw grid, it should throw an Exception.
Code for reproduction
importmatplotlib.pyplotaspltimportnumpyasnpdefget_data_and_ticks():# generate dummy load duration curvedur=2500y=np.random.normal(60,30,dur+1)y[::-1].sort()x=range(0,dur+1)perticks=np.linspace(0,1,11)xticks=perticks*duryticks=np.interp(xticks,range(0,dur+1),y)returnx,y,xticks,yticksx,y,xticks,yticks=get_data_and_ticks()# create figure object with axe objectfig,ax1=plt.subplots(figsize=(10,7))ax1.plot(x,y)# create second axiscolor="tab:blue"ax2=ax1.secondary_yaxis("right")ax2.set_yticks(yticks)ax2.set_yticklabels(labels=[f"{i*10}%"foriinrange(11)])ax2.tick_params(axis="y",color=color,labelcolor=color)# draw grid lines on the secondaryaxis# The problem is at this lineax2.grid(color=color,which="major",linestyle="--")plt.show()
Actual outcome
Expected outcome
Alternative A
draw a figure like this:
Alternative B
Raise an exception and tell the user thatSecondaryAxis.grid()
is not supported.
Matplotlib version
- Operating system: Windows 10
- Matplotlib version: 3.3.3
- Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg - Python version: 3.8.6 64-bit
Same applies if a SecondaryAxis is created forx
(ax1.secondary_xaxis("top")
)