Skip to content

Commit 6179526

Browse files
authored
Merge pull request #8983 from dstansby/pylab-moves
Final batch of pylab example moves
2 parents a57a80c + 9b66083 commit 6179526

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+62
-55
lines changed

doc/faq/howto_faq.rst

+1-1

doc/users/prev_whats_new/whats_new_1.3.rst

+4-4

examples/pylab_examples/ginput_manual_clabel_sgskip.py renamed to examples/event_handling/ginput_manual_clabel_sgskip.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def tellme(s):
3232
##################################################
3333
# Define a triangle by clicking three points
3434

35+
3536
plt.clf()
3637
plt.axis([-1., 1., -1., 1.])
3738
plt.setp(plt.gca(), autoscale_on=False)
@@ -73,6 +74,7 @@ def f(x, y, pts):
7374
z = z + 1/(np.sqrt((x - p[0])**2 + (y - p[1])**2))
7475
return 1/z
7576

77+
7678
X, Y = np.meshgrid(np.linspace(-1, 1, 51), np.linspace(-1, 1, 51))
7779
Z = f(X, Y, pts)
7880

examples/pylab_examples/demo_bboximage.py renamed to examples/images_contours_and_fields/demo_bboximage.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
not m.startswith(('spectral', 'Vega')) # Skip deprecated colormaps.
3838
)
3939

40-
#fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
40+
# fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
4141

4242
ncol = 2
4343
nrow = len(maps)//ncol + 1
@@ -50,7 +50,7 @@
5050

5151
for i, m in enumerate(maps):
5252
ix, iy = divmod(i, nrow)
53-
#plt.figimage(a, 10, i*10, cmap=plt.get_cmap(m), origin='lower')
53+
# plt.figimage(a, 10, i*10, cmap=plt.get_cmap(m), origin='lower')
5454
bbox0 = Bbox.from_bounds(ix*dx*(1 + xpad_fraction),
5555
1. - iy*dy*(1 + ypad_fraction) - dy,
5656
dx, dy)

examples/pylab_examples/markevery_demo.py renamed to examples/lines_bars_and_markers/markevery_demo.py

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
ax.append(fig1.add_subplot(gs[row, col]))
5656
ax[-1].set_title('markevery=%s' % str(case))
5757
ax[-1].plot(x, y, 'o', ls='-', ms=4, markevery=case)
58-
#fig1.tight_layout()
5958

6059
###############################################################################
6160
# Plot each markevery case for log x and y scales

examples/pylab_examples/nan_test.py renamed to examples/lines_bars_and_markers/nan_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@
3030
plt.ylabel('more nans')
3131
plt.grid(True)
3232

33+
plt.tight_layout()
3334
plt.show()

