Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6294083

Browse files
committed
simplified matlab interface wrapper
svn path=/trunk/matplotlib/; revision=594
1 parent e64f3d4 commit 6294083

5 files changed

Lines changed: 270 additions & 753 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
New entries should be added at the top
22

33
==============================================================
4+
2004-10-16 Streamlined the matlab interface wrapper, removed the
5+
noplot option to hist - just use mlab.hist instead.
46

57
2004-09-30 Added Andrew Dalke's strftime code to extend the range of
68
dates supported by the DateFormatter - JDH

examples/print_stdout.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python
12
# print png to standard out
23
# usage: python print_stdout.py > somefile.png
34
import sys

lib/matplotlib/axes.py

Lines changed: 198 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from transforms import Bbox, Point, Value, Affine
3131
from transforms import Func, LOG10, IDENTITY
3232
from transforms import get_bbox_transform, unit_bbox
33+
from transforms import blend_xy_sep_transform
3334
from font_manager import FontProperties
3435

3536
import matplotlib
@@ -339,6 +340,146 @@ def __init__(self, fig, rect,
339340
# funcs used to format x and y - fall back on major formatters
340341
self.fmt_xdata = None
341342
self.fmt_ydata = None
343+
344+
345+
def axhline(self, y=0, xmin=0, xmax=1, **kwargs):
346+
"""\
347+
AXHLINE(y=0, xmin=0, xmax=1, **kwargs)
348+
349+
axhline : Axis Horizontal Line
350+
351+
Draw a horizontal line at y from xmin to xmax. With the default
352+
values of xmin=0 and xmax=1, this line will always span the horizontal
353+
extent of the axes, regardless of the xlim settings, even if you
354+
change them, eg with the xlim command. That is, the horizontal extent
355+
is in axes coords: 0=left, 0.5=middle, 1.0=right but the y location is
356+
in data coordinates.
357+
358+
return value is the Line2D instance. kwargs are the same as kwargs to
359+
plot, and can be used to control the line properties. Eg
360+
361+
# draw a thick red hline at y=0 that spans the xrange
362+
l = ax.axhline(linewidth=4, color='r')
363+
364+
# draw a default hline at y=1 that spans the xrange
365+
l = ax.axhline(y=1)
366+
367+
# draw a default hline at y=.5 that spans the the middle half of
368+
# the xrange
369+
l = ax.axhline(y=.5, xmin=0.25, xmax=0.75)
370+
371+
"""
372+
trans = blend_xy_sep_transform( self.transAxes, self.transData)
373+
l, = self.plot([xmin,xmax], [y,y], transform=trans, **kwargs)
374+
return l
375+
376+
377+
def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
378+
"""\
379+
AXVLINE(x=0, ymin=0, ymax=1, **kwargs)
380+
axvline : Axis Vertical Line
381+
382+
Draw a vertical line at x from ymin to ymax. With the default values
383+
of ymin=0 and ymax=1, this line will always span the vertical extent
384+
of the axes, regardless of the xlim settings, even if you change them,
385+
eg with the xlim command. That is, the vertical extent is in axes
386+
coords: 0=bottom, 0.5=middle, 1.0=top but the x location is in data
387+
coordinates.
388+
389+
return value is the Line2D instance. kwargs are the same as
390+
kwargs to plot, and can be used to control the line properties. Eg
391+
392+
# draw a thick red vline at x=0 that spans the yrange
393+
l = axvline(linewidth=4, color='r')
394+
395+
# draw a default vline at x=1 that spans the yrange
396+
l = axvline(x=1)
397+
398+
# draw a default vline at x=.5 that spans the the middle half of
399+
# the yrange
400+
l = axvline(x=.5, ymin=0.25, ymax=0.75)
401+
402+
"""
403+
404+
trans = blend_xy_sep_transform( self.transData, self.transAxes )
405+
l, = self.plot([x,x], [ymin,ymax] , transform=trans, **kwargs)
406+
return l
407+
408+
409+
def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
410+
"""\
411+
AXHSPAN(ymin, ymax, xmin=0, xmax=1, **kwargs)
412+
413+
axhspan : Axis Horizontal Span. ycoords are in data units and x
414+
coords are in axes (relative 0-1) units
415+
416+
Draw a horizontal span (regtangle) from ymin to ymax. With the
417+
default values of xmin=0 and xmax=1, this always span the xrange,
418+
regardless of the xlim settings, even if you change them, eg with the
419+
xlim command. That is, the horizontal extent is in axes coords:
420+
0=left, 0.5=middle, 1.0=right but the y location is in data
421+
coordinates.
422+
423+
kwargs are the kwargs to Patch, eg
424+
425+
antialiased, aa
426+
linewidth, lw
427+
edgecolor, ec
428+
facecolor, fc
429+
430+
the terms on the right are aliases
431+
432+
return value is the patches.Polygon instance.
433+
434+
#draws a gray rectangle from y=0.25-0.75 that spans the horizontal
435+
#extent of the axes
436+
p = ax.axhspan(0.25, 0.75, facecolor=0.5, alpha=0.5)
437+
"""
438+
trans = blend_xy_sep_transform( self.transAxes, self.transData )
439+
verts = (xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)
440+
p = Polygon(verts, **kwargs)
441+
p.set_transform(trans)
442+
self.add_patch(p)
443+
return p
444+
445+
446+
def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
447+
"""\
448+
AXVSPAN(self, xmin, xmax, ymin=0, ymax=1, **kwargs)
449+
450+
axvspan : Axis Vertical Span. xcoords are in data units and y coords
451+
are in axes (relative 0-1) units
452+
453+
Draw a vertical span (regtangle) from xmin to xmax. With the default
454+
values of ymin=0 and ymax=1, this always span the yrange, regardless
455+
of the ylim settings, even if you change them, eg with the ylim
456+
command. That is, the vertical extent is in axes coords: 0=bottom,
457+
0.5=middle, 1.0=top but the y location is in data coordinates.
458+
459+
kwargs are the kwargs to Patch, eg
460+
461+
antialiased, aa
462+
linewidth, lw
463+
edgecolor, ec
464+
facecolor, fc
465+
466+
the terms on the right are aliases
467+
468+
return value is the patches.Polygon instance.
469+
470+
# draw a vertical green translucent rectangle from x=1.25 to 1.55 that
471+
# spans the yrange of the axes
472+
p = ax.axvspan(1.25, 1.55, facecolor='g', alpha=0.5)
473+
474+
"""
475+
476+
trans = blend_xy_sep_transform( self.transData, self.transAxes )
477+
verts = (xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)
478+
p = Polygon(verts, **kwargs)
479+
p.set_transform(trans)
480+
self.add_patch(p)
481+
482+
return p
342483

343484
def format_xdata(self, x):
344485
"""
@@ -703,6 +844,9 @@ def clear(self):
703844
def cohere(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
704845
window=mlab.window_hanning, noverlap=0):
705846
"""
847+
COHERE(x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
848+
window=mlab.window_hanning, noverlap=0):
849+
706850
cohere the coherence between x and y. Coherence is the normalized
707851
cross spectral density
708852
@@ -733,6 +877,10 @@ def cohere(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
733877
def csd(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
734878
window=mlab.window_hanning, noverlap=0):
735879
"""
880+
881+
CSD(x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
882+
window=mlab.window_hanning, noverlap=0):
883+
736884
The cross spectral density Pxy by Welches average periodogram
737885
method. The vectors x and y are divided into NFFT length
738886
segments. Each segment is detrended by function detrend and
@@ -935,18 +1083,35 @@ def errorbar(self, x, y, yerr=None, xerr=None,
9351083

9361084
def fill(self, *args, **kwargs):
9371085
"""
938-
Emulate matlab's fill command. *args is a variable length
939-
argument, allowing for multiple x,y pairs with an optional
940-
color format string. For example, all of the following are
941-
legal, assuming a is the Axis instance:
1086+
FILL(*args, **kwargs)
9421087
943-
a.fill(x,y) # plot polygon with vertices at x,y
944-
a.fill(x,y, 'b' ) # plot polygon with vertices at x,y in blue
1088+
plot filled polygons. *args is a variable length argument,
1089+
allowing for multiple x,y pairs with an optional color format
1090+
string. For example, all of the following are legal, assuming a
1091+
is the Axis instance:
1092+
1093+
ax.fill(x,y) # plot polygon with vertices at x,y
1094+
ax.fill(x,y, 'b' ) # plot polygon with vertices at x,y in blue
9451095
946-
An arbitrary number of x, y, color groups can be specified, as in
947-
a.fill(x1, y1, 'g', x2, y2, 'r')
1096+
An arbitrary number of x, y, color groups can be specified, as in
1097+
ax.fill(x1, y1, 'g', x2, y2, 'r')
9481098
949-
Returns a list of patches that were added.
1099+
Return value is a list of patches that were added
1100+
1101+
The following color strings are supported
1102+
1103+
b : blue
1104+
g : green
1105+
r : red
1106+
c : cyan
1107+
m : magenta
1108+
y : yellow
1109+
k : black
1110+
w : white
1111+
1112+
The kwargs that are can be used to set line properties (any
1113+
property that has a set_* method). You can use this to set edge
1114+
color, face color, etc.
9501115
"""
9511116
if not self._hold: self.cla()
9521117
patches = []
@@ -1050,7 +1215,6 @@ def hist(self, x, bins=10, normed=0, bottom=0):
10501215
If normed is true, the first element of the return tuple will be the
10511216
counts normalized to form a probability distribtion, ie,
10521217
n/(len(x)*dbin)
1053-
10541218
"""
10551219
if not self._hold: self.cla()
10561220
n,bins = mlab.hist(x, bins, normed)
@@ -1173,6 +1337,8 @@ def in_axes(self, xwin, ywin):
11731337

11741338
def hlines(self, y, xmin, xmax, fmt='k-'):
11751339
"""
1340+
HLINES(y, xmin, xmax, fmt='k-')
1341+
11761342
plot horizontal lines at each y from xmin to xmax. xmin or
11771343
xmax can be scalars or len(x) numpy arrays. If they are
11781344
scalars, then the respective values are constant, else the
@@ -1210,6 +1376,8 @@ def hlines(self, y, xmin, xmax, fmt='k-'):
12101376

12111377
def legend(self, *args, **kwargs):
12121378
"""
1379+
LEGEND(*args, **kwargs)
1380+
12131381
Place a legend on the current axes at location loc. Labels are a
12141382
sequence of strings and loc can be a string or an integer
12151383
specifying the legend location
@@ -1737,6 +1905,9 @@ def plot_date(self, d, y, fmt='bo', tz=None, **kwargs):
17371905
def psd(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none,
17381906
window=mlab.window_hanning, noverlap=0):
17391907
"""
1908+
PSD(x, NFFT=256, Fs=2, detrend=mlab.detrend_none,
1909+
window=mlab.window_hanning, noverlap=0)
1910+
17401911
The power spectral density by Welches average periodogram method.
17411912
The vector x is divided into NFFT length segments. Each segment
17421913
is detrended by function detrend and windowed by function window.
@@ -1800,6 +1971,7 @@ def set_position(self, pos):
18001971

18011972
def stem(self, x, y, linefmt='b-', markerfmt='bo', basefmt='r-'):
18021973
"""
1974+
STEM(x, y, linefmt='b-', markerfmt='bo', basefmt='r-')
18031975
18041976
A stem plot plots vertical lines (using linefmt) at each x
18051977
location from the baseline to y, and places a marker there using
@@ -1837,7 +2009,9 @@ def scatter(self, x, y, s=20, c='b',
18372009
vmax = None,
18382010
alpha=1.0):
18392011
"""\
1840-
2012+
SCATTER(x, y, s=20, c='b', marker='o', cmap=None, norm=None,
2013+
vmin=None, vmax=None, alpha=1.0)
2014+
18412015
SCATTER(x, y) - make a scatter plot of x vs y
18422016
18432017
SCATTER(x, y, s) - make a scatter plot of x vs y with size in area
@@ -1961,6 +2135,8 @@ def scatter(self, x, y, s=20, c='b',
19612135

19622136
def scatter_classic(self, x, y, s=None, c='b'):
19632137
"""
2138+
SCATTER_CLASSIC(x, y, s=None, c='b')
2139+
19642140
Make a scatter plot of x versus y. s is a size (in data
19652141
coords) and can be either a scalar or an array of the same
19662142
length as x or y. c is a color and can be a single color
@@ -2255,13 +2431,18 @@ def table(self,
22552431
colLabels=None, colColours=None, colLoc='center',
22562432
loc='bottom', bbox=None):
22572433
"""
2258-
Create a table and add it to the axes. Returns a table
2259-
instance. For finer grained control over tables, use the
2260-
Table class and add it to the axes with add_table.
2434+
TABLE(cellText=None, cellColours=None,
2435+
cellLoc='right', colWidths=None,
2436+
rowLabels=None, rowColours=None, rowLoc='left',
2437+
colLabels=None, colColours=None, colLoc='center',
2438+
loc='bottom', bbox=None):
22612439
2262-
Thanks to John Gill for providing the class and table.
2263-
"""
2440+
Add a table to the current axes. Returns a table instance. For
2441+
finer grained control over tables, use the Table class and add it
2442+
to the axes with add_table.
22642443
2444+
Thanks to John Gill for providing the class and table.
2445+
"""
22652446
# Check we have some cellText
22662447
if cellText is None:
22672448
# assume just colours are needed
@@ -2413,6 +2594,7 @@ def text(self, x, y, text, fontdict=None, **kwargs):
24132594

24142595
def vlines(self, x, ymin, ymax, color='k'):
24152596
"""
2597+
VLINES(x, ymin, ymax, color='k')
24162598
Plot vertical lines at each x from ymin to ymax. ymin or ymax
24172599
can be scalars or len(x) numpy arrays. If they are scalars,
24182600
then the respective values are constant, else the heights of

lib/matplotlib/backends/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def draw_if_interactive():
4747
def draw_if_interactive(): pass
4848
def show(): pass
4949
def error_msg(m):
50-
verbse.report_error(m)
50+
matplotlib.verbose.report_error(m)
5151
sys.exit()
5252

5353
# Additional imports which only happen for certain backends. This section

0 commit comments

Comments
 (0)