Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5867883

Browse files
committed
Un-pyplot some examples which were already explicitly referencing axes.
1 parent 078790e commit 5867883

7 files changed

+32
-28
lines changed

examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from mpl_toolkits.axes_grid1.axes_divider import make_axes_area_auto_adjustable
1212

1313

14-
plt.figure()
15-
ax = plt.axes([0, 0, 1, 1])
14+
fig = plt.figure()
15+
ax = fig.add_axes([0, 0, 1, 1])
1616

1717
ax.set_yticks([0.5], labels=["very long label"])
1818

@@ -21,9 +21,9 @@
2121
###############################################################################
2222

2323

24-
plt.figure()
25-
ax1 = plt.axes([0, 0, 1, 0.5])
26-
ax2 = plt.axes([0, 0.5, 1, 0.5])
24+
fig = plt.figure()
25+
ax1 = fig.add_axes([0, 0, 1, 0.5])
26+
ax2 = fig.add_axes([0, 0.5, 1, 0.5])
2727

2828
ax1.set_yticks([0.5], labels=["very long label"])
2929
ax1.set_ylabel("Y label")
@@ -37,7 +37,7 @@
3737

3838

3939
fig = plt.figure()
40-
ax1 = plt.axes([0, 0, 1, 1])
40+
ax1 = fig.add_axes([0, 0, 1, 1])
4141
divider = make_axes_locatable(ax1)
4242

4343
ax2 = divider.append_axes("right", "100%", pad=0.3, sharey=ax1)

examples/widgets/buttons.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
freqs = np.arange(2, 20, 3)
1717

1818
fig, ax = plt.subplots()
19-
plt.subplots_adjust(bottom=0.2)
19+
fig.subplots_adjust(bottom=0.2)
2020
t = np.arange(0.0, 1.0, 0.001)
2121
s = np.sin(2*np.pi*freqs[0]*t)
22-
l, = plt.plot(t, s, lw=2)
22+
l, = ax.plot(t, s, lw=2)
2323

2424

2525
class Index:
@@ -40,8 +40,8 @@ def prev(self, event):
4040
plt.draw()
4141

4242
callback = Index()
43-
axprev = plt.axes([0.7, 0.05, 0.1, 0.075])
44-
axnext = plt.axes([0.81, 0.05, 0.1, 0.075])
43+
axprev = fig.add_axes([0.7, 0.05, 0.1, 0.075])
44+
axnext = fig.add_axes([0.81, 0.05, 0.1, 0.075])
4545
bnext = Button(axnext, 'Next')
4646
bnext.on_clicked(callback.next)
4747
bprev = Button(axprev, 'Previous')

examples/widgets/check_buttons.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
check boxes. There are 3 different sine waves shown and we can choose which
1010
waves are displayed with the check buttons.
1111
"""
12+
1213
import numpy as np
1314
import matplotlib.pyplot as plt
1415
from matplotlib.widgets import CheckButtons
@@ -22,12 +23,12 @@
2223
l0, = ax.plot(t, s0, visible=False, lw=2, color='k', label='2 Hz')
2324
l1, = ax.plot(t, s1, lw=2, color='r', label='4 Hz')
2425
l2, = ax.plot(t, s2, lw=2, color='g', label='6 Hz')
25-
plt.subplots_adjust(left=0.2)
26+
fig.subplots_adjust(left=0.2)
2627

2728
lines = [l0, l1, l2]
2829

2930
# Make checkbuttons with all plotted lines with correct visibility
30-
rax = plt.axes([0.05, 0.4, 0.1, 0.15])
31+
rax = fig.add_axes([0.05, 0.4, 0.1, 0.15])
3132
labels = [str(line.get_label()) for line in lines]
3233
visibility = [line.get_visible() for line in lines]
3334
check = CheckButtons(rax, labels, visibility)

examples/widgets/radio_buttons.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
In this case, the buttons let the user choose one of the three different sine
1010
waves to be shown in the plot.
1111
"""
12+
1213
import numpy as np
1314
import matplotlib.pyplot as plt
1415
from matplotlib.widgets import RadioButtons
@@ -20,10 +21,10 @@
2021

2122
fig, ax = plt.subplots()
2223
l, = ax.plot(t, s0, lw=2, color='red')
23-
plt.subplots_adjust(left=0.3)
24+
fig.subplots_adjust(left=0.3)
2425

2526
axcolor = 'lightgoldenrodyellow'
26-
rax = plt.axes([0.05, 0.7, 0.15, 0.15], facecolor=axcolor)
27+
rax = fig.add_axes([0.05, 0.7, 0.15, 0.15], facecolor=axcolor)
2728
radio = RadioButtons(rax, ('2 Hz', '4 Hz', '8 Hz'))
2829

2930

@@ -34,7 +35,7 @@ def hzfunc(label):
3435
plt.draw()
3536
radio.on_clicked(hzfunc)
3637

37-
rax = plt.axes([0.05, 0.4, 0.15, 0.15], facecolor=axcolor)
38+
rax = fig.add_axes([0.05, 0.4, 0.15, 0.15], facecolor=axcolor)
3839
radio2 = RadioButtons(rax, ('red', 'blue', 'green'))
3940