examples/pylab_examples/xcorr_acorr_demo.py renamed to examples/lines_bars_and_markers/xcorr_acorr_demo.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
Cross- and Auto-Correlation Demo
44
================================
55
6-
Example use of cross-correlation (``xcorr``) and auto-correlation (``acorr``) plots.
6+
Example use of cross-correlation (`xcorr`) and auto-correlation (`acorr`)
7+
plots.
78
"""
89
import matplotlib.pyplot as plt
910
import numpy as np
@@ -14,13 +15,11 @@
1415

1516

1617
x, y = np.random.randn(2, 100)
17-
fig = plt.figure()
18-
ax1 = fig.add_subplot(211)
18+
fig, [ax1, ax2] = plt.subplots(2, 1, sharex=True)
1919
ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)
2020
ax1.grid(True)
2121
ax1.axhline(0, color='black', lw=2)
2222

23-
ax2 = fig.add_subplot(212, sharex=ax1)
2423
ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)
2524
ax2.grid(True)
2625
ax2.axhline(0, color='black', lw=2)
File renamed without changes.

examples/pylab_examples/anchored_artists.py renamed to examples/misc/anchored_artists.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212

1313
class AnchoredText(AnchoredOffsetbox):
14-
def __init__(self, s, loc, pad=0.4, borderpad=0.5, prop=None, frameon=True):
14+
def __init__(self, s, loc, pad=0.4, borderpad=0.5,
15+
prop=None, frameon=True):
1516

1617
self.txt = TextArea(s,
1718
minimumdescent=False)
@@ -26,8 +27,8 @@ class AnchoredSizeBar(AnchoredOffsetbox):
2627
def __init__(self, transform, size, label, loc,
2728
pad=0.1, borderpad=0.1, sep=2, prop=None, frameon=True):
2829
"""
29-
Draw a horizontal bar with the size in data coordinate of the give axes.
30-
A label will be drawn underneath (center-aligned).
30+
Draw a horizontal bar with the size in data coordinate of the given
31+
axes. A label will be drawn underneath (center-aligned).
3132
3233
pad, borderpad in fraction of the legend font size (or prop)
3334
sep in points.
@@ -71,7 +72,8 @@ def __init__(self, width, height, xdescent, ydescent,
7172

7273
self.da = DrawingArea(width, height, xdescent, ydescent)
7374

74-
super(AnchoredDrawingArea, self).__init__(loc, pad=pad, borderpad=borderpad,
75+
super(AnchoredDrawingArea, self).__init__(loc, pad=pad,
76+
borderpad=borderpad,
7577
child=self.da,
7678
prop=None,
7779
frameon=frameon)

examples/pylab_examples/coords_report.py renamed to examples/misc/coords_report.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
def millions(x):
1414
return '$%1.1fM' % (x*1e-6)
1515

16+
1617
# Fixing random state for reproducibility
1718
np.random.seed(19680801)
1819

examples/pylab_examples/cursor_demo_sgskip.py renamed to examples/misc/cursor_demo_sgskip.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ def mouse_move(self, event):
7777
plt.draw()
7878

7979
t = np.arange(0.0, 1.0, 0.01)
80-
s = np.sin(2*2*np.pi*t)
80+
s = np.sin(2 * 2 * np.pi * t)
8181
fig, ax = plt.subplots()
8282

83-
#cursor = Cursor(ax)
83+
# cursor = Cursor(ax)
8484
cursor = SnaptoCursor(ax, t, s)
8585
plt.connect('motion_notify_event', cursor.mouse_move)
8686

examples/pylab_examples/customize_rc.py renamed to examples/misc/customize_rc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def set_pub():
1515
rc('font', weight='bold') # bold fonts are easier to see
1616
rc('tick', labelsize=15) # tick labels bigger
17-
rc('lines', lw=1, color='k') # thicker black lines (no budget for color!)
17+
rc('lines', lw=1, color='k') # thicker black lines
1818
rc('grid', c='0.5', ls='-', lw=0.5) # solid gray grid lines
1919
rc('savefig', dpi=300) # higher res outputs
2020

examples/pylab_examples/demo_agg_filter.py renamed to examples/misc/demo_agg_filter.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import numpy as np
1010
import matplotlib.cm as cm
1111
import matplotlib.mlab as mlab
12+
import matplotlib.transforms as mtransforms
13+
from matplotlib.colors import LightSource
14+
from matplotlib.artist import Artist
1215

1316

1417
def smooth1d(x, window_len):
@@ -34,7 +37,7 @@ def smooth2d(A, sigma=3):
3437
class BaseFilter(object):
3538
def prepare_image(self, src_image, dpi, pad):
3639
ny, nx, depth = src_image.shape
37-
#tgt_image = np.zeros([pad*2+ny, pad*2+nx, depth], dtype="d")
40+
# tgt_image = np.zeros([pad*2+ny, pad*2+nx, depth], dtype="d")
3841
padded_src = np.zeros([pad*2 + ny, pad*2 + nx, depth], dtype="d")
3942
padded_src[pad:-pad, pad:-pad, :] = src_image[:, :, :]
4043

@@ -82,7 +85,7 @@ def get_pad(self, dpi):
8285
return int(self.sigma*3/72.*dpi)
8386

8487
def process_image(self, padded_src, dpi):
85-
#offsetx, offsety = int(self.offsets[0]), int(self.offsets[1])
88+
# offsetx, offsety = int(self.offsets[0]), int(self.offsets[1])
8689
tgt_image = np.zeros_like(padded_src)
8790
aa = smooth2d(padded_src[:, :, -1]*self.alpha,
8891
self.sigma/72.*dpi)
@@ -106,9 +109,6 @@ def process_image(self, padded_src, dpi):
106109
return t2
107110

108111

109-
from matplotlib.colors import LightSource
110-
111-
112112
class LightFilter(BaseFilter):
113113
"simple gauss filter"
114114

@@ -160,9 +160,6 @@ def __call__(self, im, dpi):
160160
return new_im, offsetx, offsety
161161

162162

163-
from matplotlib.artist import Artist
164-
165-
166163
class FilteredArtistList(Artist):
167164
"""
168165
A simple container to draw filtered artist.
@@ -182,9 +179,6 @@ def draw(self, renderer):
182179
renderer.stop_rasterizing()
183180

184181

185-
import matplotlib.transforms as mtransforms
186-
187-
188182
def filtered_text(ax):
189183
# mostly copied from contour_demo.py
190184

@@ -281,9 +275,10 @@ def drop_shadow_patches(ax):
281275
rects1 = ax.bar(ind, menMeans, width, color='r', ec="w", lw=2)
282276

283277
womenMeans = (25, 32, 34, 20, 25)
284-
rects2 = ax.bar(ind + width + 0.1, womenMeans, width, color='y', ec="w", lw=2)
278+
rects2 = ax.bar(ind + width + 0.1, womenMeans, width,
279+
color='y', ec="w", lw=2)
285280

286-
#gauss = GaussianFilter(1.5, offsets=(1,1), )
281+
# gauss = GaussianFilter(1.5, offsets=(1,1), )
287282
gauss = DropShadowFilter(5, offsets=(1, 1), )
288283
shadow = FilteredArtistList(rects1 + rects2, gauss)
289284
ax.add_artist(shadow)
File renamed without changes.

examples/pylab_examples/findobj_demo.py renamed to examples/misc/findobj_demo.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
def myfunc(x):
3030
return hasattr(x, 'set_color') and not hasattr(x, 'set_facecolor')
3131

32+
3233
for o in fig.findobj(myfunc):
3334
o.set_color('blue')
3435

examples/pylab_examples/patheffect_demo.py renamed to examples/misc/patheffect_demo.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
txt = ax1.annotate("test", (1., 1.), (0., 0),
1616
arrowprops=dict(arrowstyle="->",
1717
connectionstyle="angle3", lw=2),
18-
size=20, ha="center", path_effects=[PathEffects.withStroke(linewidth=3,
19-
foreground="w")])
18+
size=20, ha="center",
19+
path_effects=[PathEffects.withStroke(linewidth=3,
20+
foreground="w")])
2021
txt.arrow_patch.set_path_effects([
2122
PathEffects.Stroke(linewidth=5, foreground="w"),
2223
PathEffects.Normal()])
File renamed without changes.

examples/pylab_examples/transoffset.py renamed to examples/misc/transoffset.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
# offset_copy works for polar plots also.
4747
ax = plt.subplot(2, 1, 2, projection='polar')
4848

49-
trans_offset = mtransforms.offset_copy(ax.transData, fig=fig, y=6, units='dots')
49+
trans_offset = mtransforms.offset_copy(ax.transData, fig=fig,
50+
y=6, units='dots')
5051

5152
for x, y in zip(xs, ys):
5253
plt.polar((x,), (y,), 'ro')

examples/pylab_examples/webapp_demo_sgskip.py renamed to examples/misc/webapp_demo_sgskip.py

+1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ def make_fig():
6060

6161
FigureCanvasAgg(fig).print_png('webapp.png', dpi=150)
6262

63+
6364
make_fig()

examples/pylab_examples/zorder_demo.py renamed to examples/misc/zorder_demo.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@
5656

5757
x = np.linspace(0, 2*np.pi, 100)
5858
plt.figure()
59-
plt.plot(x, np.sin(x), linewidth=10, color='black', label='zorder=10', zorder=10) # on top
60-
plt.plot(x, np.cos(1.3*x), linewidth=10, color='red', label='zorder=1', zorder=1) # bottom
61-
plt.plot(x, np.sin(2.1*x), linewidth=10, color='green', label='zorder=3', zorder=3)
62-
plt.axhline(0, linewidth=10, color='blue', label='zorder=2', zorder=2)
59+
plt.plot(x, np.sin(x), linewidth=10, color='black', label='zorder=10',
60+
zorder=10) # on top
61+
plt.plot(x, np.cos(1.3*x), linewidth=10, color='red', label='zorder=1',
62+
zorder=1) # bottom
63+
plt.plot(x, np.sin(2.1*x), linewidth=10, color='green', label='zorder=3',
64+
zorder=3)
65+
plt.axhline(0, linewidth=10, color='blue', label='zorder=2',
66+
zorder=2)
6367
plt.title('Custom order of elements')
6468
l = plt.legend()
6569
l.set_zorder(20) # put the legend on top

examples/pylab_examples/README.txt

-4
This file was deleted.

examples/pylab_examples/symlog_demo.py renamed to examples/scales/symlog_demo.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@
3131
plt.grid(True)
3232
plt.ylabel('symlog both')
3333

34-
plt.subplots_adjust(hspace=0.5, left=0.2)
35-
34+
plt.tight_layout()
3635
plt.show()

examples/pylab_examples/hatch_demo.py renamed to examples/shapes_and_collections/hatch_demo.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
fig = plt.figure()
1313
ax1 = fig.add_subplot(131)
1414
ax1.bar(range(1, 5), range(1, 5), color='red', edgecolor='black', hatch="/")
15-
ax1.bar(range(1, 5), [6] * 4, bottom=range(1, 5), color='blue', edgecolor='black', hatch='//')
15+
ax1.bar(range(1, 5), [6] * 4, bottom=range(1, 5),
16+
color='blue', edgecolor='black', hatch='//')
1617
ax1.set_xticks([1.5, 2.5, 3.5, 4.5])
1718

1819
ax2 = fig.add_subplot(132)
1920
bars = ax2.bar(range(1, 5), range(1, 5), color='yellow', ecolor='black') + \
20-
ax2.bar(range(1, 5), [6] * 4, bottom=range(1, 5), color='green', ecolor='black')
21+
ax2.bar(range(1, 5), [6] * 4, bottom=range(1, 5),
22+
color='green', ecolor='black')
2123
ax2.set_xticks([1.5, 2.5, 3.5, 4.5])
2224

2325
patterns = ('-', '+', 'x', '\\', '*', 'o', 'O', '.')

examples/pylab_examples/demo_text_path.py renamed to examples/text_labels_and_annotations/demo_text_path.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def draw(self, renderer=None):
7474
p = PathClippedImagePatch(text_path, arr, ec="k",
7575
transform=IdentityTransform())
7676

77-
#p.set_clip_on(False)
77+
# p.set_clip_on(False)
7878

7979
# make offset box
8080
offsetbox = AuxTransformBox(IdentityTransform())
@@ -122,15 +122,18 @@ def draw(self, renderer=None):
122122
arr = np.arange(256).reshape(1, 256)/256.
123123

124124
if usetex:
125-
s = r"$\displaystyle\left[\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}\right]$!"
125+
s = (r"$\displaystyle\left[\sum_{n=1}^\infty"
126+
r"\frac{-e^{i\pi}}{2^n}\right]$!")
126127
else:
127128
s = r"$\left[\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}\right]$!"
128129
text_path = TextPath((0, 0), s, size=40, usetex=usetex)
129130
text_patch = PathClippedImagePatch(text_path, arr, ec="none",
130131
transform=IdentityTransform())
131132

132-
shadow1 = mpatches.Shadow(text_patch, 1, -1, props=dict(fc="none", ec="0.6", lw=3))
133-
shadow2 = mpatches.Shadow(text_patch, 1, -1, props=dict(fc="0.3", ec="none"))
133+
shadow1 = mpatches.Shadow(text_patch, 1, -1,
134+
props=dict(fc="none", ec="0.6", lw=3))
135+
shadow2 = mpatches.Shadow(text_patch, 1, -1,
136+
props=dict(fc="0.3", ec="none"))
134137

135138
# make offset box
136139
offsetbox = AuxTransformBox(IdentityTransform())
@@ -144,7 +147,7 @@ def draw(self, renderer=None):
144147
boxcoords="offset points",
145148
box_alignment=(0.5, 0.5),
146149
)
147-
#text_path.set_size(10)
150+
# text_path.set_size(10)
148151

149152
ax.add_artist(ab)
150153

lib/matplotlib/axes/_axes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
11601160
Examples
11611161
--------
11621162
1163-
.. plot:: mpl_examples/pylab_examples/eventplot_demo.py
1163+
.. plot:: mpl_examples/lines_bars_and_markers/eventplot_demo.py
11641164
"""
11651165
self._process_unit_info(xdata=positions,
11661166
ydata=[lineoffsets, linelengths],

lib/matplotlib/collections.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ def __init__(self,
13031303
Examples
13041304
--------
13051305
1306-
.. plot:: mpl_examples/pylab_examples/eventcollection_demo.py
1306+
.. plot:: mpl_examples/lines_bars_and_markers/eventcollection_demo.py
13071307
"""
13081308

13091309
segment = (lineoffset + linelength / 2.,

lib/matplotlib/dates.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class bytespdate2num(strpdate2num):
291291
"""
292292
Use this class to parse date strings to matplotlib datenums when
293293
you know the date format string of the date you are parsing. See
294-
:file:`examples/pylab_examples/load_converter.py`.
294+
:file:`examples/misc/load_converter.py`.
295295
"""
296296
def __init__(self, fmt, encoding='utf-8'):
297297
"""

0 commit comments

Comments
 (0)