8000 Backport PR #14149 on branch v3.1.x by timhoffm · Pull Request #14250 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Backport PR #14149 on branch v3.1.x #14250

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/axes_grid1/inset_locator_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

# We set the axis limits to something other than the default, in order to not
# distract from the fact that axes coordinates are used here.
ax.axis([0, 10, 0, 10])
ax.set(xlim=(0, 10), ylim=(0, 10))


# Note how the two following insets are created at the same positions, one by
Expand Down Expand Up @@ -126,7 +126,7 @@

ax2 = fig.add_subplot(133)
ax2.set_xscale("log")
ax2.axis([1e-6, 1e6, -2, 6])
ax2.set(xlim=(1e-6, 1e6), ylim=(-2, 6))

# Create inset in data coordinates using ax.transData as transform
axins3 = inset_axes(ax2, width="100%", height="100%",
Expand Down
12 changes: 6 additions & 6 deletions examples/event_handling/ginput_manual_clabel_sgskip.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def tellme(s):


plt.clf()
plt.axis([-1., 1., -1., 1.])
plt.setp(plt.gca(), autoscale_on=False)

tellme('You will define a triangle, click to begin')
Expand Down Expand Up @@ -84,13 +83,14 @@ def f(x, y, pts):

while True:
tellme('Select two corners of zoom, middle mouse button to finish')
pts = np.asarray(plt.ginput(2, timeout=-1))

pts = plt.ginput(2, timeout=-1)
if len(pts) < 2:
break

pts = np.sort(pts, axis=0)
plt.axis(pts.T.ravel())
(x0, y0), (x1, y1) = pts
xmin, xmax = sorted([x0, x1])
ymin, ymax = sorted([y0, y1])
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)

tellme('All Done!')
plt.show()
10 changes: 5 additions & 5 deletions examples/event_handling/pick_event_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ def onpick3(event):
def pick_image():
# picking images (matplotlib.image.AxesImage)
fig, ax = plt.subplots()
im1 = ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True)
im2 = ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True)
im3 = ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True)
im4 = ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True)
ax.axis([0, 5, 0, 5])
ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True)
ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True)
ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True)
ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True)
ax.set(xlim=(0, 5), ylim=(0, 5))

def onpick4(event):
artist = event.artist
Expand Down
4 changes: 2 additions & 2 deletions examples/images_contours_and_fields/irregulardatagrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

fig.colorbar(cntr1, ax=ax1)
ax1.plot(x, y, 'ko', ms=3)
ax1.axis((-2, 2, -2, 2))
ax1.set(xlim=(-2, 2), ylim=(-2, 2))
ax1.set_title('grid and contour (%d points, %d grid points)' %
(npts, ngridx * ngridy))

Expand All @@ -78,7 +78,7 @@

fig.colorbar(cntr2, ax=ax2)
ax2.plot(x, y, 'ko', ms=3)
ax2.axis((-2, 2, -2, 2))
ax2.set(xlim=(-2, 2), ylim=(-2, 2))
ax2.set_title('tricontour (%d points)' % npts)

plt.subplots_adjust(hspace=0.5)
Expand Down
4 changes: 0 additions & 4 deletions examples/images_contours_and_fields/pcolor_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,11 @@
ax = axs[0, 0]
c = ax.pcolor(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max)
ax.set_title('pcolor')
# set the limits of the plot to the limits of the data
ax.axis([x.min(), x.max(), y.min(), y.max()])
fig.colorbar(c, ax=ax)

ax = axs[0, 1]
c = ax.pcolormesh(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max)
ax.set_title('pcolormesh')
# set the limits of the plot to the limits of the data
ax.axis([x.min(), x.max(), y.min(), y.max()])
fig.colorbar(c, ax=ax)

ax = axs[1, 0]
Expand Down
2 changes: 1 addition & 1 deletion examples/images_contours_and_fields/plot_streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

# Displaying the starting points with blue symbols.
ax3.plot(seed_points[0], seed_points[1], 'bo')
ax3.axis((-w, w, -w, w))
ax3.set(xlim=(-w, w), ylim=(-w, w))

# Create a mask
mask = np.zeros(U.shape, dtype=bool)
Expand Down
24 changes: 12 additions & 12 deletions examples/misc/contour_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@

