-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Allow sharex/y after axes creation. #15287
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
Conversation
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.
Overall this seems a useful API though I suspect we haven’t thought through how it will be used. Allowing sharing to be toggled like this seems like it will be ripe for misunderstandings. Could use some examples of why you think this is useful
""" | ||
Share the x-axis with *other*. | ||
|
||
This is equivalent to passing ``sharex=other`` when constructing the |
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.
This docstring could be more explicit and non circular. For instance the verb to share would indicate that self shares with other, whereas the exact opposite happens. Further passing sharex=other calls this function so I don’t think it’s very helpful to say that this function is the same as that and expect the user to ferret out the behaviour
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.
"self shares with other, whereas the exact opposite happens"
What do you mean by "opposite"? Isn't sharing symmetrical? (well perhaps not deep in the implementation details, but from the user PoV it is)
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.
I meant in everyday English the transitive verb “to share” means one person shares Something with another
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.
Can you propose an alternate wording here?
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.
Sorry, the main point is that saying ax.sharex
is "Equivalent to passing sharex=other when constructing..." is a circular doc, because when you construct, you call ax.sharex
. This function ideally would define what ax.sharex
does explicitly.
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.
Right now the docs of sharex (as kwargs to the Axes constructor) are
sharex, sharey : `~.axes.Axes`, optional
The x or y `~.matplotlib.axis` is shared with the x or
y axis in the input `~.axes.Axes`.
which is not much better :/ I agree this can be improved, but is arguably a separate issue?
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.
The docstring defines what the function does for the user, and one of our main problems with "share" is that people don't know what it means and even in the history of the code base different definitions have popped up. Right now I'm not 100% sure what this PR changed and I think it should be defined clearly, in plain English, what calling this function will do.
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.
ax0 = (some axes)
ax1 = fig.add_subplot(...)
ax1.sharex(ax0)
is equivalent to
ax0 = (some axes)
ax1 = fig.add_subplot(..., sharex=ax0)
Now it is true that what the latter does is not really well documented either, but the doc available for ax1.sharex(ax0)
is, well, exactly the same.
I'm explicitly not allowing toggling, or changing who you share with, just going from "not-shared" to "shared". Indeed, allowing unsharing makes the problem much more complex. The use case hinted above is:
Each A plots the distribution (histogram) of variable a in conditions a1, a2, a3; each B plots the distribution of variable b in conditions b1, b2, b3, and each X plots the joint distribution (scatter plot). Here you want to sharex across rows and sharey across columns, except that the first row does not share y's and the first column does not share x's (let's say you don't want to normalize your histograms). |
I understand your example, but it would be helpful if you actually provided one in the PR. |
Do you mean one as comments in the code? (where?) in the commit message? |
I meant as an example in the example folder |
Sure, added a simple example. |
850d310
to
f1ed957
Compare
First thoughts on this:
|
I guess I'm +0.5 on sharex_with() and +0.25 on sharex_from() (both are better than sharex()), let's see what others think. What about adding something like
to the docstrings? (I don't really intend to support "later" calls with this PR anyways.) |
1abd103
to
b57a4da
Compare
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.
There might be unintended consequences, but let's try it.
Approved, subject to rebase.
This intentionally does not allow unsharing or changing the shared axes, as there are bigger questions on the API there. The API is named `Axes.sharex()` to allow for a later `Axes.unsharex()`, though (`set_sharex()` would be fine, but `set_unsharex()`? or perhaps `set_sharex(None)`, though). An example use case is creating a grid with `subplots()`, but with custom sharing relationships between the subplots -- e.g., sharex/sharey across all, except the first row of axes which only shares x with their column and the first column which only shares y with their lines.
rebased |
We seem to be getting a systematic failure--not just on this PR--in the macosx build on Travis, in |
macOS failure is #17065; doc failure is just spurious inability to download a Sphinx inventory. |
This intentionally does not allow unsharing or changing the shared axes,
as there are bigger questions on the API there (#9923 and issues linked there).
The API is named
Axes.sharex()
to allow for a laterAxes.unsharex()
,though (
set_sharex()
would be fine, butset_unsharex()
? or perhapsset_sharex(None)
, though). Happy to hear suggestions.An example use case is creating a grid with
subplots()
, but withcustom sharing relationships between the subplots -- e.g., sharex/sharey
across all, except the first row of axes which only shares x with their
column and the first column which only shares y with their lines.
PR Summary
PR Checklist