|
30 | 30 | from transforms import Bbox, Point, Value, Affine |
31 | 31 | from transforms import Func, LOG10, IDENTITY |
32 | 32 | from transforms import get_bbox_transform, unit_bbox |
| 33 | +from transforms import blend_xy_sep_transform |
33 | 34 | from font_manager import FontProperties |
34 | 35 |
|
35 | 36 | import matplotlib |
@@ -339,6 +340,146 @@ def __init__(self, fig, rect, |
339 | 340 | # funcs used to format x and y - fall back on major formatters |
340 | 341 | self.fmt_xdata = None |
341 | 342 | 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 |
342 | 483 |
|
343 | 484 | def format_xdata(self, x): |
344 | 485 | """ |
@@ -703,6 +844,9 @@ def clear(self): |
703 | 844 | def cohere(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none, |
704 | 845 | window=mlab.window_hanning, noverlap=0): |
705 | 846 | """ |
| 847 | + COHERE(x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none, |
| 848 | + window=mlab.window_hanning, noverlap=0): |
| 849 | +
|
706 | 850 | cohere the coherence between x and y. Coherence is the normalized |
707 | 851 | cross spectral density |
708 | 852 |
|
@@ -733,6 +877,10 @@ def cohere(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none, |
733 | 877 | def csd(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none, |
734 | 878 | window=mlab.window_hanning, noverlap=0): |
735 | 879 | """ |
| 880 | +
|
| 881 | + CSD(x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none, |
| 882 | + window=mlab.window_hanning, noverlap=0): |
| 883 | +
|
736 | 884 | The cross spectral density Pxy by Welches average periodogram |
737 | 885 | method. The vectors x and y are divided into NFFT length |
738 | 886 | segments. Each segment is detrended by function detrend and |
@@ -935,18 +1083,35 @@ def errorbar(self, x, y, yerr=None, xerr=None, |
935 | 1083 |
|
936 | 1084 | def fill(self, *args, **kwargs): |
937 | 1085 | """ |
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) |
942 | 1087 | |
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 |
945 | 1095 |
|
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') |
948 | 1098 |
|
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. |
950 | 1115 | """ |
951 | 1116 | if not self._hold: self.cla() |
952 | 1117 | patches = [] |
@@ -1050,7 +1215,6 @@ def hist(self, x, bins=10, normed=0, bottom=0): |
1050 | 1215 | If normed is true, the first element of the return tuple will be the |
1051 | 1216 | counts normalized to form a probability distribtion, ie, |
1052 | 1217 | n/(len(x)*dbin) |
1053 | | -
|
1054 | 1218 | """ |
1055 | 1219 | if not self._hold: self.cla() |
1056 | 1220 | n,bins = mlab.hist(x, bins, normed) |
@@ -1173,6 +1337,8 @@ def in_axes(self, xwin, ywin): |
1173 | 1337 |
|
1174 | 1338 | def hlines(self, y, xmin, xmax, fmt='k-'): |
1175 | 1339 | """ |
| 1340 | + HLINES(y, xmin, xmax, fmt='k-') |
| 1341 | +
|
1176 | 1342 | plot horizontal lines at each y from xmin to xmax. xmin or |
1177 | 1343 | xmax can be scalars or len(x) numpy arrays. If they are |
1178 | 1344 | scalars, then the respective values are constant, else the |
@@ -1210,6 +1376,8 @@ def hlines(self, y, xmin, xmax, fmt='k-'): |
1210 | 1376 |
|
1211 | 1377 | def legend(self, *args, **kwargs): |
1212 | 1378 | """ |
| 1379 | + LEGEND(*args, **kwargs) |
| 1380 | +
|
1213 | 1381 | Place a legend on the current axes at location loc. Labels are a |
1214 | 1382 | sequence of strings and loc can be a string or an integer |
1215 | 1383 | specifying the legend location |
@@ -1737,6 +1905,9 @@ def plot_date(self, d, y, fmt='bo', tz=None, **kwargs): |
1737 | 1905 | def psd(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none, |
1738 | 1906 | window=mlab.window_hanning, noverlap=0): |
1739 | 1907 | """ |
| 1908 | + PSD(x, NFFT=256, Fs=2, detrend=mlab.detrend_none, |
| 1909 | + window=mlab.window_hanning, noverlap=0) |
| 1910 | +
|
1740 | 1911 | The power spectral density by Welches average periodogram method. |
1741 | 1912 | The vector x is divided into NFFT length segments. Each segment |
1742 | 1913 | is detrended by function detrend and windowed by function window. |
@@ -1800,6 +1971,7 @@ def set_position(self, pos): |
1800 | 1971 |
|
1801 | 1972 | def stem(self, x, y, linefmt='b-', markerfmt='bo', basefmt='r-'): |
1802 | 1973 | """ |
| 1974 | + STEM(x, y, linefmt='b-', markerfmt='bo', basefmt='r-') |
1803 | 1975 |
|
1804 | 1976 | A stem plot plots vertical lines (using linefmt) at each x |
1805 | 1977 | 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', |
1837 | 2009 | vmax = None, |
1838 | 2010 | alpha=1.0): |
1839 | 2011 | """\ |
1840 | | -
|
| 2012 | +SCATTER(x, y, s=20, c='b', marker='o', cmap=None, norm=None, |
| 2013 | + vmin=None, vmax=None, alpha=1.0) |
| 2014 | + |
1841 | 2015 | SCATTER(x, y) - make a scatter plot of x vs y |
1842 | 2016 |
|
1843 | 2017 | 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', |
1961 | 2135 |
|
1962 | 2136 | def scatter_classic(self, x, y, s=None, c='b'): |
1963 | 2137 | """ |
| 2138 | + SCATTER_CLASSIC(x, y, s=None, c='b') |
| 2139 | +
|
1964 | 2140 | Make a scatter plot of x versus y. s is a size (in data |
1965 | 2141 | coords) and can be either a scalar or an array of the same |
1966 | 2142 | length as x or y. c is a color and can be a single color |
@@ -2255,13 +2431,18 @@ def table(self, |
2255 | 2431 | colLabels=None, colColours=None, colLoc='center', |
2256 | 2432 | loc='bottom', bbox=None): |
2257 | 2433 | """ |
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): |
2261 | 2439 |
|
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. |
2264 | 2443 |
|
| 2444 | +Thanks to John Gill for providing the class and table. |
| 2445 | + """ |
2265 | 2446 | # Check we have some cellText |
2266 | 2447 | if cellText is None: |
2267 | 2448 | # assume just colours are needed |
@@ -2413,6 +2594,7 @@ def text(self, x, y, text, fontdict=None, **kwargs): |
2413 | 2594 |
|
2414 | 2595 | def vlines(self, x, ymin, ymax, color='k'): |
2415 | 2596 | """ |
| 2597 | + VLINES(x, ymin, ymax, color='k') |
2416 | 2598 | Plot vertical lines at each x from ymin to ymax. ymin or ymax |
2417 | 2599 | can be scalars or len(x) numpy arrays. If they are scalars, |
2418 | 2600 | then the respective values are constant, else the heights of |
|
0 commit comments