Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SecondaryAxis.grid() fails silently #18941

Open
Labels
keepItems to be ignored by the “Stale” Github Action
@fohrloop

Description

@fohrloop

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

image

Expected outcome

Alternative A
draw a figure like this:

image

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"))

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepItems to be ignored by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp