Skip to content

Prefer add_subplot(foo=bar) to subplots(subplot_kw={"foo": bar}). #14411

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion galleries/examples/misc/custom_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def _get_core_transform(self, resolution):
import matplotlib.pyplot as plt

# Now make a simple example using the custom projection.
fig, ax = plt.subplots(subplot_kw={'projection': 'custom_hammer'})
ax = plt.figure().add_subplot(projection="custom_hammer")
ax.plot([-1, 1, 1], [-1, -1, 1], "o-")
ax.grid()

Expand Down
2 changes: 1 addition & 1 deletion galleries/examples/mplot3d/custom_shaded_3d_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
x, y, z = x[region], y[region], z[region]

# Set up plot
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
ax = plt.figure().add_subplot(projection="3d")

ls = LightSource(270, 45)
# To use a custom hillshading mode, override the built-in shading and pass
Expand Down
6 changes: 3 additions & 3 deletions galleries/examples/mplot3d/stem3d_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
y = np.sin(theta - np.pi/2)
z = theta

fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
ax = plt.figure().add_subplot(projection="3d")
ax.stem(x, y, z)

plt.show()
Expand All @@ -28,7 +28,7 @@
# configurable via keyword arguments. For more advanced control adapt the line
# objects returned by `~mpl_toolkits.mplot3d.axes3d.Axes3D.stem`.

fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
ax = plt.figure().add_subplot(projection="3d")
markerline, stemlines, baseline = ax.stem(
x, y, z, linefmt='grey', markerfmt='D', bottom=np.pi)
markerline.set_markerfacecolor('none')
Expand All @@ -44,7 +44,7 @@
# For examples, by setting ``orientation='x'``, the stems are projected along
# the *x*-direction, and the baseline is in the *yz*-plane.

fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
ax = plt.figure().add_subplot(projection="3d")
markerline, stemlines, baseline = ax.stem(x, y, z, bottom=-1, orientation='x')
ax.set(xlabel='x', ylabel='y', zlabel='z')

Expand Down
2 changes: 1 addition & 1 deletion galleries/examples/pie_and_polar_charts/polar_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r

fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
ax = plt.figure().add_subplot(projection="polar")
ax.plot(theta, r)
ax.set_rmax(2)
ax.set_rticks([0.5, 1, 1.5, 2]) # Less radial ticks
Expand Down
13 changes: 5 additions & 8 deletions galleries/examples/shapes_and_collections/ellipse_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
angle=np.random.rand() * 360)
for i in range(NUM)]

fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'})
fig, ax = plt.subplots()
ax.set(xlim=(0, 10), ylim=(0, 10), aspect="equal")

for e in ells:
ax.add_artist(e)
e.set_clip_box(ax.bbox)
e.set_alpha(np.random.rand())
e.set_facecolor(np.random.rand(3))

ax.set_xlim(0, 10)
ax.set_ylim(0, 10)

plt.show()

# %%
Expand All @@ -45,15 +44,13 @@
angle_step = 45 # degrees
angles = np.arange(0, 180, angle_step)

fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'})
fig, ax = plt.subplots()
ax.set(xlim=(-2.2, 2.2), ylim=(-2.2, 2.2), aspect="equal")

for angle in angles:
ellipse = Ellipse((0, 0), 4, 2, angle=angle, alpha=0.1)
ax.add_artist(ellipse)

ax.set_xlim(-2.2, 2.2)
ax.set_ylim(-2.2, 2.2)

plt.show()

# %%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
# The text in the example is placed in the fractional figure coordinate system.
# Text keyword arguments like horizontal and vertical alignment are respected.

fig, ax = plt.subplots(subplot_kw=dict(projection='polar'), figsize=(3, 3))
ax = plt.figure(figsize=(3, 3)).add_subplot(projection='polar')
r = np.arange(0, 1, 0.001)
theta = 2*2*np.pi*r
line, = ax.plot(theta, r)
Expand Down
4 changes: 2 additions & 2 deletions galleries/examples/widgets/lasso_selector_demo_sgskip.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def disconnect(self):

data = np.random.rand(100, 2)

subplot_kw = dict(xlim=(0, 1), ylim=(0, 1), autoscale_on=False)
fig, ax = plt.subplots(subplot_kw=subplot_kw)
fig, ax = plt.subplots()
ax.set(xlim=(0, 1), ylim=(0, 1))

pts = ax.scatter(data[:, 0], data[:, 1], s=80)
selector = SelectFromCollection(ax, pts)
Expand Down
2 changes: 1 addition & 1 deletion galleries/plot_types/3D/scatter3d_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
zs = rng.uniform(-50, -25, n)

# Plot
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax = plt.figure().add_subplot(projection="3d")
ax.scatter(xs, ys, zs)

ax.set(xticklabels=[],
Expand Down
2 changes: 1 addition & 1 deletion galleries/plot_types/3D/surface3d_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Z = np.sin(R)

# Plot the surface
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax = plt.figure().add_subplot(projection="3d")
ax.plot_surface(X, Y, Z, vmin=Z.min() * 2, cmap=cm.Blues)

ax.set(xticklabels=[],
Expand Down
2 changes: 1 addition & 1 deletion galleries/plot_types/3D/trisurf3d_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
z = np.sin(-x*y)

# Plot
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
ax = plt.figure().add_subplot(projection="3d")
ax.plot_trisurf(x, y, z, vmin=z.min() * 2, cmap=cm.Blues)

ax.set(xticklabels=[],
Expand Down
2 changes: 1 addition & 1 deletion galleries/plot_types/3D/voxels_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
voxelarray = cube1 | cube2

# Plot
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax = plt.figure().add_subplot(projection="3d")
ax.voxels(voxelarray, edgecolor='k')

ax.set(xticklabels=[],
Expand Down
2 changes: 1 addition & 1 deletion galleries/plot_types/3D/wire3d_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
X, Y, Z = axes3d.get_test_data(0.05)

# Plot
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax = plt.figure().add_subplot(projection="3d")
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

ax.set(xticklabels=[],
Expand Down