-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
twinx / twiny inherit autoscale behavior for shared axis #7904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3904,16 +3904,16 @@ def twinx(self): | |
""" | ||
Create a twin Axes sharing the xaxis | ||
|
||
Create a twin of Axes for generating a plot with a shared | ||
x-axis but independent y-axis. The y-axis of self will have | ||
ticks on left and the returned axes will have ticks on the | ||
right. To ensure tick marks of both axis align, see | ||
Create a new Axes instance with an invisible x-axis and an independent | ||
y-axis positioned opposite to the original one (i.e. at right). The | ||
x-axis autoscale setting will be inherited from the original Axes. | ||
To ensure that the tick marks of both y-axes align, see | ||
`~matplotlib.ticker.LinearLocator` | ||
|
||
Returns | ||
------- | ||
Axis | ||
The newly created axis | ||
ax_twin : Axes | ||
The newly created Axes instance | ||
|
||
Notes | ||
----- | ||
|
@@ -3924,6 +3924,7 @@ def twinx(self): | |
ax2.yaxis.tick_right() | ||
ax2.yaxis.set_label_position('right') | ||
ax2.yaxis.set_offset_position('right') | ||
ax2.set_autoscalex_on(self.get_autoscalex_on()) | ||
self.yaxis.tick_left() | ||
ax2.xaxis.set_visible(False) | ||
ax2.patch.set_visible(False) | ||
|
@@ -3933,25 +3934,26 @@ def twiny(self): | |
""" | ||
Create a twin Axes sharing the yaxis | ||
|
||
Create a twin of Axes for generating a plot with a shared | ||
y-axis but independent x-axis. The x-axis of self will have | ||
ticks on bottom and the returned axes will have ticks on the | ||
top. | ||
Create a new Axes instance with an invisible y-axis and an independent | ||
x-axis positioned opposite to the original one (i.e. at top). The | ||
y-axis autoscale setting will be inherited from the original Axes. | ||
To ensure that the tick marks of both x-axes align, see | ||
`~matplotlib.ticker.LinearLocator` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure that I understand the last sentence. Specifically, how does looking at the documentation for LinearLocator ensure tick alignment? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the original wording - do you have any suggestions for a better sentence? (or you could incorporate it in your PR since that deals with tickers) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will try to figure out what that sentence means exactly and attempt to improve it. |
||
|
||
Returns | ||
------- | ||
Axis | ||
The newly created axis | ||
ax_twin : Axes | ||
The newly created Axes instance | ||
|
||
Notes | ||
------ | ||
----- | ||
For those who are 'picking' artists while using twiny, pick | ||
events are only called for the artists in the top-most axes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. top-most relative to what? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this means the "original" Axes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I'm not really familiar with the Artist/picker API, I'm not really sure what top-most is in this context.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remember correctly, the new axis ends up on top. I remember having some issues with legends getting obscured by gridlines because of this. |
||
""" | ||
|
||
ax2 = self._make_twin_axes(sharey=self) | ||
ax2.xaxis.tick_top() | ||
ax2.xaxis.set_label_position('top') | ||
ax2.set_autoscaley_on(self.get_autoscaley_on()) | ||
self.xaxis.tick_bottom() | ||
ax2.yaxis.set_visible(False) | ||
ax2.patch.set_visible(False) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, good catch!