###############################################################################

plt.figure()
fig, ax = plt.subplots()

# Filled contours using filled=True.
cs = ContourSet(plt.gca(), [0, 1, 2], [filled01, filled12], filled=True, cmap=cm.bone)
cbar = plt.colorbar(cs)
cs = ContourSet(ax, [0, 1, 2], [filled01, filled12], filled=True, cmap=cm.bone)
cbar = fig.colorbar(cs)

# Contour lines (non-filled).
lines = ContourSet(plt.gca(), [0, 1, 2], [lines0, lines1, lines2], cmap=cm.cool,
linewidths=3)
lines = ContourSet(
ax, [0, 1, 2], [lines0, lines1, lines2], cmap=cm.cool, linewidths=3)
cbar.add_lines(lines)

plt.axis([-0.5, 3.5, -0.5, 4.5])
plt.title('User-specified contours')
ax.set(xlim=(-0.5, 3.5), ylim=(-0.5, 4.5),
title='User-specified contours')

###############################################################################
# Multiple filled contour lines can be specified in a single list of polygon
# vertices along with a list of vertex kinds (code types) as described in the
# Path class. This is particularly useful for polygons with holes.
# Here a code type of 1 is a MOVETO, and 2 is a LINETO.

plt.figure()
fig, ax = plt.subplots()
filled01 = [[[0, 0], [3, 0], [3, 3], [0, 3], [1, 1], [1, 2], [2, 2], [2, 1]]]
kinds01 = [[1, 2, 2, 2, 1, 2, 2, 2]]
cs = ContourSet(plt.gca(), [0, 1], [filled01], [kinds01], filled=True)
cbar = plt.colorbar(cs)
cs = ContourSet(ax, [0, 1], [filled01], [kinds01], filled=True)
cbar = fig.colorbar(cs)

plt.axis([-0.5, 3.5, -0.5, 3.5])
plt.title('User specified filled contours with holes')
ax.set(xlim=(-0.5, 3.5), ylim=(-0.5, 3.5),
title='User specified filled contours with holes')

plt.show()
14 changes: 7 additions & 7 deletions examples/pyplots/pyplot_formatstr.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
================
Pyplot Formatstr
================
====================
plot() format string
====================

Use a format string to colorize a `~matplotlib.axes.Axes.plot` and set its
markers.
Use a format string (here, 'ro') to set the color and markers of a
`~matplotlib.axes.Axes.plot`.
"""

import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'ro')
plt.show()

#############################################################################
Expand Down
3 changes: 2 additions & 1 deletion examples/pyplots/pyplot_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.xlim(40, 160)
plt.ylim(0, 0.03)
plt.grid(True)
plt.show()

Expand Down
2 changes: 1 addition & 1 deletion examples/pyplots/text_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
ax.annotate('annotate', xy=(2, 1), xytext=(3, 4),
arrowprops=dict(facecolor='black', shrink=0.05))

ax.axis([0, 10, 0, 10])
ax.set(xlim=(0, 10), ylim=(0, 10))

plt.show()

Expand Down
51 changes: 18 additions & 33 deletions examples/specialty_plots/anscombe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,37 @@
Edward Tufte uses this example from Anscombe to show 4 datasets of x
and y that have the same mean, standard deviation, and regression
line, but which are qualitatively different.

matplotlib fun for a rainy day
"""

import matplotlib.pyplot as plt
import numpy as np

x = np.array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])
y1 = np.array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68])
y2 = np.array([9.14, 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74])
y3 = np.array([7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73])
x4 = np.array([8, 8, 8, 8, 8, 8, 8, 19, 8, 8, 8])
y4 = np.array([6.58, 5.76, 7.71, 8.84, 8.47, 7.04, 5.25, 12.50, 5.56, 7.91, 6.89])
x = [10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5]
y1 = [8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68]
y2 = [9.14, 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74]
y3 = [7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73]
x4 = [8, 8, 8, 8, 8, 8, 8, 19, 8, 8, 8]
y4 = [6.58, 5.76, 7.71, 8.84, 8.47, 7.04, 5.25, 12.50, 5.56, 7.91, 6.89]


def fit(x):
return 3 + 0.5 * x


xfit = np.array([np.min(x), np.max(x)])

