diff --git a/examples/animation/old_animation/README.txt b/examples/animation/old_animation/README.txt deleted file mode 100644 index 7a64c50f3b00..000000000000 --- a/examples/animation/old_animation/README.txt +++ /dev/null @@ -1,7 +0,0 @@ -matplotlib animations -===================== - -There are a variety of techniques you can use to create dynamic plots, -which I refer to as animations. See the tutorial at -http://www.scipy.org/Cookbook/Matplotlib/Animations for an -introduction to the basic concepts diff --git a/examples/animation/old_animation/animate_decay_tk_blit.py b/examples/animation/old_animation/animate_decay_tk_blit.py deleted file mode 100644 index 36e451f803f6..000000000000 --- a/examples/animation/old_animation/animate_decay_tk_blit.py +++ /dev/null @@ -1,58 +0,0 @@ -from __future__ import print_function -import time, sys -import numpy as np -import matplotlib.pyplot as plt - - -def data_gen(): - t = data_gen.t - data_gen.t += 0.05 - return np.sin(2*np.pi*t) * np.exp(-t/10.) -data_gen.t = 0 - -fig, ax = plt.subplots() -line, = ax.plot([], [], animated=True, lw=2) -ax.set_ylim(-1.1, 1.1) -ax.set_xlim(0, 5) -ax.grid() -xdata, ydata = [], [] -def run(*args): - background = fig.canvas.copy_from_bbox(ax.bbox) - # for profiling - tstart = time.time() - - while 1: - # restore the clean slate background - fig.canvas.restore_region(background) - # update the data - t = data_gen.t - y = data_gen() - xdata.append(t) - ydata.append(y) - xmin, xmax = ax.get_xlim() - if t>=xmax: - ax.set_xlim(xmin, 2*xmax) - fig.canvas.draw() - background = fig.canvas.copy_from_bbox(ax.bbox) - - line.set_data(xdata, ydata) - - # just draw the animated artist - ax.draw_artist(line) - # just redraw the axes rectangle - fig.canvas.blit(ax.bbox) - - if run.cnt==1000: - # print the timing info and quit - print('FPS:' , 1000/(time.time()-tstart)) - sys.exit() - - run.cnt += 1 -run.cnt = 0 - - - -manager = plt.get_current_fig_manager() -manager.window.after(100, run) - -plt.show() diff --git a/examples/animation/old_animation/animation_blit_gtk.py b/examples/animation/old_animation/animation_blit_gtk.py deleted file mode 100755 index 9200daf778f7..000000000000 --- a/examples/animation/old_animation/animation_blit_gtk.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python - -from __future__ import print_function - -# For detailed comments on animation and the techniques used here, see -# the wiki entry -# http://www.scipy.org/wikis/topical_software/MatplotlibAnimation -import time - -import gtk, gobject - -import matplotlib -matplotlib.use('GTKAgg') - -import numpy as np -import matplotlib.pyplot as plt - - -fig, ax = plt.subplots() -canvas = fig.canvas - -fig.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs -ax.grid() # to ensure proper background restore - -# create the initial line -x = np.arange(0,2*np.pi,0.01) -line, = ax.plot(x, np.sin(x), animated=True, lw=2) -canvas.draw() - -# for profiling -tstart = time.time() - -def update_line(*args): - print('you are here', update_line.cnt) - if update_line.background is None: - update_line.background = canvas.copy_from_bbox(ax.bbox) - - # restore the clean slate background - canvas.restore_region(update_line.background) - # update the data - line.set_ydata(np.sin(x+update_line.cnt/10.0)) - # just draw the animated artist - ax.draw_artist(line) - - # just redraw the axes rectangle - canvas.blit(ax.bbox) - - if update_line.cnt==1000: - # print the timing info and quit - print('FPS:' , 1000/(time.time()-tstart)) - gtk.mainquit() - raise SystemExit - - update_line.cnt += 1 - return True - -update_line.cnt = 0 -update_line.background = None - - -def start_anim(event): - gobject.idle_add(update_line) - canvas.mpl_disconnect(start_anim.cid) - -start_anim.cid = canvas.mpl_connect('draw_event', start_anim) - - - -plt.show() diff --git a/examples/animation/old_animation/animation_blit_gtk2.py b/examples/animation/old_animation/animation_blit_gtk2.py deleted file mode 100755 index 58673fd95c2d..000000000000 --- a/examples/animation/old_animation/animation_blit_gtk2.py +++ /dev/null @@ -1,168 +0,0 @@ -#!/usr/bin/env python - -from __future__ import print_function - -""" -This example utlizes restore_region with optional bbox and xy -arguments. The plot is continuously shifted to the left. Instead of -drawing everything again, the plot is saved (copy_from_bbox) and -restored with offset by the amount of the shift. And only newly -exposed area is drawn. This technique may reduce drawing time for some cases. -""" - -import time - -import gtk, gobject - -import matplotlib -matplotlib.use('GTKAgg') - -import numpy as np -import matplotlib.pyplot as plt - -class UpdateLine(object): - def get_bg_bbox(self): - - return self.ax.bbox.padded(-3) - - def __init__(self, canvas, ax): - self.cnt = 0 - self.canvas = canvas - self.ax = ax - - self.prev_time = time.time() - self.start_time = self.prev_time - self.prev_pixel_offset = 0. - - - self.x0 = 0 - self.phases = np.random.random_sample((20,)) * np.pi * 2 - self.line, = ax.plot([], [], "-", animated=True, lw=2) - - self.point, = ax.plot([], [], "ro", animated=True, lw=2) - - self.ax.set_ylim(-1.1, 1.1) - - self.background1 = None - - cmap = plt.cm.jet - from itertools import cycle - self.color_cycle = cycle(cmap(np.arange(cmap.N))) - - - def save_bg(self): - self.background1 = self.canvas.copy_from_bbox(self.ax.get_figure().bbox) - - self.background2 = self.canvas.copy_from_bbox(self.get_bg_bbox()) - - - def get_dx_data(self, dx_pixel): - tp = self.ax.transData.inverted().transform_point - x0, y0 = tp((0, 0)) - x1, y1 = tp((dx_pixel, 0)) - return (x1-x0) - - - def restore_background_shifted(self, dx_pixel): - """ - restore bacground shifted by dx in data coordinate. This only - works if the data coordinate system is linear. - """ - - # restore the clean slate background - self.canvas.restore_region(self.background1) - - # restore subregion (x1+dx, y1, x2, y2) of the second bg - # in a offset position (x1-dx, y1) - x1, y1, x2, y2 = self.background2.get_extents() - self.canvas.restore_region(self.background2, - bbox=(x1+dx_pixel, y1, x2, y2), - xy=(x1-dx_pixel, y1)) - - return dx_pixel - - def on_draw(self, *args): - self.save_bg() - return False - - def update_line(self, *args): - - if self.background1 is None: - return True - - cur_time = time.time() - pixel_offset = int((cur_time - self.start_time)*100.) - dx_pixel = pixel_offset - self.prev_pixel_offset - self.prev_pixel_offset = pixel_offset - dx_data = self.get_dx_data(dx_pixel) #cur_time - self.prev_time) - - x0 = self.x0 - self.x0 += dx_data - self.prev_time = cur_time - - self.ax.set_xlim(self.x0-2, self.x0+0.1) - - - # restore background which will plot lines from previous plots - self.restore_background_shifted(dx_pixel) #x0, self.x0) - # This restores lines between [x0-2, x0] - - - - self.line.set_color(self.color_cycle.next()) - - # now plot line segment within [x0, x0+dx_data], - # Note that we're only plotting a line between [x0, x0+dx_data]. - xx = np.array([x0, self.x0]) - self.line.set_xdata(xx) - - # the for loop below could be improved by using collection. - [(self.line.set_ydata(np.sin(xx+p)), - self.ax.draw_artist(self.line)) \ - for p in self.phases] - - self.background2 = canvas.copy_from_bbox(self.get_bg_bbox()) - - self.point.set_xdata([self.x0]) - - [(self.point.set_ydata(np.sin([self.x0+p])), - self.ax.draw_artist(self.point)) \ - for p in self.phases] - - - self.ax.draw_artist(self.ax.xaxis) - self.ax.draw_artist(self.ax.yaxis) - - self.canvas.blit(self.ax.get_figure().bbox) - - - dt = (time.time()-tstart) - if dt>15: - # print the timing info and quit - print('FPS:' , self.cnt/dt) - gtk.main_quit() - raise SystemExit - - self.cnt += 1 - return True - - -plt.rcParams["text.usetex"] = False - -fig, ax = plt.subplots() -ax.xaxis.set_animated(True) -ax.yaxis.set_animated(True) -canvas = fig.canvas - -fig.subplots_adjust(left=0.2, bottom=0.2) -canvas.draw() - -# for profiling -tstart = time.time() - -ul = UpdateLine(canvas, ax) -gobject.idle_add(ul.update_line) - -canvas.mpl_connect('draw_event', ul.on_draw) - -plt.show() diff --git a/examples/animation/old_animation/animation_blit_qt4.py b/examples/animation/old_animation/animation_blit_qt4.py deleted file mode 100644 index 6ae56e19a4af..000000000000 --- a/examples/animation/old_animation/animation_blit_qt4.py +++ /dev/null @@ -1,83 +0,0 @@ -# For detailed comments on animation and the techniqes used here, see -# the wiki entry http://www.scipy.org/Cookbook/Matplotlib/Animations - -from __future__ import print_function - -import os -import sys - -#import matplotlib -#matplotlib.use('Qt4Agg') -from matplotlib.figure import Figure -from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas - -from matplotlib.backends import qt4_compat -use_pyside = qt4_compat.QT_API == qt4_compat.QT_API_PYSIDE - -if use_pyside: - from PySide import QtCore, QtGui -else: - from PyQt4 import QtCore, QtGui - -ITERS = 1000 - -import numpy as np -import time - -class BlitQT(FigureCanvas): - - def __init__(self): - FigureCanvas.__init__(self, Figure()) - - self.ax = self.figure.add_subplot(111) - self.ax.grid() - self.draw() - - self.old_size = self.ax.bbox.width, self.ax.bbox.height - self.ax_background = self.copy_from_bbox(self.ax.bbox) - self.cnt = 0 - - self.x = np.arange(0,2*np.pi,0.01) - self.sin_line, = self.ax.plot(self.x, np.sin(self.x), animated=True) - self.cos_line, = self.ax.plot(self.x, np.cos(self.x), animated=True) - self.draw() - - self.tstart = time.time() - self.startTimer(10) - - def timerEvent(self, evt): - current_size = self.ax.bbox.width, self.ax.bbox.height - if self.old_size != current_size: - self.old_size = current_size - self.ax.clear() - self.ax.grid() - self.draw() - self.ax_background = self.copy_from_bbox(self.ax.bbox) - - self.restore_region(self.ax_background) - - # update the data - self.sin_line.set_ydata(np.sin(self.x+self.cnt/10.0)) - self.cos_line.set_ydata(np.cos(self.x+self.cnt/10.0)) - # just draw the animated artist - self.ax.draw_artist(self.sin_line) - self.ax.draw_artist(self.cos_line) - # just redraw the axes rectangle - self.blit(self.ax.bbox) - - if self.cnt == 0: - # TODO: this shouldn't be necessary, but if it is excluded the - # canvas outside the axes is not initially painted. - self.draw() - if self.cnt==ITERS: - # print the timing info and quit - print('FPS:' , ITERS/(time.time()-self.tstart)) - sys.exit() - else: - self.cnt += 1 - -app = QtGui.QApplication(sys.argv) -widget = BlitQT() -widget.show() - -sys.exit(app.exec_()) diff --git a/examples/animation/old_animation/animation_blit_tk.py b/examples/animation/old_animation/animation_blit_tk.py deleted file mode 100644 index 19779aba4a15..000000000000 --- a/examples/animation/old_animation/animation_blit_tk.py +++ /dev/null @@ -1,54 +0,0 @@ -# For detailed comments on animation and the techniqes used here, see -# the wiki entry http://www.scipy.org/Cookbook/Matplotlib/Animations - -from __future__ import print_function - -import matplotlib -matplotlib.use('TkAgg') - -import sys -import matplotlib.pyplot as plt -import numpy as npy -import time - -fig, ax = plt.subplots() -canvas = fig.canvas - - -# create the initial line -x = npy.arange(0,2*npy.pi,0.01) -line, = plt.plot(x, npy.sin(x), animated=True, lw=2) - -def run(*args): - background = canvas.copy_from_bbox(ax.bbox) - # for profiling - tstart = time.time() - - while 1: - # restore the clean slate background - canvas.restore_region(background) - # update the data - line.set_ydata(npy.sin(x+run.cnt/10.0)) - # just draw the animated artist - ax.draw_artist(line) - # just redraw the axes rectangle - canvas.blit(ax.bbox) - - if run.cnt==1000: - # print the timing info and quit - print('FPS:', 1000/(time.time()-tstart)) - sys.exit() - - run.cnt += 1 -run.cnt = 0 - - -plt.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs -plt.grid() # to ensure proper background restore -manager = plt.get_current_fig_manager() -manager.window.after(100, run) - -plt.show() - - - diff --git a/examples/animation/old_animation/animation_blit_wx.py b/examples/animation/old_animation/animation_blit_wx.py deleted file mode 100644 index dc7d90c75bc6..000000000000 --- a/examples/animation/old_animation/animation_blit_wx.py +++ /dev/null @@ -1,79 +0,0 @@ -# For detailed comments on animation and the techniqes used here, see -# the wiki entry -# http://www.scipy.org/wikis/topical_software/MatplotlibAnimation - -from __future__ import print_function - -# The number of blits() to make before exiting -NBLITS = 1000 - -import matplotlib -matplotlib.use('WXAgg') -matplotlib.rcParams['toolbar'] = 'None' -import matplotlib.pyplot as plt - -import wx -import sys -import pylab as p -import numpy as npy -import time - - -# allow the user to disable the WXAgg accelerator from the command line -if '--no-accel' in sys.argv: - import matplotlib.backends.backend_wxagg - matplotlib.backends.backend_wxagg._use_accelerator(False) - - -fig, ax = plt.subplots() -canvas = fig.canvas - - -p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs -p.grid() # to ensure proper background restore - -# create the initial line -x = npy.arange(0,2*npy.pi,0.01) -line, = p.plot(x, npy.sin(x), animated=True, lw=2) - -# for profiling -tstart = time.time() -blit_time = 0.0 - -def update_line(*args): - global blit_time - - if update_line.background is None: - update_line.background = canvas.copy_from_bbox(ax.bbox) - - # restore the clean slate background - canvas.restore_region(update_line.background) - # update the data - line.set_ydata(npy.sin(x+update_line.cnt/10.0)) - # just draw the animated artist - ax.draw_artist(line) - # just redraw the axes rectangle - - t = time.time() - canvas.blit(ax.bbox) - blit_time += time.time() - t - - if update_line.cnt == NBLITS: - # print the timing info and quit - frame_time = time.time() - tstart - print('%d frames: %.2f seconds' % (NBLITS, frame_time)) - print('%d blits: %.2f seconds' % (NBLITS, blit_time)) - print() - print('FPS: %.2f' % (NBLITS/frame_time)) - print('BPS: %.2f' % (NBLITS/blit_time)) - sys.exit() - - update_line.cnt += 1 - wx.WakeUpIdle() - - - -update_line.cnt = 0 -update_line.background = None -wx.EVT_IDLE(wx.GetApp(), update_line) -p.show() diff --git a/examples/animation/old_animation/draggable_legend.py b/examples/animation/old_animation/draggable_legend.py deleted file mode 100644 index 2a6d8041b6b8..000000000000 --- a/examples/animation/old_animation/draggable_legend.py +++ /dev/null @@ -1,42 +0,0 @@ -import matplotlib.pyplot as plt - -fig, ax = plt.subplots() -ax.plot([1,2,3], label="test") - -l = ax.legend() -d1 = l.draggable() - -xy = 1, 2 -txt = ax.annotate("Test", xy, xytext=(-30, 30), - textcoords="offset points", - bbox=dict(boxstyle="round",fc=(0.2, 1, 1)), - arrowprops=dict(arrowstyle="->")) -d2 = txt.draggable() - - -from matplotlib._png import read_png -from matplotlib.cbook import get_sample_data - -from matplotlib.offsetbox import OffsetImage, AnnotationBbox - -fn = get_sample_data("ada.png", asfileobj=False) -arr_ada = read_png(fn) - -imagebox = OffsetImage(arr_ada, zoom=0.2) - -ab = AnnotationBbox(imagebox, xy, - xybox=(120., -80.), - xycoords='data', - boxcoords="offset points", - pad=0.5, - arrowprops=dict(arrowstyle="->", - connectionstyle="angle,angleA=0,angleB=90,rad=3") - ) - - -ax.add_artist(ab) - -d3 = ab.draggable(use_blit=True) - - -plt.show() diff --git a/examples/animation/old_animation/dynamic_collection.py b/examples/animation/old_animation/dynamic_collection.py deleted file mode 100644 index 3b3fde572595..000000000000 --- a/examples/animation/old_animation/dynamic_collection.py +++ /dev/null @@ -1,52 +0,0 @@ -import random -from matplotlib.collections import RegularPolyCollection -import matplotlib.cm as cm -from matplotlib.pyplot import figure, show -from numpy.random import rand - -fig = figure() -ax = fig.add_subplot(111, xlim=(0,1), ylim=(0,1), autoscale_on=False) -ax.set_title("Press 'a' to add a point, 'd' to delete one") -# a single point -offsets = [(0.5,0.5)] -facecolors = [cm.jet(0.5)] - -collection = RegularPolyCollection( - #fig.dpi, - 5, # a pentagon - rotation=0, - sizes=(50,), - facecolors = facecolors, - edgecolors = 'black', - linewidths = (1,), - offsets = offsets, - transOffset = ax.transData, - ) - -ax.add_collection(collection) - -def onpress(event): - """ - press 'a' to add a random point from the collection, 'd' to delete one - """ - if event.key=='a': - x,y = rand(2) - color = cm.jet(rand()) - offsets.append((x,y)) - facecolors.append(color) - collection.set_offsets(offsets) - collection.set_facecolors(facecolors) - fig.canvas.draw() - elif event.key=='d': - N = len(offsets) - if N>0: - ind = random.randint(0,N-1) - offsets.pop(ind) - facecolors.pop(ind) - collection.set_offsets(offsets) - collection.set_facecolors(facecolors) - fig.canvas.draw() - -fig.canvas.mpl_connect('key_press_event', onpress) - -show() diff --git a/examples/animation/old_animation/dynamic_image_gtkagg.py b/examples/animation/old_animation/dynamic_image_gtkagg.py deleted file mode 100755 index 9e454897d7b8..000000000000 --- a/examples/animation/old_animation/dynamic_image_gtkagg.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python - -from __future__ import print_function -""" -An animated image -""" -import time - -import gobject -import gtk - -import matplotlib -matplotlib.use('GTKAgg') - -from pylab import * - -fig = figure(1) -a = subplot(111) -x = arange(120.0)*2*pi/120.0 -x = resize(x, (100,120)) -y = arange(100.0)*2*pi/100.0 -y = resize(y, (120,100)) -y = transpose(y) -z = sin(x) + cos(y) -im = a.imshow( z, cmap=cm.jet)#, interpolation='nearest') - -manager = get_current_fig_manager() -cnt = 0 -tstart = time.time() -def updatefig(*args): - global x, y, cnt, start - x += pi/15 - y += pi/20 - z = sin(x) + cos(y) - im.set_array(z) - manager.canvas.draw() - cnt += 1 - if cnt==50: - print('FPS', cnt/(time.time() - tstart)) - return False - return True - -cnt = 0 - -gobject.idle_add(updatefig) -show() diff --git a/examples/animation/old_animation/dynamic_image_wxagg2.py b/examples/animation/old_animation/dynamic_image_wxagg2.py deleted file mode 100644 index 81de26d79ca5..000000000000 --- a/examples/animation/old_animation/dynamic_image_wxagg2.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env python -""" -Copyright (C) 2003-2005 Jeremy O'Donoghue and others - -License: This work is licensed under the PSF. A copy should be included -with this source code, and is also available at -http://www.python.org/psf/license.html - -""" -import sys, time, os, gc - -import matplotlib -matplotlib.use('WXAgg') - -from matplotlib import rcParams -import numpy as npy - -import matplotlib.cm as cm - -from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg -from matplotlib.backends.backend_wx import NavigationToolbar2Wx - -from matplotlib.figure import Figure -from wx import * - - -TIMER_ID = NewId() - -class PlotFigure(Frame): - - def __init__(self): - Frame.__init__(self, None, -1, "Test embedded wxFigure") - - self.fig = Figure((5,4), 75) - self.canvas = FigureCanvasWxAgg(self, -1, self.fig) - self.toolbar = NavigationToolbar2Wx(self.canvas) - self.toolbar.Realize() - - # On Windows, default frame size behaviour is incorrect - # you don't need this under Linux - tw, th = self.toolbar.GetSizeTuple() - fw, fh = self.canvas.GetSizeTuple() - self.toolbar.SetSize(Size(fw, th)) - - # Create a figure manager to manage things - - # Now put all into a sizer - sizer = BoxSizer(VERTICAL) - # This way of adding to sizer allows resizing - sizer.Add(self.canvas, 1, LEFT|TOP|GROW) - # Best to allow the toolbar to resize! - sizer.Add(self.toolbar, 0, GROW) - self.SetSizer(sizer) - self.Fit() - EVT_TIMER(self, TIMER_ID, self.onTimer) - - def init_plot_data(self): - # jdh you can add a subplot directly from the fig rather than - # the fig manager - a = self.fig.add_axes([0.075,0.1,0.75,0.85]) - cax = self.fig.add_axes([0.85,0.1,0.075,0.85]) - self.x = npy.empty((120,120)) - self.x.flat = npy.arange(120.0)*2*npy.pi/120.0 - self.y = npy.empty((120,120)) - self.y.flat = npy.arange(120.0)*2*npy.pi/100.0 - self.y = npy.transpose(self.y) - z = npy.sin(self.x) + npy.cos(self.y) - self.im = a.imshow( z, cmap=cm.jet)#, interpolation='nearest') - self.fig.colorbar(self.im,cax=cax,orientation='vertical') - - def GetToolBar(self): - # You will need to override GetToolBar if you are using an - # unmanaged toolbar in your frame - return self.toolbar - - def onTimer(self, evt): - self.x += npy.pi/15 - self.y += npy.pi/20 - z = npy.sin(self.x) + npy.cos(self.y) - self.im.set_array(z) - self.canvas.draw() - #self.canvas.gui_repaint() # jdh wxagg_draw calls this already - - def onEraseBackground(self, evt): - # this is supposed to prevent redraw flicker on some X servers... - pass - -if __name__ == '__main__': - app = PySimpleApp() - frame = PlotFigure() - frame.init_plot_data() - - # Initialise the timer - wxPython requires this to be connected to - # the receiving event handler - t = Timer(frame, TIMER_ID) - t.Start(200) - - frame.Show() - app.MainLoop() - diff --git a/examples/animation/old_animation/gtk_timeout.py b/examples/animation/old_animation/gtk_timeout.py deleted file mode 100644 index d76f609cdb9e..000000000000 --- a/examples/animation/old_animation/gtk_timeout.py +++ /dev/null @@ -1,18 +0,0 @@ -import gobject -import numpy as np -import matplotlib -matplotlib.use('GTKAgg') - -import matplotlib.pyplot as plt - -fig, ax = plt.subplots() -line, = ax.plot(np.random.rand(10)) -ax.set_ylim(0, 1) - -def update(): - line.set_ydata(np.random.rand(10)) - fig.canvas.draw_idle() - return True # return False to terminate the updates - -gobject.timeout_add(100, update) # you can also use idle_add to update when gtk is idle -plt.show() diff --git a/examples/animation/old_animation/histogram_tkagg.py b/examples/animation/old_animation/histogram_tkagg.py deleted file mode 100644 index ff37fc48bc7d..000000000000 --- a/examples/animation/old_animation/histogram_tkagg.py +++ /dev/null @@ -1,68 +0,0 @@ -""" -This example shows how to use a path patch to draw a bunch of -rectangles for an animated histogram -""" -import numpy as np -import matplotlib -matplotlib.use('TkAgg') # do this before importing pylab - -import matplotlib.pyplot as plt -import matplotlib.patches as patches -import matplotlib.path as path - -fig, ax = plt.subplots() - -# histogram our data with numpy -data = np.random.randn(1000) -n, bins = np.histogram(data, 100) - -# get the corners of the rectangles for the histogram -left = np.array(bins[:-1]) -right = np.array(bins[1:]) -bottom = np.zeros(len(left)) -top = bottom + n -nrects = len(left) - -# here comes the tricky part -- we have to set up the vertex and path -# codes arrays using moveto, lineto and closepoly - -# for each rect: 1 for the MOVETO, 3 for the LINETO, 1 for the -# CLOSEPOLY; the vert for the closepoly is ignored but we still need -# it to keep the codes aligned with the vertices -nverts = nrects*(1+3+1) -verts = np.zeros((nverts, 2)) -codes = np.ones(nverts, int) * path.Path.LINETO -codes[0::5] = path.Path.MOVETO -codes[4::5] = path.Path.CLOSEPOLY -verts[0::5,0] = left -verts[0::5,1] = bottom -verts[1::5,0] = left -verts[1::5,1] = top -verts[2::5,0] = right -verts[2::5,1] = top -verts[3::5,0] = right -verts[3::5,1] = bottom - -barpath = path.Path(verts, codes) -patch = patches.PathPatch(barpath, facecolor='green', edgecolor='yellow', alpha=0.5) -ax.add_patch(patch) - -ax.set_xlim(left[0], right[-1]) -ax.set_ylim(bottom.min(), top.max()) - -def animate(): - if animate.cnt>=100: - return - - animate.cnt += 1 - # simulate new data coming in - data = np.random.randn(1000) - n, bins = np.histogram(data, 100) - top = bottom + n - verts[1::5,1] = top - verts[2::5,1] = top - fig.canvas.draw() - fig.canvas.manager.window.after(100, animate) -animate.cnt = 0 -fig.canvas.manager.window.after(100, animate) -plt.show() diff --git a/examples/animation/old_animation/movie_demo.py b/examples/animation/old_animation/movie_demo.py deleted file mode 100755 index 0abf4a9e422d..000000000000 --- a/examples/animation/old_animation/movie_demo.py +++ /dev/null @@ -1,158 +0,0 @@ -#!/usr/bin/python -# -# Josh Lifton 2004 -# -# Permission is hereby granted to use and abuse this document -# so long as proper attribution is given. -# -# This Python script demonstrates how to use the numarray package -# to generate and handle large arrays of data and how to use the -# matplotlib package to generate plots from the data and then save -# those plots as images. These images are then stitched together -# by Mencoder to create a movie of the plotted data. This script -# is for demonstration purposes only and is not intended to be -# for general use. In particular, you will likely need to modify -# the script to suit your own needs. -# - -from __future__ import print_function - -import matplotlib -matplotlib.use('Agg') -import matplotlib.pyplot as plt # For plotting graphs. -import numpy as np -import subprocess # For issuing commands to the OS. -import os -import sys # For determining the Python version. - -# -# Print the version information for the machine, OS, -# Python interpreter, and matplotlib. The version of -# Mencoder is printed when it is called. -# -print('Executing on', os.uname()) -print('Python version', sys.version) -print('matplotlib version', matplotlib.__version__) - -not_found_msg = """ -The mencoder command was not found; -mencoder is used by this script to make an avi file from a set of pngs. -It is typically not installed by default on linux distros because of -legal restrictions, but it is widely available. -""" - -try: - subprocess.check_call(['mencoder']) -except subprocess.CalledProcessError: - print("mencoder command was found") - pass # mencoder is found, but returns non-zero exit as expected - # This is a quick and dirty check; it leaves some spurious output - # for the user to puzzle over. -except OSError: - print(not_found_msg) - sys.exit("quitting\n") - - -# -# First, let's create some data to work with. In this example -# we'll use a normalized Gaussian waveform whose mean and -# standard deviation both increase linearly with time. Such a -# waveform can be thought of as a propagating system that loses -# coherence over time, as might happen to the probability -# distribution of a clock subjected to independent, identically -# distributed Gaussian noise at each time step. -# - -print('Initializing data set...') # Let the user know what's happening. - -# Initialize variables needed to create and store the example data set. -numberOfTimeSteps = 100 # Number of frames we want in the movie. -x = np.arange(-10,10,0.01) # Values to be plotted on the x-axis. -mean = -6 # Initial mean of the Gaussian. -stddev = 0.2 # Initial standard deviation. -meaninc = 0.1 # Mean increment. -stddevinc = 0.1 # Standard deviation increment. - -# Create an array of zeros and fill it with the example data. -y = np.zeros((numberOfTimeSteps,len(x)), float) -for i in range(numberOfTimeSteps) : - y[i] = (1/np.sqrt(2*np.pi*stddev))*np.exp(-((x-mean)**2)/(2*stddev)) - mean = mean + meaninc - stddev = stddev + stddevinc - -print('Done.') # Let the user know what's happening. - -# -# Now that we have an example data set (x,y) to work with, we can -# start graphing it and saving the images. -# - -for i in range(len(y)) : - # - # The next four lines are just like MATLAB. - # - plt.plot(x,y[i],'b.') - plt.axis((x[0],x[-1],-0.25,1)) - plt.xlabel('time (ms)') - plt.ylabel('probability density function') - - # - # Notice the use of LaTeX-like markup. - # - plt.title(r'$\cal{N}(\mu, \sigma^2)$', fontsize=20) - - # - # The file name indicates how the image will be saved and the - # order it will appear in the movie. If you actually wanted each - # graph to be displayed on the screen, you would include commands - # such as show() and draw() here. See the matplotlib - # documentation for details. In this case, we are saving the - # images directly to a file without displaying them. - # - filename = str('%03d' % i) + '.png' - plt.savefig(filename, dpi=100) - - # - # Let the user know what's happening. - # - print('Wrote file', filename) - - # - # Clear the figure to make way for the next image. - # - plt.clf() - -# -# Now that we have graphed images of the dataset, we will stitch them -# together using Mencoder to create a movie. Each image will become -# a single frame in the movie. -# -# We want to use Python to make what would normally be a command line -# call to Mencoder. Specifically, the command line call we want to -# emulate is (without the initial '#'): -# mencoder mf://*.png -mf type=png:w=800:h=600:fps=25 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o output.avi -# See the MPlayer and Mencoder documentation for details. -# - -command = ('mencoder', - 'mf://*.png', - '-mf', - 'type=png:w=800:h=600:fps=25', - '-ovc', - 'lavc', - '-lavcopts', - 'vcodec=mpeg4', - '-oac', - 'copy', - '-o', - 'output.avi') - -#os.spawnvp(os.P_WAIT, 'mencoder', command) - -print("\n\nabout to execute:\n%s\n\n" % ' '.join(command)) -subprocess.check_call(command) - -print("\n\n The movie was written to 'output.avi'") - -print("\n\n You may want to delete *.png now.\n\n") - diff --git a/examples/animation/old_animation/simple_anim_gtk.py b/examples/animation/old_animation/simple_anim_gtk.py deleted file mode 100644 index ecdec7333640..000000000000 --- a/examples/animation/old_animation/simple_anim_gtk.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -A simple example of an animated plot using a gtk backend -""" -from __future__ import print_function -import time -import numpy as np -import matplotlib -matplotlib.use('GTKAgg') # do this before importing pylab - -import matplotlib.pyplot as plt - -fig, ax = plt.subplots() - -def animate(): - tstart = time.time() # for profiling - x = np.arange(0, 2*np.pi, 0.01) # x-array - line, = ax.plot(x, np.sin(x)) - - for i in np.arange(1,200): - line.set_ydata(np.sin(x+i/10.0)) # update the data - fig.canvas.draw() # redraw the canvas - print('FPS:' , 200/(time.time()-tstart)) - raise SystemExit - -import gobject -print('adding idle') -gobject.idle_add(animate) -print('showing') -plt.show() diff --git a/examples/animation/old_animation/simple_anim_tkagg.py b/examples/animation/old_animation/simple_anim_tkagg.py deleted file mode 100755 index e8a3a5ca314e..000000000000 --- a/examples/animation/old_animation/simple_anim_tkagg.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python - -""" -A simple example of an animated plot in tkagg -""" -from __future__ import print_function -import time -import numpy as np -import matplotlib -matplotlib.use('TkAgg') # do this before importing pylab - -import matplotlib.pyplot as plt -fig, ax = plt.subplots() - -def animate(): - tstart = time.time() # for profiling - x = np.arange(0, 2*np.pi, 0.01) # x-array - line, = ax.plot(x, np.sin(x)) - - for i in np.arange(1,200): - line.set_ydata(np.sin(x+i/10.0)) # update the data - fig.canvas.draw() # redraw the canvas - print('FPS:' , 200/(time.time()-tstart)) - -win = fig.canvas.manager.window -fig.canvas.manager.window.after(100, animate) -plt.show() diff --git a/examples/animation/old_animation/simple_idle_wx.py b/examples/animation/old_animation/simple_idle_wx.py deleted file mode 100644 index 16541597623b..000000000000 --- a/examples/animation/old_animation/simple_idle_wx.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -A simple example of an animated plot using a wx backend -""" -from __future__ import print_function -import numpy as np -import matplotlib -matplotlib.use('WXAgg') # do this before importing pylab - -import matplotlib.pyplot as plt - -fig, ax = plt.subplots() -t = np.arange(0, 2*np.pi, 0.1) -line, = ax.plot(t, np.sin(t)) -dt = 0.05 - -def update_line(idleevent): - if update_line.i==200: - return False - print('animate', update_line.i) - line.set_ydata(np.sin(t+update_line.i/10.)) - fig.canvas.draw_idle() # redraw the canvas - update_line.i += 1 -update_line.i = 0 - -import wx -wx.EVT_IDLE(wx.GetApp(), update_line) -plt.show() diff --git a/examples/animation/old_animation/simple_timer_wx.py b/examples/animation/old_animation/simple_timer_wx.py deleted file mode 100644 index a427524effd6..000000000000 --- a/examples/animation/old_animation/simple_timer_wx.py +++ /dev/null @@ -1,34 +0,0 @@ -from __future__ import print_function -""" -A simple example of an animated plot using a wx backend -""" -import numpy as np -import matplotlib -matplotlib.use('WXAgg') # do this before importing pylab - -import matplotlib.pyplot as plt - -fig, ax = plt.subplots() -t = np.arange(0, 2*np.pi, 0.1) -line, = ax.plot(t, np.sin(t)) -dt = 0.05 - - -def update_line(event): - if update_line.i==200: - return False - print('update', update_line.i) - line.set_ydata(np.sin(t+update_line.i/10.)) - fig.canvas.draw() # redraw the canvas - update_line.i += 1 -update_line.i = 0 - -import wx -id = wx.NewId() -actor = fig.canvas.manager.frame -timer = wx.Timer(actor, id=id) -timer.Start(100) -wx.EVT_TIMER(actor, id, update_line) -#actor.Bind(wx.EVT_TIMER, update_line, id=id) - -plt.show() diff --git a/examples/animation/old_animation/strip_chart_demo.py b/examples/animation/old_animation/strip_chart_demo.py deleted file mode 100644 index 7f659afd020e..000000000000 --- a/examples/animation/old_animation/strip_chart_demo.py +++ /dev/null @@ -1,70 +0,0 @@ -""" -Emulate an oscilloscope. Requires the animation API introduced in -matplotlib 0.84. See -http://www.scipy.org/wikis/topical_software/Animations for an -explanation. - -This example uses gtk but does not depend on it intimately. It just -uses the idle handler to trigger events. You can plug this into a -different GUI that supports animation (GTKAgg, TkAgg, WXAgg) and use -your toolkits idle/timer functions. -""" -import gobject -import matplotlib -matplotlib.use('GTKAgg') -import numpy as np -import matplotlib.pyplot as plt -from matplotlib.lines import Line2D - - -class Scope: - def __init__(self, ax, maxt=10, dt=0.01): - self.ax = ax - self.canvas = ax.figure.canvas - self.dt = dt - self.maxt = maxt - self.tdata = [0] - self.ydata = [0] - self.line = Line2D(self.tdata, self.ydata, animated=True) - self.ax.add_line(self.line) - self.background = None - self.canvas.mpl_connect('draw_event', self.update_background) - self.ax.set_ylim(-.1, 1.1) - self.ax.set_xlim(0, self.maxt) - - def update_background(self, event): - self.background = self.canvas.copy_from_bbox(self.ax.bbox) - - def emitter(self, p=0.01): - 'return a random value with probability p, else 0' - v = np.random.rand(1) - if v>p: return 0. - else: return np.random.rand(1) - - def update(self, *args): - if self.background is None: return True - y = self.emitter() - lastt = self.tdata[-1] - if lastt>self.tdata[0]+self.maxt: # reset the arrays - self.tdata = [self.tdata[-1]] - self.ydata = [self.ydata[-1]] - self.ax.set_xlim(self.tdata[0], self.tdata[0]+self.maxt) - self.ax.figure.canvas.draw() - - self.canvas.restore_region(self.background) - - t = self.tdata[-1] + self.dt - self.tdata.append(t) - self.ydata.append(y) - self.line.set_data(self.tdata, self.ydata) - self.ax.draw_artist(self.line) - - self.canvas.blit(self.ax.bbox) - return True - - -fig, ax = plt.subplots() -scope = Scope(ax) -gobject.idle_add(scope.update) - -plt.show()