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

Skip to content

Commit 7471077

Browse files
committed
fix the plot directive
svn path=/trunk/matplotlib/; revision=8896
1 parent f2ea760 commit 7471077

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

examples/animation/dynamic_image2.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ def f(x, y):
1313

1414
x = np.linspace(0, 2 * np.pi, 120)
1515
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
16-
16+
# ims is a list of lists, each row is a list of artists to draw in the
17+
# current frame; here we are just animating one artist, the image, in
18+
# each frame
1719
ims = []
1820
for i in range(60):
1921
x += np.pi / 15.
2022
y += np.pi / 20.
21-
ims.append([plt.imshow(f(x, y), cmap=plt.get_cmap('jet'))])
23+
im = plt.imshow(f(x, y))
24+
ims.append([im])
2225

2326
ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
2427
repeat_delay=1000)
28+
29+
ani.save('dynamic_images.mp4')
30+
31+
2532
plt.show()

examples/animation/strip_chart_demo.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import matplotlib.animation as animation
1010

1111
class Scope:
12-
def __init__(self, ax, maxt=10, dt=0.01):
12+
def __init__(self, ax, maxt=2, dt=0.02):
1313
self.ax = ax
1414
self.dt = dt
1515
self.maxt = maxt
@@ -26,14 +26,16 @@ def update(self, y):
2626
self.tdata = [self.tdata[-1]]
2727
self.ydata = [self.ydata[-1]]
2828
self.ax.set_xlim(self.tdata[0], self.tdata[0] + self.maxt)
29+
self.ax.figure.canvas.draw()
2930

3031
t = self.tdata[-1] + self.dt
3132
self.tdata.append(t)
3233
self.ydata.append(y)
3334
self.line.set_data(self.tdata, self.ydata)
3435
return self.line,
3536

36-
def emitter(p=0.01):
37+
38+
def emitter(p=0.03):
3739
'return a random value with probability p, else 0'
3840
while True:
3941
v = np.random.rand(1)
@@ -45,6 +47,10 @@ def emitter(p=0.01):
4547
fig = plt.figure()
4648
ax = fig.add_subplot(111)
4749
scope = Scope(ax)
50+
51+
# pass a generator in "emitter" to produce data for the update func
4852
ani = animation.FuncAnimation(fig, scope.update, emitter, interval=10,
4953
blit=True)
54+
55+
5056
plt.show()

lib/matplotlib/figure.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,6 @@ def draw(self, renderer):
807807
Render the figure using :class:`matplotlib.backend_bases.RendererBase` instance renderer
808808
"""
809809
# draw the figure bounding box, perhaps none for white figure
810-
#print 'figure draw'
811810
if not self.get_visible(): return
812811
renderer.open_group('figure')
813812

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ def run_savefig(plot_path, basename, tmpdir, destdir, formats):
265265

266266
def clear_state():
267267
plt.close('all')
268-
matplotlib.rc_file_defaults()
268+
matplotlib.rcdefaults()
269+
# Set a default figure size that doesn't overflow typical browser
270+
# windows. The script is free to override it if necessary.
271+
matplotlib.rcParams['figure.figsize'] = (5.5, 4.5)
269272

270273
def render_figures(plot_path, function_name, plot_code, tmpdir, destdir,
271274
formats, context=False):

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,13 @@ def test_pcolormesh():
512512

513513
fig.savefig('pcolormesh')
514514

515+
516+
@image_comparison(baseline_images=['canonical'])
517+
def test_canonical():
518+
fig, ax = plt.subplots()
519+
ax.plot([1,2,3])
520+
fig.savefig('canonical')
521+
515522
if __name__=='__main__':
516523
import nose
517524
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 commit comments

Comments
 (0)