4041

@@ -43,7 +44,7 @@ def colorfunc(label):
4344
plt.draw()
4445
radio2.on_clicked(colorfunc)
4546

46-
rax = plt.axes([0.05, 0.1, 0.15, 0.15], facecolor=axcolor)
47+
rax = fig.add_axes([0.05, 0.1, 0.15, 0.15], facecolor=axcolor)
4748
radio3 = RadioButtons(rax, ('-', '--', '-.', 'steps', ':'))
4849

4950

examples/widgets/range_slider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
img = np.random.randn(N, N)
2727

2828
fig, axs = plt.subplots(1, 2, figsize=(10, 5))
29-
plt.subplots_adjust(bottom=0.25)
29+
fig.subplots_adjust(bottom=0.25)
3030

3131
im = axs[0].imshow(img)
3232
axs[1].hist(img.flatten(), bins='auto')
3333
axs[1].set_title('Histogram of pixel intensities')
3434

3535
# Create the RangeSlider
36-
slider_ax = plt.axes([0.20, 0.1, 0.60, 0.03])
36+
slider_ax = fig.add_axes([0.20, 0.1, 0.60, 0.03])
3737
slider = RangeSlider(slider_ax, "Threshold", img.min(), img.max())
3838

3939
# Create the Vertical lines on the histogram

examples/widgets/slider_demo.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
See :doc:`/gallery/widgets/range_slider` for an example of using
1313
a ``RangeSlider`` to define a range of values.
1414
"""
15+
1516
import numpy as np
1617
import matplotlib.pyplot as plt
1718
from matplotlib.widgets import Slider, Button
@@ -29,14 +30,14 @@ def f(t, amplitude, frequency):
2930

3031
# Create the figure and the line that we will manipulate
3132
fig, ax = plt.subplots()
32-
line, = plt.plot(t, f(t, init_amplitude, init_frequency), lw=2)
33+
line, = ax.plot(t, f(t, init_amplitude, init_frequency), lw=2)
3334
ax.set_xlabel('Time [s]')
3435

3536
# adjust the main plot to make room for the sliders
36-
plt.subplots_adjust(left=0.25, bottom=0.25)
37+
fig.subplots_adjust(left=0.25, bottom=0.25)
3738

3839
# Make a horizontal slider to control the frequency.
39-
axfreq = plt.axes([0.25, 0.1, 0.65, 0.03])
40+
axfreq = fig.add_axes([0.25, 0.1, 0.65, 0.03])
4041
freq_slider = Slider(
4142
ax=axfreq,
4243
label='Frequency [Hz]',
@@ -46,7 +47,7 @@ def f(t, amplitude, frequency):
4647
)
4748

4849
# Make a vertically oriented slider to control the amplitude
49-
axamp = plt.axes([0.1, 0.25, 0.0225, 0.63])
50+
axamp = fig.add_axes([0.1, 0.25, 0.0225, 0.63])
5051
amp_slider = Slider(
5152
ax=axamp,
5253
label="Amplitude",
@@ -68,7 +69,7 @@ def update(val):
6869
amp_slider.on_changed(update)
6970

7071
# Create a `matplotlib.widgets.Button` to reset the sliders to initial values.
71-
resetax = plt.axes([0.8, 0.025, 0.1, 0.04])
72+
resetax = fig.add_axes([0.8, 0.025, 0.1, 0.04])
7273
button = Button(resetax, 'Reset', hovercolor='0.975')
7374

7475

examples/widgets/slider_snap_demo.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
See :doc:`/gallery/widgets/range_slider` for an example of using
1616
a ``RangeSlider`` to define a range of values.
1717
"""
18+
1819
import numpy as np
1920
import matplotlib.pyplot as plt
2021
from matplotlib.widgets import Slider, Button
@@ -25,11 +26,11 @@
2526
s = a0 * np.sin(2 * np.pi * f0 * t)
2627

2728
fig, ax = plt.subplots()
28-
plt.subplots_adjust(bottom=0.25)
29-
l, = plt.plot(t, s, lw=2)
29+
fig.subplots_adjust(bottom=0.25)
30+
l, = ax.plot(t, s, lw=2)
3031

31-
ax_freq = plt.axes([0.25, 0.1, 0.65, 0.03])
32-
ax_amp = plt.axes([0.25, 0.15, 0.65, 0.03])
32+
ax_freq = fig.add_axes([0.25, 0.1, 0.65, 0.03])
33+
ax_amp = fig.add_axes([0.25, 0.15, 0.65, 0.03])
3334

3435
# define the values to use for snapping
3536
allowed_amplitudes = np.concatenate([np.linspace(.1, 5, 100), [6, 7, 8, 9]])
@@ -58,7 +59,7 @@ def update(val):
5859
sfreq.on_changed(update)
5960
samp.on_changed(update)
6061

61-
ax_reset = plt.axes([0.8, 0.025, 0.1, 0.04])
62+
ax_reset = fig.add_axes([0.8, 0.025, 0.1, 0.04])
6263
button = Button(ax_reset, 'Reset', hovercolor='0.975')
6364

6465

0 commit comments

Comments
 (0)