Revision: 5688
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5688&view=rev
Author: jdh2358
Date: 2008-06-27 08:25:50 -0700 (Fri, 27 Jun 2008)
Log Message:
-----------
more doc examples and cleanups
Modified Paths:
--------------
trunk/matplotlib/examples/pylab_examples/axhspan_demo.py
trunk/matplotlib/examples/pylab_examples/barchart_demo.py
trunk/matplotlib/examples/pylab_examples/contour_demo.py
trunk/matplotlib/examples/pylab_examples/figimage_demo.py
trunk/matplotlib/examples/pylab_examples/figlegend_demo.py
trunk/matplotlib/examples/pylab_examples/log_demo.py
trunk/matplotlib/lib/matplotlib/axes.py
trunk/matplotlib/lib/matplotlib/contour.py
trunk/matplotlib/lib/matplotlib/figure.py
Modified: trunk/matplotlib/examples/pylab_examples/axhspan_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/axhspan_demo.py 2008-06-27 13:33:33 UTC (rev 5687)
+++ trunk/matplotlib/examples/pylab_examples/axhspan_demo.py 2008-06-27 15:25:50 UTC (rev 5688)
@@ -1,40 +1,32 @@
-#!/usr/bin/env python
+import numpy as np
+import matplotlib.pyplot as plt
-from pylab import *
-figure(1)
-plot(10*rand(12), 'o')
-xlim(0,15)
-xticks([2, 4, 8, 12], ('John', 'Hunter', 'Was', 'Here'))
+t = np.arange(-1,2, .01)
+s = np.sin(2*np.pi*t)
-ylim(-1,10)
-yticks(range(8))
-
-figure(2)
-t = arange(-1,2, .01)
-s = sin(2*pi*t)
-plot(t,s)
+plt.plot(t,s)
# draw a thick red hline at y=0 that spans the xrange
-l = axhline(linewidth=4, color='r')
+l = plt.axhline(linewidth=4, color='r')
# draw a default hline at y=1 that spans the xrange
-l = axhline(y=1)
+l = plt.axhline(y=1)
# draw a default vline at x=1 that spans the xrange
-l = axvline(x=1)
+l = plt.axvline(x=1)
# draw a thick blue vline at x=0 that spans the the upper quadrant of
# the yrange
-l = axvline(x=0, ymin=0.75, linewidth=4, color='b')
+l = plt.axvline(x=0, ymin=0.75, linewidth=4, color='b')
# draw a default hline at y=.5 that spans the the middle half of
# the axes
-l = axhline(y=.5, xmin=0.25, xmax=0.75)
+l = plt.axhline(y=.5, xmin=0.25, xmax=0.75)
-p = axhspan(0.25, 0.75, facecolor='0.5', alpha=0.5)
+p = plt.axhspan(0.25, 0.75, facecolor='0.5', alpha=0.5)
-p = axvspan(1.25, 1.55, facecolor='g', alpha=0.5)
+p = plt.axvspan(1.25, 1.55, facecolor='g', alpha=0.5)
-axis([-1,2,-1,2])
+plt.axis([-1,2,-1,2])
-show()
+plt.show()
Modified: trunk/matplotlib/examples/pylab_examples/barchart_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/barchart_demo.py 2008-06-27 13:33:33 UTC (rev 5687)
+++ trunk/matplotlib/examples/pylab_examples/barchart_demo.py 2008-06-27 15:25:50 UTC (rev 5688)
@@ -1,39 +1,38 @@
#!/usr/bin/env python
-# a bar plot with errorbars
-from numpy import arange
-from matplotlib.pyplot import *
+import numpy as np
+import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)
-ind = arange(N) # the x locations for the groups
+ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
-figure()
-subplot(111)
-rects1 = bar(ind, menMeans, width, color='r', yerr=menStd)
+plt.subplot(111)
+rects1 = plt.bar(ind, menMeans, width, color='r', yerr=menStd)
+
womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)
-rects2 = bar(ind+width, womenMeans, width, color='y', yerr=womenStd)
+rects2 = plt.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)
# add some
-ylabel('Scores')
-title('Scores by group and gender')
-xticks(ind+width, ('G1', 'G2', 'G3', 'G4', 'G5') )
+plt.ylabel('Scores')
+plt.title('Scores by group and gender')
+plt.xticks(ind+width, ('G1', 'G2', 'G3', 'G4', 'G5') )
-legend( (rects1[0], rects2[0]), ('Men', 'Women') )
+plt.legend( (rects1[0], rects2[0]), ('Men', 'Women') )
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
- text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
+ plt.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
#savefig('barchart_demo')
-show()
+plt.show()
Modified: trunk/matplotlib/examples/pylab_examples/contour_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/contour_demo.py 2008-06-27 13:33:33 UTC (rev 5687)
+++ trunk/matplotlib/examples/pylab_examples/contour_demo.py 2008-06-27 15:25:50 UTC (rev 5688)
@@ -1,21 +1,25 @@
#!/usr/bin/env python
-'''
+"""
Illustrate simple contour plotting, contours on an image with
a colorbar for the contours, and labelled contours.
See also contour_image.py.
-'''
-from pylab import *
+"""
+import matplotlib
+import numpy as np
+import matplotlib.cm as cm
+import matplotlib.mlab as mlab
+import matplotlib.pyplot as plt
-rcParams['xtick.direction'] = 'out'
-rcParams['ytick.direction'] = 'out'
+matplotlib.rcParams['xtick.direction'] = 'out'
+matplotlib.rcParams['ytick.direction'] = 'out'
delta = 0.025
-x = arange(-3.0, 3.0, delta)
-y = arange(-2.0, 2.0, delta)
-X, Y = meshgrid(x, y)
-Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
-Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
+x = np.arange(-3.0, 3.0, delta)
+y = np.arange(-2.0, 2.0, delta)
+X, Y = np.meshgrid(x, y)
+Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
+Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)
@@ -25,77 +29,77 @@
# inline argument to clabel will control whether the labels are draw
# over the line segments of the contour, removing the lines beneath
# the label
-figure()
-CS = contour(X, Y, Z)
-clabel(CS, inline=1, fontsize=10)
-title('Simplest default with labels')
+plt.figure()
+CS = plt.contour(X, Y, Z)
+plt.clabel(CS, inline=1, fontsize=10)
+plt.title('Simplest default with labels')
# You can force all the contours to be the same color.
-figure()
-CS = contour(X, Y, Z, 6,
- colors='k', # negative contours will be dashed by default
- )
-clabel(CS, fontsize=9, inline=1)
-title('Single color - negative contours dashed')
+plt.figure()
+CS = plt.contour(X, Y, Z, 6,
+ colors='k', # negative contours will be dashed by default
+ )
+plt.clabel(CS, fontsize=9, inline=1)
+plt.title('Single color - negative contours dashed')
# You can set negative contours to be solid instead of dashed:
-rcParams['contour.negative_linestyle'] = 'solid'
-figure()
-CS = contour(X, Y, Z, 6,
- colors='k', # negative contours will be dashed by default
- )
-clabel(CS, fontsize=9, inline=1)
-title('Single color - negative contours solid')
+matplotlib.rcParams['contour.negative_linestyle'] = 'solid'
+plt.figure()
+CS = plt.contour(X, Y, Z, 6,
+ colors='k', # negative contours will be dashed by default
+ )
+plt.clabel(CS, fontsize=9, inline=1)
+plt.title('Single color - negative contours solid')
# And you can manually specify the colors of the contour
-figure()
-CS = contour(X, Y, Z, 6,
- linewidths=arange(.5, 4, .5),
- colors=('r', 'green', 'blue', (1,1,0), '#afeeee', '0.5')
- )
-clabel(CS, fontsize=9, inline=1)
-title('Crazy lines')
+plt.figure()
+CS = plt.contour(X, Y, Z, 6,
+ linewidths=np.arange(.5, 4, .5),
+ colors=('r', 'green', 'blue', (1,1,0), '#afeeee', '0.5')
+ )
+plt.clabel(CS, fontsize=9, inline=1)
+plt.title('Crazy lines')
# Or you can use a colormap to specify the colors; the default
# colormap will be used for the contour lines
-figure()
-im = imshow(Z, interpolation='bilinear', origin='lower',
- cmap=cm.gray, extent=(-3,3,-2,2))
-levels = arange(-1.2, 1.6, 0.2)
-CS = contour(Z, levels,
- origin='lower',
- linewidths=2,
- extent=(-3,3,-2,2))
+plt.figure()
+im = plt.imshow(Z, interpolation='bilinear', origin='lower',
+ cmap=cm.gray, extent=(-3,3,-2,2))
+levels = np.arange(-1.2, 1.6, 0.2)
+CS = plt.contour(Z, levels,
+ origin='lower',
+ linewidths=2,
+ extent=(-3,3,-2,2))
#Thicken the zero contour.
zc = CS.collections[6]
-setp(zc, linewidth=4)
+plt.setp(zc, linewidth=4)
-clabel(CS, levels[1::2], # label every second level
- inline=1,
- fmt='%1.1f',
- fontsize=14)
+plt.clabel(CS, levels[1::2], # label every second level
+ inline=1,
+ fmt='%1.1f',
+ fontsize=14)
# make a colorbar for the contour lines
-CB = colorbar(CS, shrink=0.8, extend='both')
+CB = plt.colorbar(CS, shrink=0.8, extend='both')
-title('Lines with colorbar')
-hot() # Now change the colormap for the contour lines and colorbar
-flag()
+plt.title('Lines with colorbar')
+#plt.hot() # Now change the colormap for the contour lines and colorbar
+plt.flag()
# We can still add a colorbar for the image, too.
-CBI = colorbar(im, orientation='horizontal', shrink=0.8)
+CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8)
# This makes the original colorbar look a bit out of place,
# so let's improve its position.
-l,b,w,h = gca().get_position().bounds
+l,b,w,h = plt.gca().get_position().bounds
ll,bb,ww,hh = CB.ax.get_position().bounds
CB.ax.set_position([ll, b+0.1*h, ww, h*0.8])
#savefig('contour_demo')
-show()
+plt.show()
Modified: trunk/matplotlib/examples/pylab_examples/figimage_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/figimage_demo.py 2008-06-27 13:33:33 UTC (rev 5687)
+++ trunk/matplotlib/examples/pylab_examples/figimage_demo.py 2008-06-27 15:25:50 UTC (rev 5688)
@@ -1,21 +1,21 @@
-#!/usr/bin/env python
"""
See pcolor_demo2 for a much faster way of generating pcolor plots
"""
-from __future__ import division
-from pylab import *
-rc('axes', hold=True)
-rc('image', origin='upper')
-figure(1, frameon=False)
-Z = arange(10000.0); Z.shape = 100,100
-Z[:,50:] = 1
-jet() # sets the default
-im1 = figimage(Z, xo=50, yo=0)
-im2 = figimage(Z, xo=100, yo=100, alpha=.8)
-#gray() # overrides current and sets default
-#savefig('figimage_demo')
+import numpy as np
+import matplotlib
+import matplotlib.cm as cm
+import matplotlib.pyplot as plt
-show()
+fig = plt.figure(frameon=False)
+Z = np.arange(10000.0)
+Z.shape = 100,100
+Z[:,50:] = 1.
+im1 = plt.figimage(Z, xo=50, yo=0, cmap=cm.jet)
+im2 = plt.figimage(Z, xo=100, yo=100, alpha=.8, cmap=cm.jet)
+plt.show()
+
+
+
Modified: trunk/matplotlib/examples/pylab_examples/figlegend_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/figlegend_demo.py 2008-06-27 13:33:33 UTC (rev 5687)
+++ trunk/matplotlib/examples/pylab_examples/figlegend_demo.py 2008-06-27 15:25:50 UTC (rev 5688)
@@ -1,18 +1,19 @@
-#!/usr/bin/env python
+import numpy as np
+import matplotlib.pyplot as plt
-from pylab import *
-ax1 = axes([0.1, 0.1, 0.4, 0.7])
-ax2 = axes([0.55, 0.1, 0.4, 0.7])
+fig = plt.figure()
+ax1 = fig.add_axes([0.1, 0.1, 0.4, 0.7])
+ax2 = fig.add_axes([0.55, 0.1, 0.4, 0.7])
-x = arange(0.0, 2.0, 0.02)
-y1 = sin(2*pi*x)
-y2 = exp(-x)
+x = np.arange(0.0, 2.0, 0.02)
+y1 = np.sin(2*np.pi*x)
+y2 = np.exp(-x)
l1, l2 = ax1.plot(x, y1, 'rs-', x, y2, 'go')
-y3 = sin(4*pi*x)
-y4 = exp(-2*x)
+y3 = np.sin(4*np.pi*x)
+y4 = np.exp(-2*x)
l3, l4 = ax2.plot(x, y3, 'yd-', x, y3, 'k^')
-figlegend((l1, l2), ('Line 1', 'Line 2'), 'upper left')
-figlegend((l3, l4), ('Line 3', 'Line 4'), 'upper right')
-show()
+fig.legend((l1, l2), ('Line 1', 'Line 2'), 'upper left')
+fig.legend((l3, l4), ('Line 3', 'Line 4'), 'upper right')
+plt.show()
Modified: trunk/matplotlib/examples/pylab_examples/log_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/log_demo.py 2008-06-27 13:33:33 UTC (rev 5687)
+++ trunk/matplotlib/examples/pylab_examples/log_demo.py 2008-06-27 15:25:50 UTC (rev 5688)
@@ -1,26 +1,25 @@
-#!/usr/bin/env python
-from pylab import *
+import numpy as np
+import matplotlib.pyplot as plt
-dt = 0.01
-t = arange(dt, 20.0, dt)
+plt.subplots_adjust(hspace=0.4)
+t = np.arange(0.01, 20.0, 0.01)
-subplot(311)
-semilogy(t, exp(-t/5.0))
-ylabel('semilogy')
-grid(True)
+# log y axis
+plt.subplot(311)
+plt.semilogy(t, np.exp(-t/5.0))
+plt.ylabel('semilogy')
+plt.grid(True)
-subplot(312)
-semilogx(t, sin(2*pi*t))
-ylabel('semilogx')
+# log x axis
+plt.subplot(312)
+plt.semilogx(t, np.sin(2*np.pi*t))
+plt.ylabel('semilogx')
+plt.grid(True)
+# log x and y axis
+plt.subplot(313)
+plt.loglog(t, 20*np.exp(-t/10.0), basex=4)
+plt.grid(True)
+plt.ylabel('loglog base 4 on x')
-
-grid(True)
-gca().xaxis.grid(True, which='minor') # minor grid on too
-
-subplot(313)
-loglog(t, 20*exp(-t/10.0), basex=4)
-grid(True)
-ylabel('loglog base 4 on x')
-savefig('log_demo')
-show()
+plt.show()
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py 2008-06-27 13:33:33 UTC (rev 5687)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2008-06-27 15:25:50 UTC (rev 5688)
@@ -2697,6 +2697,8 @@
Valid kwargs are :class:`~matplotlib.lines.Line2D` properties:
%(Line2D)s
+
+ See :meth:`axhspan` for example plot and source code
"""
ymin, ymax = self.get_ylim()
@@ -2747,6 +2749,8 @@
Valid kwargs are :class:`~matplotlib.lines.Line2D` properties:
%(Line2D)s
+
+ See :meth:`axhspan` for example plot and source code
"""
xmin, xmax = self.get_xlim()
@@ -2793,6 +2797,11 @@
Valid kwargs are :class:`~matplotlib.patches.Polygon` properties:
%(Polygon)s
+
+ **Example:**
+
+ .. plot:: ../mpl_examples/pylab_examples/axhspan_demo.py
+
"""
# convert y axis units
trans = mtransforms.blended_transform_factory(
@@ -2836,6 +2845,8 @@
properties:
%(Polygon)s
+
+ See :meth:`axhspan` for example plot and source code
"""
# convert x axis units
trans = mtransforms.blended_transform_factory(
@@ -3214,6 +3225,11 @@
:class:`~matplotlib.lines.Line2D` properties:
%(Line2D)s
+
+ **Example:**
+
+ .. plot:: ../mpl_examples/pylab_examples/log_demo.py
+
"""
if not self._hold: self.cla()
@@ -3262,6 +3278,8 @@
:class:`~matplotlib.lines.Line2D` properties:
%(Line2D)s
+
+ See :meth:`loglog` for example code and figure
"""
if not self._hold: self.cla()
d = {'basex': kwargs.pop( 'basex', 10),
@@ -3303,6 +3321,8 @@
:class:`~matplotlib.lines.Line2D` properties:
%(Line2D)s
+
+ See :meth:`loglog` for example code and figure
"""
if not self._hold: self.cla()
d = {'basey': kwargs.pop('basey', 10),
@@ -3371,6 +3391,8 @@
:func:`~matplotlib.pyplot.xcorr` above, and
:func:`~matplotlib.pyplot.acorr` below.
+ **Example:**
+
.. plot:: ../mpl_examples/pylab_examples/xcorr_demo.py
"""
return self.xcorr(x, x, **kwargs)
@@ -3426,6 +3448,8 @@
:func:`~matplotlib.pyplot.xcorr` above, and
:func:`~matplotlib.pyplot.acorr` below.
+ **Example:**
+
.. plot:: ../mpl_examples/pylab_examples/xcorr_demo.py
"""
@@ -3565,6 +3589,10 @@
*axespad*: [ None | scalar ]
The border between the axes and legend edge. If *None*, use rc
settings.
+
+ **Example:**
+
+ .. plot:: legend_demo.py
"""
def get_handles():
@@ -3724,10 +3752,8 @@
%(Rectangle)s
- **Example:**
+ **Example:** A stacked bar chart.
- A stacked bar chart.
-
.. plot:: ../mpl_examples/pylab_examples/bar_stacked.py
"""
if not self._hold: self.cla()
@@ -4295,6 +4321,11 @@
the third element is a list of
:class:`~matplotlib.collections.LineCollection` instances for
the horizontal and vertical error ranges.
+
+ **Example:**
+
+ .. plot:: errorbar_demo.py
+
"""
self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
@@ -4496,6 +4527,9 @@
Returns a list of the :class:`matplotlib.lines.Line2D`
instances added.
+ **Example:**
+
+ .. plot:: boxplot_demo.py
"""
if not self._hold: self.cla()
holdStatus = self._hold
Modified: trunk/matplotlib/lib/matplotlib/contour.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/contour.py 2008-06-27 13:33:33 UTC (rev 5687)
+++ trunk/matplotlib/lib/matplotlib/contour.py 2008-06-27 15:25:50 UTC (rev 5688)
@@ -69,6 +69,7 @@
*fmt*:
a format string for the label. Default is '%1.3f'
+
"""
fontsize = kwargs.get('fontsize', None)
inline = kwargs.get('inline', 1)
@@ -892,4 +893,5 @@
be removed. Chunking introduces artifacts at the chunk boundaries
unless *antialiased* is *False*.
+ .. plot:: contour_demo.py
"""
Modified: trunk/matplotlib/lib/matplotlib/figure.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/figure.py 2008-06-27 13:33:33 UTC (rev 5687)
+++ trunk/matplotlib/lib/matplotlib/figure.py 2008-06-27 15:25:50 UTC (rev 5688)
@@ -468,6 +468,9 @@
:class:`~matplotlib.axes.Axes` with size [0,1,0,1].
An :class:`matplotlib.image.FigureImage` instance is returned.
+
+ .. plot:: ../mpl_examples/pylab_examples/figimage_demo.py
+
"""
if not self._hold: self.clf()
@@ -912,6 +915,7 @@
*axespad*
the border between the axes and legend edge
+ .. plot:: ../mpl_examples/pylab_examples/figlegend_demo.py
"""
handles = flatten(handles)
l = Legend(self, handles, labels, *args, **kwargs)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|