# HG changeset patch
# User Karl-Dieter Crisman <kcrisman@gmail.com>
# Date 1297738595 18000
# Node ID 398687a996483a352a91e318bdd2fb30f424edb7
# Parent be86952efaf5568c677b98b7ba0f8b342d89ebf6
Trac # 2100 - change new default aspect ratio to do 'automatic' instead of 'auto'.
This also fixes vector plotting.
diff -r be86952efaf5 -r 398687a99648 sage/plot/bar_chart.py
|
a
|
b
|
|
| 119 | 119 | subplot.bar(ind, datalist, color=color, width=width, label=options['legend_label']) |
| 120 | 120 | |
| 121 | 121 | @rename_keyword(color='rgbcolor') |
| 122 | | @options(width=0.5, rgbcolor=(0,0,1), legend_label=None, aspect_ratio='auto') |
| | 122 | @options(width=0.5, rgbcolor=(0,0,1), legend_label=None, aspect_ratio='automatic') |
| 123 | 123 | def bar_chart(datalist, **options): |
| 124 | 124 | """ |
| 125 | 125 | A bar chart of (currently) one list of numerical data. |
diff -r be86952efaf5 -r 398687a99648 sage/plot/line.py
|
a
|
b
|
|
| 275 | 275 | |
| 276 | 276 | |
| 277 | 277 | @rename_keyword(color='rgbcolor') |
| 278 | | @options(alpha=1, rgbcolor=(0,0,1), thickness=1, legend_label=None) |
| | 278 | @options(alpha=1, rgbcolor=(0,0,1), thickness=1, legend_label=None, aspect_ratio ='automatic') |
| 279 | 279 | def line2d(points, **options): |
| 280 | 280 | r""" |
| 281 | 281 | Create the line through the given list of points. |
diff -r be86952efaf5 -r 398687a99648 sage/plot/plot.py
|
a
|
b
|
|
| 470 | 470 | """ |
| 471 | 471 | Set the aspect ratio, which is the ratio of height and width |
| 472 | 472 | of a unit square (i.e., height/width of a unit square), or |
| 473 | | 'auto' (expand to fill the figure). |
| | 473 | 'automatic' (expand to fill the figure). |
| 474 | 474 | |
| 475 | 475 | INPUT: |
| 476 | 476 | |
| 477 | 477 | |
| 478 | | - ``ratio`` - a positive real number or 'auto' |
| | 478 | - ``ratio`` - a positive real number or 'automatic' |
| 479 | 479 | |
| 480 | 480 | |
| 481 | 481 | EXAMPLES: We create a plot of a circle, and it doesn't look quite |
| … |
… |
|
| 501 | 501 | sage: P + Q |
| 502 | 502 | sage: Q + P |
| 503 | 503 | """ |
| 504 | | if ratio != 'auto': |
| | 504 | if ratio != 'auto' and ratio != 'automatic': |
| 505 | 505 | ratio = float(ratio) |
| 506 | 506 | if ratio <= 0: |
| 507 | | raise ValueError, "the aspect ratio must be positive or 'auto'" |
| | 507 | raise ValueError, "the aspect ratio must be positive or 'automatic'" |
| | 508 | else: |
| | 509 | ratio = 'automatic' |
| 508 | 510 | self.__aspect_ratio = ratio |
| 509 | 511 | |
| 510 | 512 | def aspect_ratio(self): |
| 511 | 513 | """ |
| 512 | 514 | Get the current aspect ratio, which is the ratio of height to |
| 513 | | width of a unit square, or 'auto'. |
| 514 | | |
| 515 | | OUTPUT: a positive float (height/width of a unit square), or 'auto' |
| | 515 | width of a unit square, or 'automatic'. |
| | 516 | |
| | 517 | OUTPUT: a positive float (height/width of a unit square), or 'automatic' |
| 516 | 518 | (expand to fill the figure). |
| 517 | 519 | |
| 518 | 520 | EXAMPLES:: |
| … |
… |
|
| 523 | 525 | sage: P.set_aspect_ratio(2) |
| 524 | 526 | sage: P.aspect_ratio() |
| 525 | 527 | 2.0 |
| 526 | | sage: P.set_aspect_ratio('auto') |
| | 528 | sage: P.set_aspect_ratio('automatic') |
| 527 | 529 | sage: P.aspect_ratio() |
| 528 | | 'auto' |
| | 530 | 'automatic' |
| 529 | 531 | """ |
| 530 | 532 | return self.__aspect_ratio |
| 531 | 533 | |
| … |
… |
|
| 1251 | 1253 | The xmin, xmax, ymin, and ymax properties of the graphics objects |
| 1252 | 1254 | are expanded to include all objects in both scenes. If the aspect |
| 1253 | 1255 | ratio property of either or both objects are set, then the larger |
| 1254 | | aspect ratio is chosen, with 'auto' being overridden by a |
| | 1256 | aspect ratio is chosen, with 'automatic' being overridden by a |
| 1255 | 1257 | numeric aspect ratio. |
| 1256 | 1258 | |
| 1257 | 1259 | If one of the graphics object is set to show a legend, then the |
| … |
… |
|
| 1268 | 1270 | |
| 1269 | 1271 | Extra keywords to show are propagated:: |
| 1270 | 1272 | |
| 1271 | | sage: (g1 + g2)._extra_kwds=={'aspect_ratio': 'auto', 'frame': True} |
| | 1273 | sage: (g1 + g2)._extra_kwds=={'aspect_ratio': 'automatic', 'frame': True} |
| 1272 | 1274 | True |
| 1273 | 1275 | """ |
| 1274 | 1276 | if isinstance(other, int) and other == 0: |
| … |
… |
|
| 1280 | 1282 | raise TypeError, "other (=%s) must be a Graphics objects"%other |
| 1281 | 1283 | g = Graphics() |
| 1282 | 1284 | g.__objects = self.__objects + other.__objects |
| 1283 | | if self.__aspect_ratio=='auto': |
| | 1285 | if self.__aspect_ratio=='automatic': |
| 1284 | 1286 | g.__aspect_ratio=other.__aspect_ratio |
| 1285 | | elif other.__aspect_ratio=='auto': |
| | 1287 | elif other.__aspect_ratio=='automatic': |
| 1286 | 1288 | g.__aspect_ratio=self.__aspect_ratio |
| 1287 | 1289 | else: |
| 1288 | 1290 | g.__aspect_ratio = max(self.__aspect_ratio, other.__aspect_ratio) |
| … |
… |
|
| 1420 | 1422 | will look round and a unit square will appear to have sides |
| 1421 | 1423 | of equal length. If the aspect ratio is set ``2``, vertical units will be |
| 1422 | 1424 | twice as long as horizontal units, so a unit square will be twice as |
| 1423 | | high as it is wide. If set to ``'auto'``, the aspect ratio |
| | 1425 | high as it is wide. If set to ``'automatic'``, the aspect ratio |
| 1424 | 1426 | is determined by ``figsize`` and the picture fills the figure. |
| 1425 | 1427 | |
| 1426 | 1428 | - ``axes`` - (default: True) |
| … |
… |
|
| 1968 | 1970 | subplot = figure.add_subplot(111) |
| 1969 | 1971 | if aspect_ratio is None: |
| 1970 | 1972 | aspect_ratio=self.aspect_ratio() |
| 1971 | | subplot.set_aspect(aspect_ratio, adjustable='box') |
| | 1973 | if aspect_ratio == 'automatic': |
| | 1974 | subplot.set_aspect('auto', adjustable='box') |
| | 1975 | else: |
| | 1976 | subplot.set_aspect(aspect_ratio, adjustable='box') |
| 1972 | 1977 | #add all the primitives to the subplot |
| 1973 | 1978 | for g in self.__objects: |
| 1974 | 1979 | g._render_on_subplot(subplot) |
| … |
… |
|
| 2691 | 2696 | @rename_keyword(color='rgbcolor') |
| 2692 | 2697 | @options(alpha=1, thickness=1, fill=False, fillcolor='automatic', fillalpha=0.5, rgbcolor=(0,0,1), plot_points=200, |
| 2693 | 2698 | adaptive_tolerance=0.01, adaptive_recursion=5, detect_poles = False, exclude = None, legend_label=None, |
| 2694 | | __original_opts=True, aspect_ratio='auto') |
| | 2699 | __original_opts=True, aspect_ratio='automatic') |
| 2695 | 2700 | def plot(funcs, *args, **kwds): |
| 2696 | 2701 | r""" |
| 2697 | 2702 | Use plot by writing |
| … |
… |
|
| 3535 | 3540 | kwds['polar']=True |
| 3536 | 3541 | return plot(funcs, *args, **kwds) |
| 3537 | 3542 | |
| 3538 | | @options(aspect_ratio='auto') |
| | 3543 | @options(aspect_ratio='automatic') |
| 3539 | 3544 | def list_plot(data, plotjoined=False, **kwargs): |
| 3540 | 3545 | r""" |
| 3541 | 3546 | ``list_plot`` takes either a single list of data, a list of tuples, |
diff -r be86952efaf5 -r 398687a99648 sage/plot/plot3d/base.pyx
|
a
|
b
|
|
| 947 | 947 | opts['aspect_ratio'] = (1, 1, 1) |
| 948 | 948 | if not isinstance(opts['aspect_ratio'], (str, list, tuple)): |
| 949 | 949 | raise TypeError, 'aspect ratio must be a string, list, tuple, or 1' |
| | 950 | # deal with any aspect_ratio instances passed from the default options to plot |
| | 951 | if opts['aspect_ratio'] == 'auto': |
| | 952 | opts['aspect_ratio'] = 'automatic' |
| 950 | 953 | |
| 951 | 954 | if opts['frame_aspect_ratio'] == 'automatic': |
| 952 | 955 | if opts['aspect_ratio'] != 'automatic': |
| … |
… |
|
| 1029 | 1032 | |
| 1030 | 1033 | sage: sphere((0,0,0)) |
| 1031 | 1034 | |
| 1032 | | EXAMPLES: We illustrate use of the aspect_ratio option:: |
| | 1035 | EXAMPLES: We illustrate use of the ``aspect_ratio`` option:: |
| 1033 | 1036 | |
| 1034 | 1037 | sage: x, y = var('x,y') |
| 1035 | 1038 | sage: p = plot3d(2*sin(x*y), (x, -pi, pi), (y, -pi, pi)) |
| … |
… |
|
| 1043 | 1046 | |
| 1044 | 1047 | sage: p.show(aspect_ratio=[1,1,1], frame_aspect_ratio=[1,1,1/8]) |
| 1045 | 1048 | |
| | 1049 | This example shows indirectly that the defaults |
| | 1050 | from :func:`~sage.plot.plot.plot` are dealt with properly:: |
| | 1051 | |
| | 1052 | sage: plot(vector([1,2,3])) |
| | 1053 | |
| 1046 | 1054 | We use the 'canvas3d' backend from inside the notebook to get a view of |
| 1047 | 1055 | the plot rendered inline using HTML canvas:: |
| 1048 | 1056 | |
diff -r be86952efaf5 -r 398687a99648 sage/plot/plot3d/plot_field3d.py
|
a
|
b
|
|
| 57 | 57 | sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),plot_points=4) |
| 58 | 58 | sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),plot_points=[3,5,7]) |
| 59 | 59 | sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),center_arrows=True) |
| | 60 | |
| | 61 | TESTS: |
| | 62 | |
| | 63 | This tests that Trac # 2100 is fixed in a way compatible with this command:: |
| | 64 | |
| | 65 | sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),center_arrows=True,aspect_ratio=(1,2,1)) |
| 60 | 66 | """ |
| 61 | 67 | (ff,gg,hh), ranges = setup_for_eval_on_grid(functions, [xrange, yrange, zrange], plot_points) |
| 62 | 68 | xpoints, ypoints, zpoints = [srange(*r, include_endpoint=True) for r in ranges] |
diff -r be86952efaf5 -r 398687a99648 sage/plot/point.py
|
a
|
b
|
|
| 312 | 312 | return point3d(points, **kwds) |
| 313 | 313 | |
| 314 | 314 | @rename_keyword(color='rgbcolor', pointsize='size') |
| 315 | | @options(alpha=1, size=10, faceted=False, rgbcolor=(0,0,1), legend_label=None) |
| | 315 | @options(alpha=1, size=10, faceted=False, rgbcolor=(0,0,1), legend_label=None, aspect_ratio='automatic') |
| 316 | 316 | def point2d(points, **options): |
| 317 | 317 | r""" |
| 318 | 318 | A point of size ``size`` defined by point = `(x,y)`. |
diff -r be86952efaf5 -r 398687a99648 sage/plot/scatter_plot.py
|
a
|
b
|
|
| 128 | 128 | options = self.options() |
| 129 | 129 | subplot.scatter(self.xdata, self.ydata, alpha=options['alpha'], zorder=options['zorder'], marker=options['marker'],s=options['markersize'],facecolors=options['facecolor'], edgecolors=options['edgecolor']) |
| 130 | 130 | |
| 131 | | @options(alpha=1, markersize=50, marker='o', zorder=5, facecolor='#fec7b8', edgecolor='black', aspect_ratio='auto') |
| | 131 | @options(alpha=1, markersize=50, marker='o', zorder=5, facecolor='#fec7b8', edgecolor='black', aspect_ratio='automatic') |
| 132 | 132 | def scatter_plot(datalist, **options): |
| 133 | 133 | """ |
| 134 | 134 | Returns a Graphics object of a scatter plot containing all points in |