Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
DOC: change marginal scatter plot to subplot_mosaic#29670
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -3,8 +3,11 @@ | ||||||||
Scatter plot with histograms | ||||||||
============================ | ||||||||
Add histograms to the x-axes and y-axes margins of a scatter plot. | ||||||||
This layout features a central scatter plot illustrating the relationship | ||||||||
between x and y, a histogram at the top displaying the distribution of x, and a | ||||||||
histogram on the right showing the distribution of y. | ||||||||
timhoffm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||||
For a nice alignment of the main Axes with the marginals, two options are shown | ||||||||
below: | ||||||||
@@ -15,14 +18,9 @@ | ||||||||
While `.Axes.inset_axes` may be a bit more complex, it allows correct handling | ||||||||
of main Axes with a fixed aspect ratio. | ||||||||
Comment on lines 18 to 19 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. Suggested change
Optional, but could be left out. That is also explained at the start of the inset_axes example itself. 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 guess I think it is also useful to explain why there are two methods where they are listed. A bit of repetition is probably OK. | ||||||||
Let us first define a function that takes x and y data as input, as well as | ||||||||
three Axes, the main Axes for the scatter, and two marginal Axes. It will then | ||||||||
create the scatter and histograms inside the provided Axes. | ||||||||
""" | ||||||||
import matplotlib.pyplot as plt | ||||||||
@@ -55,27 +53,22 @@ def scatter_hist(x, y, ax, ax_histx, ax_histy): | ||||||||
# %% | ||||||||
# Defining the Axes positions using subplot_mosaic | ||||||||
# ------------------------------------------------ | ||||||||
# | ||||||||
# We use the `~.pyplot.subplot_mosaic` function to define the positions and | ||||||||
# names of the three axes; the empty axes is specified by ``'.'``. We manually | ||||||||
timhoffm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||||
# specify the size of the figure, and can make the different axes have | ||||||||
# different sizes by specifying the *width_ratios* and *height_ratios* | ||||||||
# arguments. The *layout* argument is set to ``'constrained'`` to optimize the | ||||||||
# spacing between the axes. | ||||||||
fig, axs = plt.subplot_mosaic([['histx', '.'], | ||||||||
['scatter', 'histy']], | ||||||||
figsize=(6, 6), | ||||||||
width_ratios=(4, 1), height_ratios=(1, 4), | ||||||||
layout='constrained') | ||||||||
scatter_hist(x, y, axs['scatter'], axs['histx'], axs['histy']) | ||||||||
# %% | ||||||||
@@ -109,13 +102,27 @@ def scatter_hist(x, y, ax, ax_histx, ax_histy): | ||||||||
# %% | ||||||||
# | ||||||||
# While we recommend using one of the two methods described above, there are | ||||||||
# number of other ways to achieve a similar layout: | ||||||||
# | ||||||||
# - The Axes can be positioned manually in relative coordinates using | ||||||||
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. Suggested change
Sorry, overlooked one additional ReST formatting issue (bullet lists must be separated with an empty line) | ||||||||
# `~matplotlib.figure.Figure.add_axes`. | ||||||||
# - A gridspec can be used to create the layout | ||||||||
# (`~matplotlib.figure.Figure.add_gridspec`) and adding only the three desired | ||||||||
# axes (`~matplotlib.figure.Figure.add_subplot`). | ||||||||
# - Four subplots can be created using `~.pyplot.subplots`, and the unused | ||||||||
# axes in the upper right can be removed manually. | ||||||||
# - The ``axes_grid1`` toolkit can be used, as shown in | ||||||||
# :doc:`/gallery/axes_grid1/scatter_hist_locatable_axes`. | ||||||||
# | ||||||||
# .. admonition:: References | ||||||||
# | ||||||||
# The use of the following functions, methods, classes and modules is shown | ||||||||
# in this example: | ||||||||
# | ||||||||
# - `matplotlib.figure.Figure.subplot_mosaic` | ||||||||
# - `matplotlib.pyplot.subplot_mosaic` | ||||||||
# - `matplotlib.figure.Figure.add_subplot` | ||||||||
# - `matplotlib.axes.Axes.inset_axes` | ||||||||
# - `matplotlib.axes.Axes.scatter` | ||||||||
# - `matplotlib.axes.Axes.hist` | ||||||||
Uh oh!
There was an error while loading.Please reload this page.