plt.subplot(221)
plt.plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2)
plt.axis([2, 20, 2, 14])
plt.setp(plt.gca(), xticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20))
plt.text(3, 12, 'I', fontsize=20)

plt.subplot(222)
plt.plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2)
plt.axis([2, 20, 2, 14])
plt.setp(plt.gca(), xticks=(0, 10, 20), xticklabels=[],
yticks=(4, 8, 12), yticklabels=[], )
plt.text(3, 12, 'II', fontsize=20)
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True)
axs[0, 0].set(xlim=(0, 20), ylim=(2, 14))
axs[0, 0].set(xticks=(0, 10, 20), yticks=(4, 8, 12))

plt.subplot(223)
plt.plot(x, y3, 'ks', xfit, fit(xfit), 'r-', lw=2)
plt.axis([2, 20, 2, 14])
plt.text(3, 12, 'III', fontsize=20)
plt.setp(plt.gca(), yticks=(4, 8, 12), xticks=(0, 10, 20))

plt.subplot(224)
xfit = np.array([np.min(x), np.max(x)])
axs[0, 0].plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2)
axs[0, 1].plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2)
axs[1, 0].plot(x, y3, 'ks', xfit, fit(xfit), 'r-', lw=2)
xfit = np.array([np.min(x4), np.max(x4)])
plt.plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2)
plt.axis([2, 20, 2, 14])
plt.setp(plt.gca(), yticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20))
plt.text(3, 12, 'IV', fontsize=20)
axs[1, 1].plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2)

for ax, label in zip(axs.flat, ['I', 'II', 'III', 'IV']):
ax.label_outer()
ax.text(3, 12, label, fontsize=20)

# verify the stats
pairs = (x, y1), (x, y2), (x, y3), (x4, y4)
Expand Down
4 changes: 2 additions & 2 deletions examples/statistics/hexbin_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
fig.subplots_adjust(hspace=0.5, left=0.07, right=0.93)
ax = axs[0]
hb = ax.hexbin(x, y, gridsize=50, cmap='inferno')
ax.axis([xmin, xmax, ymin, ymax])
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
ax.set_title("Hexagon binning")
cb = fig.colorbar(hb, ax=ax)
cb.set_label('counts')

ax = axs[1]
hb = ax.hexbin(x, y, gridsize=50, bins='log', cmap='inferno')
ax.axis([xmin, xmax, ymin, ymax])
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
ax.set_title("With a log color scale")
cb = fig.colorbar(hb, ax=ax)
cb.set_label('log10(N)')
Expand Down
3 changes: 2 additions & 1 deletion examples/subplots_axes_and_figures/axes_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

# the main axes is subplot(111) by default
plt.plot(t, s)
plt.axis([0, 1, 1.1 * np.min(s), 2 * np.max(s)])
plt.xlim(0, 1)
plt.ylim(1.1 * np.min(s), 2 * np.max(s))
plt.xlabel('time (s)')
plt.ylabel('current (nA)')
plt.title('Gaussian colored noise')
Expand Down
2 changes: 0 additions & 2 deletions examples/subplots_axes_and_figures/axhspan_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@

plt.axvspan(1.25, 1.55, facecolor='#2ca02c', alpha=0.5)

plt.axis([-1, 2, -1, 2])

plt.show()
2 changes: 1 addition & 1 deletion examples/subplots_axes_and_figures/axis_equal_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

axs[1, 0].plot(3 * np.cos(an), 3 * np.sin(an))
axs[1, 0].axis('equal')
axs[1, 0].axis([-3, 3, -3, 3])
axs[1, 0].set(xlim=(-3, 3), ylim=(-3, 3))
axs[1, 0].set_title('still a circle, even after changing limits', fontsize=10)

axs[1, 1].plot(3 * np.cos(an), 3 * np.sin(an))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def test_rotation_mode(fig, mode, subplot_location):
# prepare axes layout
for axis in ax.axis.values():
axis.toggle(ticks=False, ticklabels=False)
ax.axis([0, 1, 0, 1])
ax.axvline(0.5, color="skyblue", zorder=0)
ax.axhline(0.5, color="skyblue", zorder=0)
ax.plot(0.5, 0.5, color="C0", marker="o", zorder=1)
Expand Down
Loading
0