diff --git a/examples/pylab_examples/barchart_demo2.py b/examples/pylab_examples/barchart_demo2.py index 7d1d411d37a5..6db915d2d23d 100644 --- a/examples/pylab_examples/barchart_demo2.py +++ b/examples/pylab_examples/barchart_demo2.py @@ -10,7 +10,6 @@ """ import numpy as np import matplotlib.pyplot as plt -import pylab from matplotlib.ticker import MaxNLocator student = 'Johnny Doe' @@ -33,7 +32,7 @@ rects = ax1.barh(pos, rankings, align='center', height=0.5, color='m') ax1.axis([0, 100, 0, 5]) -pylab.yticks(pos, testNames) +plt.yticks(pos, testNames) ax1.set_title('Johnny Doe') plt.text(50, -0.5, 'Cohort Size: ' + str(cohortSize), horizontalalignment='center', size='small') @@ -43,7 +42,7 @@ ax2 = ax1.twinx() ax2.plot([100, 100], [0, 5], 'white', alpha=0.1) ax2.xaxis.set_major_locator(MaxNLocator(11)) -xticks = pylab.setp(ax2, xticklabels=['0', '10', '20', '30', '40', '50', '60', +xticks = plt.setp(ax2, xticklabels=['0', '10', '20', '30', '40', '50', '60', '70', '80', '90', '100']) ax2.xaxis.grid(True, linestyle='--', which='major', color='grey', alpha=0.25) diff --git a/examples/pylab_examples/barcode_demo.py b/examples/pylab_examples/barcode_demo.py index 5178a9fc2683..2e5b480145b3 100644 --- a/examples/pylab_examples/barcode_demo.py +++ b/examples/pylab_examples/barcode_demo.py @@ -1,14 +1,13 @@ -from matplotlib.pyplot import figure, show, cm -from numpy import where -from numpy.random import rand +import matplotlib.pyplot as plt +import numpy as np # the bar -x = where(rand(500) > 0.7, 1.0, 0.0) +x = np.where(np.random.rand(500) > 0.7, 1.0, 0.0) axprops = dict(xticks=[], yticks=[]) -barprops = dict(aspect='auto', cmap=cm.binary, interpolation='nearest') +barprops = dict(aspect='auto', cmap=plt.cm.binary, interpolation='nearest') -fig = figure() +fig = plt.figure() # a vertical barcode -- this is broken at present x.shape = len(x), 1 @@ -22,4 +21,4 @@ ax.imshow(x, **barprops) -show() +plt.show() diff --git a/examples/pylab_examples/boxplot_demo.py b/examples/pylab_examples/boxplot_demo.py index 4dd53cd3487d..288332180e71 100644 --- a/examples/pylab_examples/boxplot_demo.py +++ b/examples/pylab_examples/boxplot_demo.py @@ -1,57 +1,52 @@ -#!/usr/bin/python - -# -# Example boxplot code -# - -from pylab import * +import matplotlib.pyplot as plt +import numpy as np # fake up some data -spread = rand(50) * 100 -center = ones(25) * 50 -flier_high = rand(10) * 100 + 100 -flier_low = rand(10) * -100 -data = concatenate((spread, center, flier_high, flier_low), 0) +spread = np.random.rand(50) * 100 +center = np.ones(25) * 50 +flier_high = np.random.rand(10) * 100 + 100 +flier_low = np.random.rand(10) * -100 +data = np.concatenate((spread, center, flier_high, flier_low), 0) # basic plot -boxplot(data) +plt.boxplot(data) # notched plot -figure() -boxplot(data, 1) +plt.figure() +plt.boxplot(data, 1) # change outlier point symbols -figure() -boxplot(data, 0, 'gD') +plt.figure() +plt.boxplot(data, 0, 'gD') # don't show outlier points -figure() -boxplot(data, 0, '') +plt.figure() +plt.boxplot(data, 0, '') # horizontal boxes -figure() -boxplot(data, 0, 'rs', 0) +plt.figure() +plt.boxplot(data, 0, 'rs', 0) # change whisker length -figure() -boxplot(data, 0, 'rs', 0, 0.75) +plt.figure() +plt.boxplot(data, 0, 'rs', 0, 0.75) # fake up some more data -spread = rand(50) * 100 -center = ones(25) * 40 -flier_high = rand(10) * 100 + 100 -flier_low = rand(10) * -100 -d2 = concatenate((spread, center, flier_high, flier_low), 0) +spread = np.random.rand(50) * 100 +center = np.ones(25) * 40 +flier_high = np.random.rand(10) * 100 + 100 +flier_low = np.random.rand(10) * -100 +d2 = np.concatenate((spread, center, flier_high, flier_low), 0) data.shape = (-1, 1) d2.shape = (-1, 1) -#data = concatenate( (data, d2), 1 ) +# data = concatenate( (data, d2), 1 ) # Making a 2-D array only works if all the columns are the # same length. If they are not, then use a list instead. # This is actually more efficient because boxplot converts # a 2-D array into a list of vectors internally anyway. data = [data, d2, d2[::2, 0]] # multiple box plots on one figure -figure() -boxplot(data) +plt.figure() +plt.boxplot(data) -show() +plt.show() diff --git a/examples/pylab_examples/break.py b/examples/pylab_examples/break.py index 6b1f6142d1da..37e13aa8c867 100644 --- a/examples/pylab_examples/break.py +++ b/examples/pylab_examples/break.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python -from pylab import * +import matplotlib.pyplot as plt +plt.gcf().text(0.5, 0.95, 'Distance Histograms by Category is \ + a really long title') -gcf().text(0.5, 0.95, - 'Distance Histograms by Category is a really long title') - -show() +plt.show() diff --git a/examples/pylab_examples/clippedline.py b/examples/pylab_examples/clippedline.py index d33bf4b2a1e4..ad1db567c869 100644 --- a/examples/pylab_examples/clippedline.py +++ b/examples/pylab_examples/clippedline.py @@ -9,13 +9,14 @@ """ from matplotlib.lines import Line2D +import matplotlib.pyplot as plt import numpy as np -from pylab import figure, show class ClippedLine(Line2D): """ - Clip the xlimits to the axes view limits -- this example assumes x is sorted + Clip the xlimits to the axes view limits + this example assumes x is sorted """ def __init__(self, ax, *args, **kwargs): @@ -45,7 +46,7 @@ def draw(self, renderer): Line2D.draw(self, renderer) -fig = figure() +fig = plt.figure() ax = fig.add_subplot(111, autoscale_on=False) t = np.arange(0.0, 100.0, 0.01) @@ -54,4 +55,4 @@ def draw(self, renderer): ax.add_line(line) ax.set_xlim(10, 30) ax.set_ylim(-1.1, 1.1) -show() +plt.show()