diff --git a/examples/api/sankey_demo_old.py b/examples/api/sankey_demo_old.py deleted file mode 100755 index 93005feaf79d..000000000000 --- a/examples/api/sankey_demo_old.py +++ /dev/null @@ -1,200 +0,0 @@ -""" -========================== -Yet another Sankey diagram -========================== - -This example showcases a more complex sankey diagram. -""" - -from __future__ import print_function - -__author__ = "Yannick Copin " -__version__ = "Time-stamp: <10/02/2010 16:49 ycopin@lyopc548.in2p3.fr>" - -import numpy as np - - -def sankey(ax, - outputs=[100.], outlabels=None, - inputs=[100.], inlabels='', - dx=40, dy=10, outangle=45, w=3, inangle=30, offset=2, **kwargs): - """Draw a Sankey diagram. - - outputs: array of outputs, should sum up to 100% - outlabels: output labels (same length as outputs), - or None (use default labels) or '' (no labels) - inputs and inlabels: similar for inputs - dx: horizontal elongation - dy: vertical elongation - outangle: output arrow angle [deg] - w: output arrow shoulder - inangle: input dip angle - offset: text offset - **kwargs: propagated to Patch (e.g., fill=False) - - Return (patch,[intexts,outtexts]). - """ - import matplotlib.patches as mpatches - from matplotlib.path import Path - - outs = np.abs(outputs) - outsigns = np.sign(outputs) - outsigns[-1] = 0 # Last output - - ins = np.abs(inputs) - insigns = np.sign(inputs) - insigns[0] = 0 # First input - - assert sum(outs) == 100, "Outputs don't sum up to 100%" - assert sum(ins) == 100, "Inputs don't sum up to 100%" - - def add_output(path, loss, sign=1): - # Arrow tip height - h = (loss/2 + w) * np.tan(np.radians(outangle)) - move, (x, y) = path[-1] # Use last point as reference - if sign == 0: # Final loss (horizontal) - path.extend([(Path.LINETO, [x + dx, y]), - (Path.LINETO, [x + dx, y + w]), - (Path.LINETO, [x + dx + h, y - loss/2]), # Tip - (Path.LINETO, [x + dx, y - loss - w]), - (Path.LINETO, [x + dx, y - loss])]) - outtips.append((sign, path[-3][1])) - else: # Intermediate loss (vertical) - path.extend([(Path.CURVE4, [x + dx/2, y]), - (Path.CURVE4, [x + dx, y]), - (Path.CURVE4, [x + dx, y + sign*dy]), - (Path.LINETO, [x + dx - w, y + sign*dy]), - # Tip - (Path.LINETO, [ - x + dx + loss/2, y + sign*(dy + h)]), - (Path.LINETO, [x + dx + loss + w, y + sign*dy]), - (Path.LINETO, [x + dx + loss, y + sign*dy]), - (Path.CURVE3, [x + dx + loss, y - sign*loss]), - (Path.CURVE3, [x + dx/2 + loss, y - sign*loss])]) - outtips.append((sign, path[-5][1])) - - def add_input(path, gain, sign=1): - h = (gain / 2) * np.tan(np.radians(inangle)) # Dip depth - move, (x, y) = path[-1] # Use last point as reference - if sign == 0: # First gain (horizontal) - path.extend([(Path.LINETO, [x - dx, y]), - (Path.LINETO, [x - dx + h, y + gain/2]), # Dip - (Path.LINETO, [x - dx, y + gain])]) - xd, yd = path[-2][1] # Dip position - indips.append((sign, [xd - h, yd])) - else: # Intermediate gain (vertical) - path.extend([(Path.CURVE4, [x - dx/2, y]), - (Path.CURVE4, [x - dx, y]), - (Path.CURVE4, [x - dx, y + sign*dy]), - # Dip - (Path.LINETO, [ - x - dx - gain / 2, y + sign*(dy - h)]), - (Path.LINETO, [x - dx - gain, y + sign*dy]), - (Path.CURVE3, [x - dx - gain, y - sign*gain]), - (Path.CURVE3, [x - dx/2 - gain, y - sign*gain])]) - xd, yd = path[-4][1] # Dip position - indips.append((sign, [xd, yd + sign*h])) - - outtips = [] # Output arrow tip dir. and positions - urpath = [(Path.MOVETO, [0, 100])] # 1st point of upper right path - lrpath = [(Path.LINETO, [0, 0])] # 1st point of lower right path - for loss, sign in zip(outs, outsigns): - add_output(sign >= 0 and urpath or lrpath, loss, sign=sign) - - indips = [] # Input arrow tip dir. and positions - llpath = [(Path.LINETO, [0, 0])] # 1st point of lower left path - ulpath = [(Path.MOVETO, [0, 100])] # 1st point of upper left path - for gain, sign in reversed(list(zip(ins, insigns))): - add_input(sign <= 0 and llpath or ulpath, gain, sign=sign) - - def revert(path): - """A path is not just revertable by path[::-1] because of Bezier - curves.""" - rpath = [] - nextmove = Path.LINETO - for move, pos in path[::-1]: - rpath.append((nextmove, pos)) - nextmove = move - return rpath - - # Concatenate subpathes in correct order - path = urpath + revert(lrpath) + llpath + revert(ulpath) - - codes, verts = zip(*path) - verts = np.array(verts) - - # Path patch - path = Path(verts, codes) - patch = mpatches.PathPatch(path, **kwargs) - ax.add_patch(patch) - - if False: # DEBUG - print("urpath", urpath) - print("lrpath", revert(lrpath)) - print("llpath", llpath) - print("ulpath", revert(ulpath)) - xs, ys = zip(*verts) - ax.plot(xs, ys, 'go-') - - # Labels - - def set_labels(labels, values): - """Set or check labels according to values.""" - if labels == '': # No labels - return labels - elif labels is None: # Default labels - return ['%2d%%' % val for val in values] - else: - assert len(labels) == len(values) - return labels - - def put_labels(labels, positions, output=True): - """Put labels to positions.""" - texts = [] - lbls = output and labels or labels[::-1] - for i, label in enumerate(lbls): - s, (x, y) = positions[i] # Label direction and position - if s == 0: - t = ax.text(x + offset, y, label, - ha=output and 'left' or 'right', va='center') - elif s > 0: - t = ax.text(x, y + offset, label, ha='center', va='bottom') - else: - t = ax.text(x, y - offset, label, ha='center', va='top') - texts.append(t) - return texts - - outlabels = set_labels(outlabels, outs) - outtexts = put_labels(outlabels, outtips, output=True) - - inlabels = set_labels(inlabels, ins) - intexts = put_labels(inlabels, indips, output=False) - - # Axes management - ax.set_xlim(verts[:, 0].min() - dx, verts[:, 0].max() + dx) - ax.set_ylim(verts[:, 1].min() - dy, verts[:, 1].max() + dy) - ax.set_aspect('equal', adjustable='datalim') - - return patch, [intexts, outtexts] - - -if __name__ == '__main__': - - import matplotlib.pyplot as plt - - outputs = [10., -20., 5., 15., -10., 40.] - outlabels = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Hurray!'] - outlabels = [s + '\n%d%%' % abs(l) for l, s in zip(outputs, outlabels)] - - inputs = [60., -25., 15.] - - fig = plt.figure() - ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[], title="Sankey diagram") - - patch, (intexts, outtexts) = sankey(ax, outputs=outputs, - outlabels=outlabels, inputs=inputs, - inlabels=None) - outtexts[1].set_color('r') - outtexts[-1].set_fontweight('bold') - - plt.show() diff --git a/examples/misc/sample_data_demo.py b/examples/misc/sample_data_demo.py deleted file mode 100644 index 082fb63d6050..000000000000 --- a/examples/misc/sample_data_demo.py +++ /dev/null @@ -1,13 +0,0 @@ -""" -Grab mpl data from the ~/.matplotlib/sample_data cache if it exists, else -fetch it from GitHub and cache it -""" -from __future__ import print_function -import matplotlib.cbook as cbook -import matplotlib.pyplot as plt -fname = cbook.get_sample_data('ada.png', asfileobj=False) - -print('fname', fname) -im = plt.imread(fname) -plt.imshow(im) -plt.show() diff --git a/examples/pylab_examples/manual_axis.py b/examples/pylab_examples/manual_axis.py deleted file mode 100644 index 9cc15cf4e18e..000000000000 --- a/examples/pylab_examples/manual_axis.py +++ /dev/null @@ -1,63 +0,0 @@ -""" -The techniques here are no longer required with the new support for -spines in matplotlib -- see -http://matplotlib.org/examples/pylab_examples/spine_placement_demo.html. - -This example should be considered deprecated and is left just for demo -purposes for folks wanting to make a pseudo-axis -""" - -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.lines as lines - - -def make_xaxis(ax, yloc, offset=0.05, **props): - xmin, xmax = ax.get_xlim() - locs = [loc for loc in ax.xaxis.get_majorticklocs() - if loc >= xmin and loc <= xmax] - tickline, = ax.plot(locs, [yloc]*len(locs), linestyle='', - marker=lines.TICKDOWN, **props) - axline, = ax.plot([xmin, xmax], [yloc, yloc], **props) - tickline.set_clip_on(False) - axline.set_clip_on(False) - for loc in locs: - ax.text(loc, yloc - offset, '%1.1f' % loc, - horizontalalignment='center', - verticalalignment='top') - - -def make_yaxis(ax, xloc=0, offset=0.05, **props): - ymin, ymax = ax.get_ylim() - locs = [loc for loc in ax.yaxis.get_majorticklocs() - if loc >= ymin and loc <= ymax] - tickline, = ax.plot([xloc]*len(locs), locs, linestyle='', - marker=lines.TICKLEFT, **props) - axline, = ax.plot([xloc, xloc], [ymin, ymax], **props) - tickline.set_clip_on(False) - axline.set_clip_on(False) - - for loc in locs: - ax.text(xloc - offset, loc, '%1.1f' % loc, - verticalalignment='center', - horizontalalignment='right') - - -props = dict(color='black', linewidth=2, markeredgewidth=2) - -# Fixing random state for reproducibility -np.random.seed(19680801) - - -x = np.arange(200.) -y = np.sin(2*np.pi*x/200.) + np.random.rand(200) - 0.5 -fig = plt.figure(facecolor='white') -ax = fig.add_subplot(111, frame_on=False) -ax.axison = False -ax.plot(x, y, 'd', markersize=8, markerfacecolor='blue') -ax.set_xlim(0, 200) -ax.set_ylim(-1.5, 1.5) -make_xaxis(ax, 0, offset=0.1, **props) -make_yaxis(ax, 0, offset=5, **props) - -plt.show() diff --git a/examples/pylab_examples/text_handles.py b/examples/pylab_examples/text_handles.py deleted file mode 100644 index ffaa782df8eb..000000000000 --- a/examples/pylab_examples/text_handles.py +++ /dev/null @@ -1,33 +0,0 @@ -""" -Controlling the properties of axis text using handles - -See examples/text_themes.py for a more elegant, pythonic way to control -fonts. After all, if we were slaves to MATLAB , we wouldn't be -using python! -""" - -import matplotlib.pyplot as plt -import numpy as np - - -def f(t): - s1 = np.sin(2*np.pi*t) - e1 = np.exp(-t) - return np.multiply(s1, e1) - -t1 = np.arange(0.0, 5.0, 0.1) -t2 = np.arange(0.0, 5.0, 0.02) - -fig, ax = plt.subplots() -plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k') -plt.text(3.0, 0.6, 'f(t) = exp(-t) sin(2 pi t)') -ttext = plt.title('Fun with text!') -ytext = plt.ylabel('Damped oscillation') -xtext = plt.xlabel('time (s)') - -plt.setp(ttext, size='large', color='r', style='italic') -plt.setp(xtext, size='medium', name=['Courier', 'DejaVu Sans Mono'], - weight='bold', color='g') -plt.setp(ytext, size='medium', name=['Helvetica', 'DejaVu Sans'], - weight='light', color='b') -plt.show() diff --git a/examples/pylab_examples/toggle_images.py b/examples/pylab_examples/toggle_images.py deleted file mode 100644 index 7891087aab15..000000000000 --- a/examples/pylab_examples/toggle_images.py +++ /dev/null @@ -1,50 +0,0 @@ -""" toggle between two images by pressing "t" - -The basic idea is to load two images (they can be different shapes) and plot -them to the same axes. Then, toggle the visible property of -them using keypress event handling - -If you want two images with different shapes to be plotted with the same -extent, they must have the same "extent" property - -As usual, we'll define some random images for demo. Real data is much more -exciting! - -Note, on the wx backend on some platforms (e.g., linux), you have to -first click on the figure before the keypress events are activated. -If you know how to fix this, please email us! - -""" - -import matplotlib.pyplot as plt -import numpy as np - -# Fixing random state for reproducibility -np.random.seed(19680801) - - -# two images x1 is initially visible, x2 is not -x1 = np.random.random((100, 100)) -x2 = np.random.random((150, 175)) - -# arbitrary extent - both images must have same extent if you want -# them to be resampled into the same axes space -extent = (0, 1, 0, 1) -im1 = plt.imshow(x1, extent=extent) -im2 = plt.imshow(x2, extent=extent) -im2.set_visible(False) - - -def toggle_images(event): - 'toggle the visible state of the two images' - if event.key != 't': - return - b1 = im1.get_visible() - b2 = im2.get_visible() - im1.set_visible(not b1) - im2.set_visible(not b2) - plt.draw() - -plt.connect('key_press_event', toggle_images) - -plt.show() diff --git a/examples/tests/backend_driver.py b/examples/tests/backend_driver.py index cf5a79b10036..a499f601360b 100755 --- a/examples/tests/backend_driver.py +++ b/examples/tests/backend_driver.py @@ -195,7 +195,6 @@ 'log_test.py', 'major_minor_demo1.py', 'major_minor_demo2.py', - 'manual_axis.py', 'masked_demo.py', 'mathtext_demo.py', 'mathtext_examples.py', @@ -237,7 +236,6 @@ 'subplots_adjust.py', 'symlog_demo.py', 'table_demo.py', - 'text_handles.py', 'text_rotation.py', 'text_rotation_relative_to_line.py', 'transoffset.py', @@ -307,7 +305,6 @@ # examples that generate multiple figures excluded = { - 'pylab': ['__init__.py', 'toggle_images.py', ], 'units': ['__init__.py', 'date_support.py', ], } diff --git a/lib/matplotlib/sankey.py b/lib/matplotlib/sankey.py index c5e69884368d..2269d63d4d51 100644 --- a/lib/matplotlib/sankey.py +++ b/lib/matplotlib/sankey.py @@ -6,36 +6,6 @@ import six from six.moves import zip - -# Original version by Yannick Copin (ycopin@ipnl.in2p3.fr) 10/2/2010, available -# at: -# http://matplotlib.org/examples/api/sankey_demo_old.html -# Modifications by Kevin Davies (kld@alumni.carnegiemellon.edu) 6/3/2011: -# --Used arcs for the curves (so that the widths of the paths are uniform) -# --Converted the function to a class and created methods to join multiple -# simple Sankey diagrams -# --Provided handling for cases where the total of the inputs isn't 100 -# Now, the default layout is based on the assumption that the inputs sum to -# 1. A scaling parameter can be used in other cases. -# --The call structure was changed to be more explicit about layout, -# including the length of the trunk, length of the paths, gap between the -# paths, and the margin around the diagram. -# --Allowed the lengths of paths to be adjusted individually, with an option -# to automatically justify them -# --The call structure was changed to make the specification of path -# orientation more flexible. Flows are passed through one array, with -# inputs being positive and outputs being negative. An orientation -# argument specifies the direction of the arrows. The "main" -# inputs/outputs are now specified via an orientation of 0, and there may -# be several of each. -# --Changed assertions to ValueError to catch common calling errors (by -# Francesco Montesano, franz.bergesung@gmail.com) -# --Added the physical unit as a string argument to be used in the labels, so -# that the values of the flows can usually be applied automatically -# --Added an argument for a minimum magnitude below which flows are not shown -# --Added a tapered trunk in the case that the flows do not sum to 0 -# --Allowed the diagram to be rotated - import numpy as np from matplotlib.cbook import iterable, Bunch