Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1676489

Browse filesBrowse files
committed
Backport PR #14149: Avoid using axis([xlo, xhi, ylo, yhi]) in examples.
1 parent 3b26ee6 commit 1676489
Copy full SHA for 1676489

File tree

Expand file treeCollapse file tree

21 files changed

+100
-147
lines changed
Filter options
Expand file treeCollapse file tree

21 files changed

+100
-147
lines changed

‎examples/axes_grid1/inset_locator_demo.py

Copy file name to clipboardExpand all lines: examples/axes_grid1/inset_locator_demo.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

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

7979

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

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

131131
# Create inset in data coordinates using ax.transData as transform
132132
axins3 = inset_axes(ax2, width="100%", height="100%",

‎examples/event_handling/ginput_manual_clabel_sgskip.py

Copy file name to clipboardExpand all lines: examples/event_handling/ginput_manual_clabel_sgskip.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def tellme(s):
2828

2929

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

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

8584
while True:
8685
tellme('Select two corners of zoom, middle mouse button to finish')
87-
pts = np.asarray(plt.ginput(2, timeout=-1))
88-
86+
pts = plt.ginput(2, timeout=-1)
8987
if len(pts) < 2:
9088
break
91-
92-
pts = np.sort(pts, axis=0)
93-
plt.axis(pts.T.ravel())
89+
(x0, y0), (x1, y1) = pts
90+
xmin, xmax = sorted([x0, x1])
91+
ymin, ymax = sorted([y0, y1])
92+
plt.xlim(xmin, xmax)
93+
plt.ylim(ymin, ymax)
9494

9595
tellme('All Done!')
9696
plt.show()

‎examples/event_handling/pick_event_demo.py

Copy file name to clipboardExpand all lines: examples/event_handling/pick_event_demo.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ def onpick3(event):
165165
def pick_image():
166166
# picking images (matplotlib.image.AxesImage)
167167
fig, ax = plt.subplots()
168-
im1 = ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True)
169-
im2 = ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True)
170-
im3 = ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True)
171-
im4 = ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True)
172-
ax.axis([0, 5, 0, 5])
168+
ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True)
169+
ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True)
170+
ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True)
171+
ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True)
172+
ax.set(xlim=(0, 5), ylim=(0, 5))
173173

174174
def onpick4(event):
175175
artist = event.artist

‎examples/images_contours_and_fields/irregulardatagrid.py

Copy file name to clipboardExpand all lines: examples/images_contours_and_fields/irregulardatagrid.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

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

@@ -78,7 +78,7 @@
7878

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

8484
plt.subplots_adjust(hspace=0.5)

‎examples/images_contours_and_fields/pcolor_demo.py

Copy file name to clipboardExpand all lines: examples/images_contours_and_fields/pcolor_demo.py
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,11 @@
5454
ax = axs[0, 0]
5555
c = ax.pcolor(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max)
5656
ax.set_title('pcolor')
57-
# set the limits of the plot to the limits of the data
58-
ax.axis([x.min(), x.max(), y.min(), y.max()])
5957
fig.colorbar(c, ax=ax)
6058

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

6864
ax = axs[1, 0]

‎examples/images_contours_and_fields/plot_streamplot.py

Copy file name to clipboardExpand all lines: examples/images_contours_and_fields/plot_streamplot.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

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

5858
# Create a mask
5959
mask = np.zeros(U.shape, dtype=bool)

‎examples/misc/contour_manual.py

Copy file name to clipboardExpand all lines: examples/misc/contour_manual.py
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,33 @@
2525

2626
###############################################################################
2727

28-
plt.figure()
28+
fig, ax = plt.subplots()
2929

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

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

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

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

48-
plt.figure()
48+
fig, ax = plt.subplots()
4949
filled01 = [[[0, 0], [3, 0], [3, 3], [0, 3], [1, 1], [1, 2], [2, 2], [2, 1]]]
5050
kinds01 = [[1, 2, 2, 2, 1, 2, 2, 2]]
51-
cs = ContourSet(plt.gca(), [0, 1], [filled01], [kinds01], filled=True)
52-
cbar = plt.colorbar(cs)
51+
cs = ContourSet(ax, [0, 1], [filled01], [kinds01], filled=True)
52+
cbar = fig.colorbar(cs)
5353

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

5757
plt.show()

‎examples/pyplots/pyplot_formatstr.py

Copy file name to clipboardExpand all lines: examples/pyplots/pyplot_formatstr.py
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""
2-
================
3-
Pyplot Formatstr
4-
================
2+
====================
3+
plot() format string
4+
====================
55
6-
Use a format string to colorize a `~matplotlib.axes.Axes.plot` and set its
7-
markers.
6+
Use a format string (here, 'ro') to set the color and markers of a
7+
`~matplotlib.axes.Axes.plot`.
88
"""
9+
910
import matplotlib.pyplot as plt
10-
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
11-
plt.axis([0, 6, 0, 20])
11+
plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'ro')
1212
plt.show()
1313

1414
#############################################################################

‎examples/pyplots/pyplot_text.py

Copy file name to clipboardExpand all lines: examples/pyplots/pyplot_text.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
plt.ylabel('Probability')
2222
plt.title('Histogram of IQ')
2323
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
24-
plt.axis([40, 160, 0, 0.03])
24+
plt.xlim(40, 160)
25+
plt.ylim(0, 0.03)
2526
plt.grid(True)
2627
plt.show()
2728

‎examples/pyplots/text_commands.py

Copy file name to clipboardExpand all lines: examples/pyplots/text_commands.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
ax.annotate('annotate', xy=(2, 1), xytext=(3, 4),
3636
arrowprops=dict(facecolor='black', shrink=0.05))
3737

38-
ax.axis([0, 10, 0, 10])
38+
ax.set(xlim=(0, 10), ylim=(0, 10))
3939

4040
plt.show()
4141

‎examples/specialty_plots/anscombe.py

Copy file name to clipboardExpand all lines: examples/specialty_plots/anscombe.py
+18-33Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,37 @@
88
Edward Tufte uses this example from Anscombe to show 4 datasets of x
99
and y that have the same mean, standard deviation, and regression
1010
line, but which are qualitatively different.
11-
12-
matplotlib fun for a rainy day
1311
"""
1412

