-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Doc: Scatter Hist example update #13775
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
Doc: Scatter Hist example update #13775
Conversation
Perhaps also diff --git i/examples/axes_grid1/scatter_hist_locatable_axes.py w/examples/axes_grid1/scatter_hist_locatable_axes.py
index 5786a382e..3611ddb1d 100644
--- i/examples/axes_grid1/scatter_hist_locatable_axes.py
+++ w/examples/axes_grid1/scatter_hist_locatable_axes.py
@@ -24,11 +24,13 @@ axScatter.scatter(x, y)
axScatter.set_aspect(1.)
# create new axes on the right and on the top of the current axes
-# The first argument of the new_vertical(new_horizontal) method is
-# the height (width) of the axes to be created in inches.
divider = make_axes_locatable(axScatter)
-axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
-axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)
+axHistx = divider.append_axes(
+ "top", size=1.2, pad=0.1, # Both sizes are in inches.
+ sharex=axScatter)
+axHisty = divider.append_axes(
+ "right", size=1.2, pad=0.1,
+ sharey=axScatter)
# make some labels invisible
axHistx.xaxis.set_tick_params(labelbottom=False) |
164a3d1
to
3aefb71
Compare
|
||
""" | ||
|
||
############################################################################# | ||
# Let us first define a function that takes x and y data as input, as well |
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 will be no space in the generated ReST code between the docstring (stripped) and the documentation comment. Here, the two texts get merged into one paragraph.
Not sure if you can do this at all or if you have to continue the docstring. Anyway this should have a section title.
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.
That is actually desired - in the sense of, I do not want a new section here (because the two sections are the two examples mentionned earlier). I now put everything in the heading docstring.
divider = make_axes_locatable(axScatter) | ||
axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter) | ||
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter) | ||
axHistx = divider.append_axes("top", 1.2, pad=0.1, # height and pad in inches |
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.
Would the plots look better with pad=0
?
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 don't think they look bad in the first place. With pad=0 the axis of the main plot would directly continue into the independent axis of the marginal plot; hence one would need to introduce another visual distinction.
a9ee73e
to
5261a1e
Compare
x = np.random.randn(1000) | ||
y = np.random.randn(1000) | ||
|
||
|
||
def scatter_hist(x, y, axScatter, axHistx, axHisty): |
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 find the logical cut a bit peculiar. A function plotting data into a scatter and two hist plots into three axes is quite special; in particular since the label locations and orientations of the hist plots imply additional assumptions on the axes layout.
This is not a function you would write in real-world applications; instead one would write a function generating the whole figure. This particular function is created to not duplicate the code of filling the axes. I feel uncomfortable having such a function in examples.
This makes me think: What is the purpose of the example:
- Demonstrate this particular case of plot.
- Demonstrate how complex layouts of multiple axes can be created in different ways.
Originally the first. IMHO adding the second makes the example more complicated to understand. It's probably better to do this in a separate example (maybe even without data) and only refer is here ("See ... for different ways of achieving the axes layout").
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 write such functions all the time, because it allows me to have the figure layout and the actual plotting separated. E.g. one could have the axes be part of an even bigger layout without changing anything within the function.
Showcasing the two ways of achieving this plot allows users to choose which one suits their needs. Initially we only had the first case of manually positionning the axes. But then users would ask how to calculate the coordinates of the rectangles in case this whole bunch is to be positionned in a 2x2 axes layout.
A function plotting data into a scatter and two hist plots into three axes is quite special
Seaborn has this as its own function called jointplot
, and also provides a general purpose JointGrid
to map dataframes into such 3 axes. In R/ggplot it's called ggMarginal, in Origin it's "Marginal-Histograms-Graph".
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.
unrelated: pep8-ify the variable names? (ax_histx, etc.)
5261a1e
to
4e63c18
Compare
4e63c18
to
bd2f47d
Compare
2edd7f9
to
2a1984a
Compare
2a1984a
to
255e3b4
Compare
255e3b4
to
104cd8f
Compare
Thank @ImportanceOfBeingErnest and @timhoffm ! |
PR Summary
Update the Scatter Hist examples. Partially inspired by @jklymak's comment on stackoverflow.
add_axes
as well asgridspec
. (Previouslyplt.axes
was used.)Previously:
With this PR:
PR Checklist