-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
DOC: new plot gallery #19703
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: new plot gallery #19703
Changes from 9 commits
d49696a
90fad32
42df67e
7b79ba4
f3a5b27
aec15b0
2653170
b40ed41
69327fb
b3b44b1
6e4c4be
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# from the Matplotlib cheatsheet as used in our gallery: | ||
|
||
axes.grid: True | ||
axes.axisbelow: True | ||
|
||
figure.figsize: 2, 2 | ||
# make it so the axes labels don't show up. Obviously | ||
# not good style for any quantitative analysis: | ||
figure.subplot.left: 0.01 | ||
figure.subplot.right: 0.99 | ||
figure.subplot.bottom: 0.01 | ||
figure.subplot.top: 0.99 | ||
|
||
xtick.major.size: 0.0 | ||
ytick.major.size: 0.0 | ||
|
||
# colors: | ||
image.cmap : Blues | ||
# axes.prop_cycle: cycler('color', ['FF7F0E', '1F77B4', '2CA02C']) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.. _basic_plots: | ||
|
||
Basic | ||
----- | ||
|
||
Basic plot types, usually x versus y. |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||
====================== | ||||||||||||||||||||||||||||||||||||
plot([X], Y, [fmt]...) | ||||||||||||||||||||||||||||||||||||
====================== | ||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||
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'd leave out the parameters in the title. They are a bit cluttered. We should however add a bit of info inside the example, e.g.
Suggested change
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 was basically copying the cheatsheet, which I think was pretty good. If you would like to simplify it later, and add more info to the main text, I think we could do as follow-ups. |
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
import matplotlib.pyplot as plt | ||||||||||||||||||||||||||||||||||||
import numpy as np | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
plt.style.use('mpl_plot_gallery') | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
# make data | ||||||||||||||||||||||||||||||||||||
X = np.linspace(0, 10, 100) | ||||||||||||||||||||||||||||||||||||
Y = 4 + 2 * np.sin(2 * X) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
# plot | ||||||||||||||||||||||||||||||||||||
fig, ax = plt.subplots() | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
ax.plot(X, Y, linewidth=2.0) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
ax.set_xlim(0, 8) | ||||||||||||||||||||||||||||||||||||
ax.set_xticks(np.arange(1, 8)) | ||||||||||||||||||||||||||||||||||||
ax.set_ylim(0, 8) | ||||||||||||||||||||||||||||||||||||
ax.set_yticks(np.arange(1, 8)) | ||||||||||||||||||||||||||||||||||||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
================== | ||
scatter(X, Y, ...) | ||
================== | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.style.use('mpl_plot_gallery') | ||
|
||
# make the data | ||
np.random.seed(3) | ||
X = 4 + np.random.normal(0, 2, 24) | ||
Y = 4 + np.random.normal(0, 2, len(X)) | ||
# size and color: | ||
S = np.random.uniform(15, 80, len(X)) | ||
|
||
# plot | ||
fig, ax = plt.subplots() | ||
|
||
ax.scatter(X, Y, s=S, c=-S, cmap=plt.get_cmap('Blues'), vmin=-100, vmax=0) | ||
|
||
ax.set_xlim(0, 8) | ||
ax.set_xticks(np.arange(1, 8)) | ||
ax.set_ylim(0, 8) | ||
ax.set_yticks(np.arange(1, 8)) | ||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
====================== | ||
bar[h](x, height, ...) | ||
====================== | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
plt.style.use('mpl_plot_gallery') | ||
|
||
# make data: | ||
np.random.seed(3) | ||
X = 0.5 + np.arange(8) | ||
Y = np.random.uniform(2, 7, len(X)) | ||
|
||
# plot | ||
fig, ax = plt.subplots() | ||
|
||
ax.bar(X, Y, width=1, edgecolor="white", linewidth=0.7) | ||
|
||
ax.set_xlim(0, 8) | ||
ax.set_xticks(np.arange(1, 8)) | ||
ax.set_ylim(0, 8) | ||
ax.set_yticks(np.arange(1, 8)) | ||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
================= | ||
stem([x], y, ...) | ||
================= | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.style.use('mpl_plot_gallery') | ||
|
||
# make data | ||
np.random.seed(3) | ||
X = 0.5 + np.arange(8) | ||
Y = np.random.uniform(2, 7, len(X)) | ||
|
||
# plot | ||
fig, ax = plt.subplots() | ||
|
||
ax.stem(X, Y, bottom=0, linefmt="-", markerfmt="d") | ||
|
||
ax.set_xlim(0, 8) | ||
ax.set_xticks(np.arange(1, 8)) | ||
ax.set_ylim(0, 8) | ||
ax.set_yticks(np.arange(1, 8)) | ||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
===================== | ||
step(x, y, where=...) | ||
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. We want to have
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. As above, we can add more, or modify as wanted after this is merged. |
||
===================== | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.style.use('mpl_plot_gallery') | ||
|
||
# make data | ||
np.random.seed(3) | ||
X = 0.5 + np.arange(8) | ||
Y = np.random.uniform(2, 7, len(X)) | ||
|
||
# plot | ||
fig, ax = plt.subplots() | ||
|
||
ax.step(X, Y, linewidth=2.5) | ||
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. Weird to have 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 just a gallery, not documentation for the functions. So the title provides useful keywords the user may be interested in, but we aren't necessarily trying to demo those kwargs. 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. See my proposal above for leaving parameters out of the title and optionally add them to the body. |
||
|
||
ax.set_xlim(0, 8) | ||
ax.set_xticks(np.arange(1, 8)) | ||
ax.set_ylim(0, 8) | ||
ax.set_yticks(np.arange(1, 8)) | ||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
==================== | ||
pie(X, explode, ...) | ||
There was a problem hiding this comment. Choose a reason for hiding this comment57AEThe reason will be displayed to describe this comment to others. Learn more. Again, 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. ... as above... |
||
==================== | ||
""" | ||
import matplotlib as mpl | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.style.use('mpl_plot_gallery') | ||
|
||
|
||
# make data | ||
X = [1, 2, 3, 4] | ||
colors = np.zeros((len(X), 4)) | ||
colors[:] = mpl.colors.to_rgba("C0") | ||
colors[:, 3] = np.linspace(0.25, 0.75, len(X)) | ||
|
||
# plot | ||
fig, ax = plt.subplots() | ||
ax.pie(X, colors=["white"]*len(X), radius=3, center=(4, 4), | ||
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True) | ||
ax.pie(X, colors=colors, radius=3, center=(4, 4), | ||
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True) | ||
|
||
ax.set_xlim(0, 8) | ||
ax.set_xticks(np.arange(1, 8)) | ||
ax.set_ylim(0, 8) | ||
ax.set_yticks(np.arange(1, 8)) | ||
|
||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
================================= | ||
fill[_between][x](X, Y1, Y2, ...) | ||
================================= | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.style.use('mpl_plot_gallery') | ||
|
||
# make data | ||
np.random.seed(1) | ||
X = np.linspace(0, 8, 16) | ||
Y1 = 3 + 4*X/8 + np.random.uniform(0.0, 0.5, len(X)) | ||
Y2 = 1 + 2*X/8 + np.random.uniform(0.0, 0.5, len(X)) | ||
|
||
# plot | ||
fig, ax = plt.subplots() | ||
|
||
ax.fill_between(X, Y1, Y2, alpha=.5, linewidth=0) | ||
ax.plot(X, (Y1+Y2)/2, linewidth=2.5) | ||
|
||
ax.set_xlim(0, 8) | ||
ax.set_xticks(np.arange(1, 8)) | ||
ax.set_ylim(0, 8) | ||
ax.set_yticks(np.arange(1, 8)) | ||
|
||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.. _array_plots: | ||
|
||
Plots of arrays and fields | ||
-------------------------- | ||
|
||
Plotting for arrays of data ``Z(x, y)`` and fields ``U(x, y), V(x, y)`` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
======================= | ||
imshow(Z, [cmap=], ...) | ||
======================= | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.style.use('mpl_plot_gallery') | ||
|
||
# make data | ||
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256)) | ||
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2) | ||
Z = Z - Z.min() | ||
Z = Z[::16, ::16] | ||
|
||
# plot | ||
fig, ax = plt.subplots() | ||
|
||
ax.imshow(Z, extent=[0, 8, 0, 8], interpolation="nearest", | ||
cmap=plt.get_cmap('Blues'), vmin=0, vmax=1.6) | ||
|
||
ax.set_xticks([]) | ||
ax.set_yticks([]) | ||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
=================================== | ||
pcolormesh([X, Y], Z, [cmap=], ...) | ||
=================================== | ||
|
||
`~.axes.Axes.pcolormesh` is more flexible than `~.axes.Axes.imshow` in that | ||
the x and y vectors need not be equally spaced (indeed they can be skewed). | ||
|
||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.style.use('mpl_plot_gallery') | ||
|
||
# make full-res data | ||
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256)) | ||
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2) | ||
Z = Z - Z.min() | ||
|
||
# sample unevenly in x: | ||
dx = np.sqrt((np.arange(16) - 8)**2) + 6 | ||
dx = np.floor(dx / sum(dx) * 255) | ||
xint = np.cumsum(dx).astype('int') | ||
X = X[0, xint] | ||
Y = Y[::8, 0] | ||
Z = Z[::8, :][:, xint] | ||
|
||
# plot | ||
fig, ax = plt.subplots() | ||
|
||
ax.pcolormesh(X, Y, Z, vmin=0, vmax=1.5, shading='nearest') | ||
|
||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
===================================== | ||
contour[f]([X, Y], Z, [levels=], ...) | ||
===================================== | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.style.use('mpl_plot_gallery') | ||
|
||
# make data | ||
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256)) | ||
Z = (1 - X/2. + X**5 + Y**3)*np.exp(-X**2-Y**2) | ||
Z = Z - Z.min() | ||
levs = np.linspace(np.min(Z), np.max(Z), 7) | ||
|
||
# plot | ||
fig, ax = plt.subplots() | ||
|
||
plt.contourf(X, Y, Z, levels=levs) | ||
plt.contour(X, Y, Z, levels=levs, colors="white", linewidths=0.5) | ||
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. At first, this looked like the bug with alpha and multiple filled contours to me. I don't know if you want to use a different colour for the contours, but I'm not sure which colour matches the theme. 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'm not following this concern.... what is wrong with just adding white contours on top of 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. When I first saw it, I thought it was #4419 and not on purpose. |
||
|
||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
========================= | ||
quiver([X, Y], U, V, ...) | ||
========================= | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.style.use('mpl_plot_gallery') | ||
|
||
# make data | ||
T = np.linspace(0, 2*np.pi, 8) | ||
X, Y = 4 + 1 * np.cos(T), 4 + 1 * np.sin(T) | ||
U, V = 1.5 * np.cos(T), 1.5 * np.sin(T) | ||
|
||
# plot | ||
fig, ax = plt.subplots() | ||
|
||
plt.quiver(X, Y, U, V, color="C0", angles='xy', | ||
scale_units='xy', scale=0.5, width=.05) | ||
|
||
ax.set_xlim(0, 8) | ||
ax.set_xticks(np.arange(1, 8)) | ||
ax.set_ylim(0, 8) | ||
ax.set_yticks(np.arange(1, 8)) | ||
|
||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
======================== | ||
streamplot([X, Y], U, V) | ||
======================== | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.style.use('mpl_plot_gallery') | ||
|
||
# make a stream function: | ||
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256)) | ||
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2) | ||
Z = Z - Z.min() | ||
# make U and V out of the streamfunction: | ||
V = np.diff(Z[1:, :], axis=1) | ||
U = -np.diff(Z[:, 1:], axis=0) | ||
|
||
# plot: | ||
fig, ax = plt.subplots() | ||
# contour stream function | ||
ax.contour(X, Y, Z, colors='C1', alpha=0.5, zorder=1, linewidths=3) | ||
# plot stream plot | ||
ax.streamplot(X[1:, 1:], Y[1:, 1:], U, V, zorder=2) | ||
|
||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.. _stats_plots: | ||
|
||
Specialized statistics plots | ||
============================ | ||
|
||
Matplotlib has some specialized plots for statistical analysis. |
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.
Do we want this in the top-level (of the repo, not the docs site) instead of in
doc
?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 other galleries are at the top level...