diff --git a/examples/axisartist/demo_axisline_style.py b/examples/axisartist/demo_axisline_style.py index 21fb11564a31..7823e9c52b12 100644 --- a/examples/axisartist/demo_axisline_style.py +++ b/examples/axisartist/demo_axisline_style.py @@ -1,8 +1,9 @@ """ -=================== -Demo Axisline Style -=================== +================ +Axis line styles +================ +This example shows some configurations for axis style. """ from mpl_toolkits.axisartist.axislines import SubplotZero @@ -15,10 +16,14 @@ fig.add_subplot(ax) for direction in ["xzero", "yzero"]: + # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") + + # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: + # hides borders ax.axis[direction].set_visible(False) x = np.linspace(-0.5, 1., 100) diff --git a/examples/event_handling/poly_editor.py b/examples/event_handling/poly_editor.py index 9224997bbb25..13b139d56bab 100644 --- a/examples/event_handling/poly_editor.py +++ b/examples/event_handling/poly_editor.py @@ -4,8 +4,7 @@ =========== This is an example to show how to build cross-GUI applications using -matplotlib event handling to interact with objects on the canvas - +Matplotlib event handling to interact with objects on the canvas. """ import numpy as np from matplotlib.lines import Line2D @@ -34,17 +33,19 @@ class PolygonInteractor(object): def __init__(self, ax, poly): if poly.figure is None: - raise RuntimeError('You must first add the polygon to a figure or canvas before defining the interactor') + raise RuntimeError('You must first add the polygon to a figure ' + 'or canvas before defining the interactor') self.ax = ax canvas = poly.figure.canvas self.poly = poly x, y = zip(*self.poly.xy) - self.line = Line2D(x, y, marker='o', markerfacecolor='r', animated=True) + self.line = Line2D(x, y, + marker='o', markerfacecolor='r', + animated=True) self.ax.add_line(self.line) - #self._update_line(poly) - cid = self.poly.add_callback(self.poly_changed) + self.cid = self.poly.add_callback(self.poly_changed) self._ind = None # the active vert canvas.mpl_connect('draw_event', self.draw_callback) @@ -113,7 +114,9 @@ def key_press_callback(self, event): elif event.key == 'd': ind = self.get_ind_under_point(event) if ind is not None: - self.poly.xy = [tup for i, tup in enumerate(self.poly.xy) if i != ind] + self.poly.xy = [tup + for i, tup in enumerate(self.poly.xy) + if i != ind] self.line.set_data(zip(*self.poly.xy)) elif event.key == 'i': xys = self.poly.get_transform().transform(self.poly.xy) @@ -173,7 +176,6 @@ def motion_notify_callback(self, event): ax.add_patch(poly) p = PolygonInteractor(ax, poly) - #ax.add_line(p.line) ax.set_title('Click and drag a point to move it') ax.set_xlim((-2, 2)) ax.set_ylim((-2, 2)) diff --git a/examples/event_handling/resample.py b/examples/event_handling/resample.py index 049dd449fdcc..b9811942b857 100644 --- a/examples/event_handling/resample.py +++ b/examples/event_handling/resample.py @@ -1,9 +1,13 @@ """ -======== -Resample -======== +=============== +Resampling Data +=============== +Downsampling lowers the sample rate or sample size of a signal. In +this tutorial, the signal is downsampled when the plot is adjusted +through dragging and zooming. """ + import numpy as np import matplotlib.pyplot as plt @@ -13,18 +17,28 @@ class DataDisplayDownsampler(object): def __init__(self, xdata, ydata): self.origYData = ydata self.origXData = xdata - self.ratio = 5 + self.max_points = 50 self.delta = xdata[-1] - xdata[0] def downsample(self, xstart, xend): - # Very simple downsampling that takes the points within the range - # and picks every Nth point + # get the points in the view range mask = (self.origXData > xstart) & (self.origXData < xend) - xdata = self.origXData[mask] - xdata = xdata[::self.ratio] + # dilate the mask by one to catch the points just outside + # of the view range to not truncate the line + mask = np.convolve([1, 1], mask, mode='same').astype(bool) + # sort out how many points to drop + ratio = max(np.sum(mask) // self.max_points, 1) + # mask data + xdata = self.origXData[mask] ydata = self.origYData[mask] - ydata = ydata[::self.ratio] + + # downsample data + xdata = xdata[::ratio] + ydata = ydata[::ratio] + + print("using {} of {} visible points".format( + len(ydata), np.sum(mask))) return xdata, ydata @@ -37,8 +51,9 @@ def update(self, ax): self.line.set_data(*self.downsample(xstart, xend)) ax.figure.canvas.draw_idle() + # Create a signal -xdata = np.linspace(16, 365, 365-16) +xdata = np.linspace(16, 365, (365-16)*4) ydata = np.sin(2*np.pi*xdata/153) + np.cos(2*np.pi*xdata/127) d = DataDisplayDownsampler(xdata, ydata) @@ -51,5 +66,5 @@ def update(self, ax): # Connect for changing the view limits ax.callbacks.connect('xlim_changed', d.update) - +ax.set_xlim(16, 365) plt.show() diff --git a/examples/mplot3d/lines3d.py b/examples/mplot3d/lines3d.py index a1504de63e22..34ef9328c663 100644 --- a/examples/mplot3d/lines3d.py +++ b/examples/mplot3d/lines3d.py @@ -1,9 +1,9 @@ ''' -=================== -3D parametric curve -=================== +================ +Parametric Curve +================ -Demonstrating plotting a parametric curve in 3D. +This example demonstrates plotting a parametric curve in 3D. ''' import matplotlib as mpl diff --git a/examples/mplot3d/lorenz_attractor.py b/examples/mplot3d/lorenz_attractor.py index 54967e219b72..47b21292b4cb 100644 --- a/examples/mplot3d/lorenz_attractor.py +++ b/examples/mplot3d/lorenz_attractor.py @@ -1,11 +1,12 @@ ''' -==================== -The Lorenz Attractor -==================== +================ +Lorenz Attractor +================ -Plot of the Lorenz Attractor based on Edward Lorenz's 1963 "Deterministic -Nonperiodic Flow" publication. -http://journals.ametsoc.org/doi/abs/10.1175/1520-0469%281963%29020%3C0130%3ADNF%3E2.0.CO%3B2 +This is an example of plotting Edward Lorenz's 1963 `"Deterministic +Nonperiodic Flow" +`_ +in a 3-dimensional space using mplot3d. Note: Because this is a simple non-linear ODE, it would be more easily done using SciPy's ode solver, but this approach depends only diff --git a/examples/mplot3d/mixed_subplots.py b/examples/mplot3d/mixed_subplots.py index 00d691813485..37962d654d94 100644 --- a/examples/mplot3d/mixed_subplots.py +++ b/examples/mplot3d/mixed_subplots.py @@ -1,11 +1,10 @@ """ -================== -2D and 3D subplots -================== +================================= +2D and 3D *Axes* in same *Figure* +================================= -Demonstrate the mixing of 2d and 3d subplots. +This example shows a how to plot a 2D and 3D plot on the same figure. """ - from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np diff --git a/examples/mplot3d/offset.py b/examples/mplot3d/offset.py index a92757cd9d96..da846c8cc26a 100644 --- a/examples/mplot3d/offset.py +++ b/examples/mplot3d/offset.py @@ -1,7 +1,7 @@ ''' -=================== -Offset text display -=================== +========================= +Automatic Text Offsetting +========================= This example demonstrates mplot3d's offset text display. As one rotates the 3D figure, the offsets should remain oriented the diff --git a/examples/pylab_examples/bar_stacked.py b/examples/pylab_examples/bar_stacked.py index 6330474506f3..d7fb25b080c6 100644 --- a/examples/pylab_examples/bar_stacked.py +++ b/examples/pylab_examples/bar_stacked.py @@ -1,10 +1,15 @@ """ -=========== -Bar Stacked -=========== +================= +Stacked Bar Graph +================= + +This is an example of creating a stacked bar plot with error bars +using `~matplotlib.pyplot.bar`. Note the parameters *yerr* used for +error bars, and *bottom* to stack the women's bars on top of the men's +bars. -A stacked bar plot with errorbars. """ + import numpy as np import matplotlib.pyplot as plt diff --git a/examples/pylab_examples/dolphin.py b/examples/pylab_examples/dolphin.py index 2f3763614c06..f705eb18e314 100644 --- a/examples/pylab_examples/dolphin.py +++ b/examples/pylab_examples/dolphin.py @@ -1,9 +1,13 @@ """ -======= -Dolphin -======= +======== +Dolphins +======== + +This example shows how to draw, and manipulate shapes given vertices +and nodes using the `Patches`, `Path` and `Transforms` classes. """ + import matplotlib.cm as cm import matplotlib.pyplot as plt from matplotlib.patches import Circle, PathPatch diff --git a/examples/pylab_examples/fill_between_demo.py b/examples/pylab_examples/fill_between_demo.py index 4aa8d4821d9a..2b065ed42f60 100644 --- a/examples/pylab_examples/fill_between_demo.py +++ b/examples/pylab_examples/fill_between_demo.py @@ -1,9 +1,12 @@ """ -================= -Fill Between Demo -================= +============================== +Filling the area between lines +============================== +This example shows how to use `fill_between` to color between lines based on +user-defined logic. """ + import matplotlib.pyplot as plt import numpy as np diff --git a/examples/pylab_examples/geo_demo.py b/examples/pylab_examples/geo_demo.py index 42cd9173a823..8692432eca65 100644 --- a/examples/pylab_examples/geo_demo.py +++ b/examples/pylab_examples/geo_demo.py @@ -1,9 +1,14 @@ """ -======== -Geo Demo -======== +====================== +Geographic Projections +====================== + +This shows 4 possible projections using subplot. Matplotlib also +supports `Basemaps Toolkit `_ and +`Cartopy `_ for geographic projections. """ + import matplotlib.pyplot as plt plt.figure() diff --git a/examples/pylab_examples/log_test.py b/examples/pylab_examples/log_test.py index 55ff68c50e59..fa9aca22becf 100644 --- a/examples/pylab_examples/log_test.py +++ b/examples/pylab_examples/log_test.py @@ -1,9 +1,12 @@ """ ======== -Log Test +Log Axis ======== +This is an example of assigning a log-scale for the x-axis using +`semilogx`. """ + import matplotlib.pyplot as plt import numpy as np diff --git a/examples/pylab_examples/mri_demo.py b/examples/pylab_examples/mri_demo.py index 0f2e873c1ae9..837344cf84f9 100644 --- a/examples/pylab_examples/mri_demo.py +++ b/examples/pylab_examples/mri_demo.py @@ -1,11 +1,13 @@ """ -======== -MRI Demo -======== +=== +MRI +=== -Displays an MRI image. -""" +This example illustrates how to read an image (of an MRI) into a NumPy +array, and display it in greyscale using `imshow`. + +""" import matplotlib.pyplot as plt import matplotlib.cbook as cbook