1513
import matplotlib.pyplot as plt
1614
import numpy as np
1715

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

2523

2624
def fit(x):
2725
return 3 + 0.5 * x
2826

2927

30-
xfit = np.array([np.min(x), np.max(x)])
31-
32-
plt.subplot(221)
33-
plt.plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2)
34-
plt.axis([2, 20, 2, 14])
35-
plt.setp(plt.gca(), xticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20))
36-
plt.text(3, 12, 'I', fontsize=20)
37-
38-
plt.subplot(222)
39-
plt.plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2)
40-
plt.axis([2, 20, 2, 14])
41-
plt.setp(plt.gca(), xticks=(0, 10, 20), xticklabels=[],
42-
yticks=(4, 8, 12), yticklabels=[], )
43-
plt.text(3, 12, 'II', fontsize=20)
28+
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True)
29+
axs[0, 0].set(xlim=(0, 20), ylim=(2, 14))
30+
axs[0, 0].set(xticks=(0, 10, 20), yticks=(4, 8, 12))
4431

45-
plt.subplot(223)
46-
plt.plot(x, y3, 'ks', xfit, fit(xfit), 'r-', lw=2)
47-
plt.axis([2, 20, 2, 14])
48-
plt.text(3, 12, 'III', fontsize=20)
49-
plt.setp(plt.gca(), yticks=(4, 8, 12), xticks=(0, 10, 20))
50-
51-
plt.subplot(224)
32+
xfit = np.array([np.min(x), np.max(x)])
33+
axs[0, 0].plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2)
34+
axs[0, 1].plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2)
35+
axs[1, 0].plot(x, y3, 'ks', xfit, fit(xfit), 'r-', lw=2)
5236
xfit = np.array([np.min(x4), np.max(x4)])
53-
plt.plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2)
54-
plt.axis([2, 20, 2, 14])
55-
plt.setp(plt.gca(), yticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20))
56-
plt.text(3, 12, 'IV', fontsize=20)
37+
axs[1, 1].plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2)
38+
39+
for ax, label in zip(axs.flat, ['I', 'II', 'III', 'IV']):
40+
ax.label_outer()
41+
ax.text(3, 12, label, fontsize=20)
5742

5843
# verify the stats
5944
pairs = (x, y1), (x, y2), (x, y3), (x4, y4)

‎examples/statistics/hexbin_demo.py

Copy file name to clipboardExpand all lines: examples/statistics/hexbin_demo.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
fig.subplots_adjust(hspace=0.5, left=0.07, right=0.93)
3030
ax = axs[0]
3131
hb = ax.hexbin(x, y, gridsize=50, cmap='inferno')
32-
ax.axis([xmin, xmax, ymin, ymax])
32+
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
3333
ax.set_title("Hexagon binning")
3434
cb = fig.colorbar(hb, ax=ax)
3535
cb.set_label('counts')
3636

3737
ax = axs[1]
3838
hb = ax.hexbin(x, y, gridsize=50, bins='log', cmap='inferno')
39-
ax.axis([xmin, xmax, ymin, ymax])
39+
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
4040
ax.set_title("With a log color scale")
4141
cb = fig.colorbar(hb, ax=ax)
4242
cb.set_label('log10(N)')

‎examples/subplots_axes_and_figures/axes_demo.py

Copy file name to clipboardExpand all lines: examples/subplots_axes_and_figures/axes_demo.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
# the main axes is subplot(111) by default
2323
plt.plot(t, s)
24-
plt.axis([0, 1, 1.1 * np.min(s), 2 * np.max(s)])
24+
plt.xlim(0, 1)
25+
plt.ylim(1.1 * np.min(s), 2 * np.max(s))
2526
plt.xlabel('time (s)')
2627
plt.ylabel('current (nA)')
2728
plt.title('Gaussian colored noise')

‎examples/subplots_axes_and_figures/axhspan_demo.py

Copy file name to clipboardExpand all lines: examples/subplots_axes_and_figures/axhspan_demo.py
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,4 @@
3232

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

35-
plt.axis([-1, 2, -1, 2])
36-
3735
plt.show()

‎examples/subplots_axes_and_figures/axis_equal_demo.py

Copy file name to clipboardExpand all lines: examples/subplots_axes_and_figures/axis_equal_demo.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

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

2929
axs[1, 1].plot(3 * np.cos(an), 3 * np.sin(an))

‎examples/text_labels_and_annotations/demo_text_rotation_mode.py

Copy file name to clipboardExpand all lines: examples/text_labels_and_annotations/demo_text_rotation_mode.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def test_rotation_mode(fig, mode, subplot_location):
4949
# prepare axes layout
5050
for axis in ax.axis.values():
5151
axis.toggle(ticks=False, ticklabels=False)
52-
ax.axis([0, 1, 0, 1])
5352
ax.axvline(0.5, color="skyblue", zorder=0)
5453
ax.axhline(0.5, color="skyblue", zorder=0)
5554
ax.plot(0.5, 0.5, color="C0", marker="o", zorder=1)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.