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

The original xlim changed by twinx #6860

Closed
Labels
Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
Milestone
@fjdu

Description

@fjdu
  • Matplotlib version: 1.4.3
  • Python version: Python 2.7.11 :: Anaconda 2.3.0 (x86_64)
  • Platform: OSX 10.11.5

The issue: when making a twinx of the original axis with xlim and ylim explicitly set, the twinx axis and the plotting actions that follow will change the xlim of the original plot. "Semantically", all the plots are still correct, but I doubt whether this is the intended behavior.

This can sometimes leads toserious confusions. One example is when the axis (and its twinx) is part of an axes grid, and when its xticklabels are set to be invisible (which is common in a regular grid of axes). In this case, plotting actions with twinx will change the x axis range implicitly and unknowingly, hence changing the alignment with other axes, making the quantitative interpretation of the plots impossible.

From thesource code of twinx it is clear to me that the twinx only "inherits" the position of the original axis. I am thinking that it might be more helpful if it inherits all the properties of the original x axis.

See the following examples.

# This (x, y) pair will be used in all the following examplesx=array([-2,0,2,4])y=0.3*x+0.2fig=figure()# This xlim and ylim are explicitly set, and I expect them not to be altered unless I explicitly do so.ax=fig.add_axes((0.1,0.1,0.8,0.8),xlim=(0,2),ylim=(0,1),autoscalex_on=False,autoscaley_on=False)ax.plot(x,y,color='blue',lw=10)

image

fig=figure()ax=fig.add_axes((0.1,0.1,0.8,0.8),xlim=(0,2),ylim=(0,1),autoscalex_on=False,autoscaley_on=False)ax.plot(x,y,color='blue',lw=10)ax=twinx(ax)ax.plot(x,y,color='red',lw=5)# I would expect the two lines to overlap, but they don't.# Both xlim and ylim are changed.# Note that the blue line and the red line are still "semantically" correct.

image

fig=figure()ax=fig.add_axes((0.1,0.1,0.8,0.8),xlim=(0,2),ylim=(0,1),autoscalex_on=False,autoscaley_on=False)ax.plot(x,y,color='blue',lw=10)ax=twinx(ax)ax.plot(x,y,color='red',lw=5)ax.set_xlim((0,2))# This one is acceptible, since the twinx axis has the same xlim as the original one,# though I expected that this should be the default behavior (without manually setting xlim).

image

fig=figure()ax=fig.add_axes((0.1,0.1,0.8,0.8),xlim=(0,2),ylim=(0,1),autoscalex_on=False,autoscaley_on=False)ax.plot(x,y,color='blue',lw=10)ax=twinx(ax)ax.plot(x,y,color='red',lw=5)ax.set_ylim((0,1))# In this case the two lines overlap, but the original xlim is changed.

image

fig=figure()ax=fig.add_axes((0.1,0.1,0.8,0.8),xlim=(0,2),ylim=(0,1),autoscalex_on=False,autoscaley_on=False)ax.plot(x,y,color='blue',lw=10)ax=twinx(ax)ax.plot(x,y,color='red',lw=5)ax.set_ylim((0,1))ax.set_xlim((0,2))# This is what I expected in the beginning.# Basically, I do not expect the twinx to change the original xlim# (and any other properties of the x axis).

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp