From 645e155c2f01ab7ac087730b3a8aeb5230fbb0a5 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 5 Mar 2023 21:30:54 -0800 Subject: [PATCH 01/21] sage.plot: Add # optional - numpy --- src/sage/plot/complex_plot.pyx | 22 +++++++++--------- src/sage/plot/line.py | 4 ++-- src/sage/plot/matrix_plot.py | 4 ++-- src/sage/plot/plot.py | 42 +++++++++++++++++----------------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/sage/plot/complex_plot.pyx b/src/sage/plot/complex_plot.pyx index efb923a2df7..70ee0924490 100644 --- a/src/sage/plot/complex_plot.pyx +++ b/src/sage/plot/complex_plot.pyx @@ -669,11 +669,11 @@ def add_lightness_smoothing_to_rgb(rgb, delta): We can call this on grids of values:: - sage: import numpy as np - sage: from sage.plot.complex_plot import add_lightness_smoothing_to_rgb - sage: add_lightness_smoothing_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 + sage: import numpy as np # optional - numpy + sage: from sage.plot.complex_plot import add_lightness_smoothing_to_rgb # optional - numpy + sage: add_lightness_smoothing_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 # optional - numpy array([[[0.75 , 0.8125, 0.875 ]]]) - sage: add_lightness_smoothing_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 + sage: add_lightness_smoothing_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 # optional - numpy array([[[0.75 , 0.8125, 0.875 ]]]) """ import numpy as np @@ -731,21 +731,21 @@ def add_contours_to_rgb(rgb, delta, dark_rate=0.5): EXAMPLES:: - sage: import numpy as np - sage: from sage.plot.complex_plot import add_contours_to_rgb - sage: add_contours_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 + sage: import numpy as np # optional - numpy + sage: from sage.plot.complex_plot import add_contours_to_rgb # optional - numpy + sage: add_contours_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 # optional - numpy array([[[0.25 , 0.625, 1. ]]]) - sage: add_contours_to_rgb(np.array([[[0, 0, 0]]]), np.array([[1]])) # abs tol 1e-4 + sage: add_contours_to_rgb(np.array([[[0, 0, 0]]]), np.array([[1]])) # abs tol 1e-4 # optional - numpy array([[[0.5, 0.5, 0.5]]]) - sage: add_contours_to_rgb(np.array([[[1, 1, 1]]]), np.array([[-0.5]])) # abs tol 1e-4 + sage: add_contours_to_rgb(np.array([[[1, 1, 1]]]), np.array([[-0.5]])) # abs tol 1e-4 # optional - numpy array([[[0.75, 0.75, 0.75]]]) Raising ``dark_rate`` leads to bigger adjustments:: - sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 + sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 # optional - numpy ....: np.array([[0.5]]), dark_rate=0.1) array([[[0.55, 0.55, 0.55]]]) - sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 + sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 # optional - numpy ....: np.array([[0.5]]), dark_rate=0.5) array([[[0.75, 0.75, 0.75]]]) """ diff --git a/src/sage/plot/line.py b/src/sage/plot/line.py index 691e3c31307..8c2d8ec0ad1 100644 --- a/src/sage/plot/line.py +++ b/src/sage/plot/line.py @@ -391,14 +391,14 @@ def line2d(points, **options): sage: line([]) #returns an empty plot Graphics object consisting of 0 graphics primitives - sage: import numpy; line(numpy.array([])) + sage: import numpy; line(numpy.array([])) # optional - numpy Graphics object consisting of 0 graphics primitives sage: line([(1,1)]) Graphics object consisting of 1 graphics primitive A line with numpy arrays:: - sage: line(numpy.array([[1,2], [3,4]])) + sage: line(numpy.array([[1,2], [3,4]])) # optional - numpy Graphics object consisting of 1 graphics primitive A line with a legend:: diff --git a/src/sage/plot/matrix_plot.py b/src/sage/plot/matrix_plot.py index 7676aebe02d..65df86e50a9 100644 --- a/src/sage/plot/matrix_plot.py +++ b/src/sage/plot/matrix_plot.py @@ -496,8 +496,8 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): As does plotting of NumPy arrays:: - sage: import numpy - sage: matrix_plot(numpy.random.rand(10, 10)) + sage: import numpy # optional - numpy + sage: matrix_plot(numpy.random.rand(10, 10)) # optional - numpy Graphics object consisting of 1 graphics primitive A plot title can be added to the matrix plot.:: diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index ced087a3814..cd3e966c639 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -683,16 +683,16 @@ def SelectiveFormatter(formatter, skip_values): sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.pyplot as plt - sage: import numpy - sage: fig=plt.figure() - sage: ax=fig.add_subplot(111) - sage: t = numpy.arange(0.0, 2.0, 0.01) - sage: s = numpy.sin(2*numpy.pi*t) - sage: p = ax.plot(t, s) - sage: formatter=SelectiveFormatter(ax.xaxis.get_major_formatter(),skip_values=[0,1]) - sage: ax.xaxis.set_major_formatter(formatter) + sage: import numpy # optional - numpy + sage: fig = plt.figure() + sage: ax = fig.add_subplot(111) + sage: t = numpy.arange(0.0, 2.0, 0.01) # optional - numpy + sage: s = numpy.sin(2*numpy.pi*t) # optional - numpy + sage: p = ax.plot(t, s) # optional - numpy + sage: formatter=SelectiveFormatter(ax.xaxis.get_major_formatter(), skip_values=[0,1]) # optional - numpy + sage: ax.xaxis.set_major_formatter(formatter) # optional - numpy sage: import tempfile - sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # optional - numpy ....: fig.savefig(f.name) """ @@ -717,16 +717,16 @@ def __init__(self, formatter, skip_values): sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.pyplot as plt - sage: import numpy - sage: fig=plt.figure() - sage: ax=fig.add_subplot(111) - sage: t = numpy.arange(0.0, 2.0, 0.01) - sage: s = numpy.sin(2*numpy.pi*t) - sage: line=ax.plot(t, s) - sage: formatter=SelectiveFormatter(ax.xaxis.get_major_formatter(),skip_values=[0,1]) - sage: ax.xaxis.set_major_formatter(formatter) + sage: import numpy # optional - numpy + sage: fig = plt.figure() + sage: ax = fig.add_subplot(111) + sage: t = numpy.arange(0.0, 2.0, 0.01) # optional - numpy + sage: s = numpy.sin(2*numpy.pi*t) # optional - numpy + sage: line = ax.plot(t, s) # optional - numpy + sage: formatter = SelectiveFormatter(ax.xaxis.get_major_formatter(), skip_values=[0,1]) # optional - numpy + sage: ax.xaxis.set_major_formatter(formatter) # optional - numpy sage: from tempfile import NamedTemporaryFile - sage: with NamedTemporaryFile(suffix=".png") as f: + sage: with NamedTemporaryFile(suffix=".png") as f: # optional - numpy ....: fig.savefig(f.name) """ self.formatter=formatter @@ -2896,8 +2896,8 @@ def list_plot(data, plotjoined=False, **kwargs): You can provide a numpy array.:: - sage: import numpy - sage: list_plot(numpy.arange(10)) + sage: import numpy # optional - numpy + sage: list_plot(numpy.arange(10)) # optional - numpy Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -2908,7 +2908,7 @@ def list_plot(data, plotjoined=False, **kwargs): :: - sage: list_plot(numpy.array([[1,2], [2,3], [3,4]])) + sage: list_plot(numpy.array([[1,2], [2,3], [3,4]])) # optional - numpy Graphics object consisting of 1 graphics primitive .. PLOT:: From b78ebc7616810bd85b1e498c49656d2401698a5f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 17 May 2023 13:20:30 -0700 Subject: [PATCH 02/21] Massive modularization fixes --- src/sage/plot/colors.py | 2 +- src/sage/plot/plot.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/plot/colors.py b/src/sage/plot/colors.py index bc89be406ea..78b58ba6090 100644 --- a/src/sage/plot/colors.py +++ b/src/sage/plot/colors.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.plot r""" Colors diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index cd3e966c639..d83fb24cad7 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -3093,7 +3093,7 @@ def list_plot(data, plotjoined=False, **kwargs): # a tuple. # So, the only other check we need to do is whether data[0] is an # element of the Symbolic Ring. - if data[0] in sage.symbolic.ring.SR: + if isinstance(data[0], Expression): data = list(enumerate(data)) try: From 45115bb4138109c32e759fdfb75749e48da41797 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 14 Jun 2023 23:25:05 -0700 Subject: [PATCH 03/21] sage.ext, sage.plot: More # optional --- src/sage/ext/fast_callable.pyx | 2 +- src/sage/plot/complex_plot.pyx | 56 +++++++++++++++++----------------- src/sage/plot/plot3d/plot3d.py | 34 ++++++++++++++------- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/sage/ext/fast_callable.pyx b/src/sage/ext/fast_callable.pyx index 6634b027ef5..6097b3d718d 100644 --- a/src/sage/ext/fast_callable.pyx +++ b/src/sage/ext/fast_callable.pyx @@ -1622,7 +1622,7 @@ class IntegerPowerFunction(): sage: cube = IntegerPowerFunction(3) sage: cube (^3) - sage: cube(AA(7)^(1/3)) + sage: cube(AA(7)^(1/3)) # optional - sage.rings.number_field 7.000000000000000? sage: cube.exponent 3 diff --git a/src/sage/plot/complex_plot.pyx b/src/sage/plot/complex_plot.pyx index 70ee0924490..e17c970d521 100644 --- a/src/sage/plot/complex_plot.pyx +++ b/src/sage/plot/complex_plot.pyx @@ -927,7 +927,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Here we plot a couple of simple functions:: - sage: complex_plot(sqrt(x), (-5, 5), (-5, 5)) + sage: complex_plot(sqrt(x), (-5, 5), (-5, 5)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -936,7 +936,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, :: - sage: complex_plot(sin(x), (-5, 5), (-5, 5)) + sage: complex_plot(sin(x), (-5, 5), (-5, 5)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -945,7 +945,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, :: - sage: complex_plot(log(x), (-10, 10), (-10, 10)) + sage: complex_plot(log(x), (-10, 10), (-10, 10)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -954,7 +954,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, :: - sage: complex_plot(exp(x), (-10, 10), (-10, 10)) + sage: complex_plot(exp(x), (-10, 10), (-10, 10)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -963,7 +963,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, A plot with a different choice of colormap:: - sage: complex_plot(exp(x), (-10, 10), (-10, 10), cmap='viridis') + sage: complex_plot(exp(x), (-10, 10), (-10, 10), cmap='viridis') # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -972,8 +972,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, A function with some nice zeros and a pole:: - sage: f(z) = z^5 + z - 1 + 1/z - sage: complex_plot(f, (-3, 3), (-3, 3)) + sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -984,8 +984,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, The same function as above, but with contours. Contours render poorly with few plot points, so we use 300 here:: - sage: f(z) = z^5 + z - 1 + 1/z - sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, contoured=True) + sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, contoured=True) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -995,8 +995,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, The same function as above, but tiled and with the *plasma* colormap:: - sage: f(z) = z^5 + z - 1 + 1/z - sage: complex_plot(f, (-3, 3), (-3, 3), + sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), # optional - sage.symbolic ....: plot_points=300, tiled=True, cmap='plasma') Graphics object consisting of 1 graphics primitive @@ -1009,8 +1009,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, controlled by adjusting ``nphases``. We make the same plot with fewer tilings:: - sage: f(z) = z^5 + z - 1 + 1/z - sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, + sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, # optional - sage.symbolic ....: tiled=True, nphases=5, cmap='plasma') Graphics object consisting of 1 graphics primitive @@ -1022,8 +1022,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, It is also possible to use *linear* contours. We plot the same function above on an inset, setting contours to appear `1` apart:: - sage: f(z) = z^5 + z - 1 + 1/z - sage: complex_plot(f, (0, 1), (0, 1), plot_points=300, + sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic + sage: complex_plot(f, (0, 1), (0, 1), plot_points=300, # optional - sage.symbolic ....: contoured=True, contour_type='linear', contour_base=1) Graphics object consisting of 1 graphics primitive @@ -1035,8 +1035,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Note that tightly spaced contours can lead to Moiré patterns and aliasing problems. For example:: - sage: f(z) = z^5 + z - 1 + 1/z - sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, + sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, # optional - sage.symbolic ....: contoured=True, contour_type='linear', contour_base=1) Graphics object consisting of 1 graphics primitive @@ -1049,8 +1049,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, be considered more appropriate for showing changes in phase without sharp color contrasts:: - sage: f(z) = z^5 + z - 1 + 1/z - sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, cmap='twilight') + sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, cmap='twilight') # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1061,8 +1061,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Passing *matplotlib* as the colormap gives a special colormap that is similar to the default:: - sage: f(z) = z^5 + z - 1 + 1/z - sage: complex_plot(f, (-3, 3), (-3, 3), + sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), # optional - sage.symbolic ....: plot_points=300, contoured=True, cmap='matplotlib') Graphics object consisting of 1 graphics primitive @@ -1073,7 +1073,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Here is the identity, useful for seeing what values map to what colors:: - sage: complex_plot(lambda z: z, (-3, 3), (-3, 3)) + sage: complex_plot(lambda z: z, (-3, 3), (-3, 3)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1082,7 +1082,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, The Riemann Zeta function:: - sage: complex_plot(zeta, (-30,30), (-30,30)) + sage: complex_plot(zeta, (-30,30), (-30,30)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1093,7 +1093,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, ``dark_rate`` will make regions become darker/lighter faster when there are no contours:: - sage: complex_plot(zeta, (-30, 30), (-30, 30), dark_rate=1.0) + sage: complex_plot(zeta, (-30, 30), (-30, 30), dark_rate=1.0) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1103,7 +1103,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Decreasing ``dark_rate`` has the opposite effect. When there are contours, adjust ``dark_rate`` affects how visible contours are. Compare:: - sage: complex_plot(zeta, (-1, 9), (10, 20), plot_points=200, # long time + sage: complex_plot(zeta, (-1, 9), (10, 20), plot_points=200, # long time # optional - sage.symbolic ....: contoured=True, cmap='twilight', dark_rate=0.2) Graphics object consisting of 1 graphics primitive @@ -1113,7 +1113,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, and:: - sage: complex_plot(zeta, (-1, 9), (10, 20), plot_points=200, # long time + sage: complex_plot(zeta, (-1, 9), (10, 20), plot_points=200, # long time # optional - sage.symbolic ....: contoured=True, cmap='twilight', dark_rate=0.75) Graphics object consisting of 1 graphics primitive @@ -1126,12 +1126,12 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Extra options will get passed on to show(), as long as they are valid:: - sage: complex_plot(lambda z: z, (-3, 3), (-3, 3), figsize=[1,1]) + sage: complex_plot(lambda z: z, (-3, 3), (-3, 3), figsize=[1,1]) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive :: - sage: complex_plot(lambda z: z, (-3, 3), (-3, 3)).show(figsize=[1,1]) # These are equivalent + sage: complex_plot(lambda z: z, (-3, 3), (-3, 3)).show(figsize=[1,1]) # These are equivalent # optional - sage.symbolic REFERENCES: diff --git a/src/sage/plot/plot3d/plot3d.py b/src/sage/plot/plot3d/plot3d.py index 9ba89595d70..7b45d9b98c1 100644 --- a/src/sage/plot/plot3d/plot3d.py +++ b/src/sage/plot/plot3d/plot3d.py @@ -4,7 +4,8 @@ EXAMPLES:: sage: x, y = var('x y') - sage: W = plot3d(sin(pi*((x)^2 + (y)^2))/2, (x, -1, 1), (y, -1, 1), frame=False, color='purple', opacity=0.8) + sage: W = plot3d(sin(pi*((x)^2 + (y)^2))/2, (x, -1, 1), (y, -1, 1), + ....: frame=False, color='purple', opacity=0.8) sage: S = sphere((0, 0, 0), size=0.3, color='red', aspect_ratio=[1,1,1]) sage: show(W + S, figsize=8) @@ -30,7 +31,8 @@ sage: def f(x,y): ....: return math.sin(y^2 + x^2)/math.sqrt(x^2 + y^2 + 0.0001) - sage: P = plot3d(f, (-3, 3),(-3, 3), adaptive=True, color=rainbow(60, 'rgbtuple'), max_bend=.1, max_depth=15) + sage: P = plot3d(f, (-3, 3),(-3, 3), adaptive=True, + ....: color=rainbow(60, 'rgbtuple'), max_bend=.1, max_depth=15) sage: P.show() .. ONLY:: html @@ -121,11 +123,14 @@ def c(x, y): return float((x + y + x*y)/15) % 1 :: - sage: S += sphere((.45, -.1, .15), size=.1, color='white') + sphere((.51,-.1,.17), size=.05, color='black') - sage: S += sphere((.45, .1, .15), size=.1, color='white') + sphere((.51, .1,.17), size=.05, color='black') + sage: S += sphere((.45, -.1, .15), size=.1, color='white') + sage: S += sphere((.51,-.1,.17), size=.05, color='black') + sage: S += sphere((.45, .1, .15), size=.1, color='white') + sage: S += sphere((.51, .1,.17), size=.05, color='black') sage: S += sphere((.5, 0, -.2), size=.1, color='yellow') sage: def f(x,y): return math.exp(x/5)*math.cos(y) - sage: P = plot3d(f, (-5, 5), (-5, 5), adaptive=True, color=['red','yellow'], max_depth=10) + sage: P = plot3d(f, (-5, 5), (-5, 5), adaptive=True, + ....: color=['red','yellow'], max_depth=10) sage: cape_man = P.scale(.2) + S.translate(1, 0, 0) sage: cape_man.show(aspect_ratio=[1, 1, 1]) @@ -703,7 +708,8 @@ class SphericalElevation(_Coordinates): Plot a sin curve wrapped around the equator:: - sage: P1 = plot3d( (pi/12)*sin(8*theta), (r,0.99,1), (theta, 0, 2*pi), transformation=SE, plot_points=(10,200)) + sage: P1 = plot3d((pi/12)*sin(8*theta), (r,0.99,1), (theta, 0, 2*pi), + ....: transformation=SE, plot_points=(10,200)) sage: P2 = sphere(center=(0,0,0), size=1, color='red', opacity=0.3) sage: P1 + P2 Graphics3d Object @@ -736,10 +742,14 @@ class SphericalElevation(_Coordinates): sage: r, phi, theta = var('r phi theta') sage: SE = SphericalElevation('elevation', ['radius', 'azimuth']) sage: angles = [pi/18, pi/12, pi/6] - sage: P1 = [plot3d( a, (r,0,3), (theta, 0, 2*pi), transformation=SE, opacity=0.85, color='blue') for a in angles] + sage: P1 = [plot3d(a, (r,0,3), (theta, 0, 2*pi), transformation=SE, + ....: opacity=0.85, color='blue') + ....: for a in angles] sage: S = Spherical('inclination', ['radius', 'azimuth']) - sage: P2 = [plot3d( a, (r,0,3), (theta, 0, 2*pi), transformation=S, opacity=0.85, color='red') for a in angles] + sage: P2 = [plot3d(a, (r,0,3), (theta, 0, 2*pi), transformation=S, + ....: opacity=0.85, color='red') + ....: for a in angles] sage: show(sum(P1+P2), aspect_ratio=1) .. ONLY:: html @@ -1084,7 +1094,7 @@ def plot3d(f, urange, vrange, adaptive=False, transformation=None, **kwds): sage: var('x,y') (x, y) - sage: plot3d(sin(x^2 + y^2),(x,-5,5),(y,-5,5), plot_points=200) + sage: plot3d(sin(x^2 + y^2), (x,-5,5), (y,-5,5), plot_points=200) Graphics3d Object .. ONLY:: html @@ -1152,8 +1162,10 @@ def plot3d(f, urange, vrange, adaptive=False, transformation=None, **kwds): Two wobby translucent planes:: sage: x,y = var('x,y') - sage: P = plot3d(x + y + sin(x*y), (x, -10, 10), (y, -10, 10), opacity=0.87, color='blue') - sage: Q = plot3d(x - 2*y - cos(x*y),(x, -10, 10), (y, -10, 10), opacity=0.3, color='red') + sage: P = plot3d(x + y + sin(x*y), (x, -10, 10), (y, -10, 10), + ....: opacity=0.87, color='blue') + sage: Q = plot3d(x - 2*y - cos(x*y),(x, -10, 10), (y, -10, 10), + ....: opacity=0.3, color='red') sage: P + Q Graphics3d Object From caacd0a444e908dc0c9d754d5c65f0b14e1d02f5 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 17 Jun 2023 21:02:21 -0700 Subject: [PATCH 04/21] More # optional --- src/sage/plot/plot3d/implicit_plot3d.py | 121 +++++++++------ src/sage/plot/plot3d/implicit_surface.pyx | 1 + src/sage/plot/plot3d/index_face_set.pyx | 46 +++--- src/sage/plot/plot3d/list_plot3d.py | 93 +++++++----- src/sage/plot/plot3d/plot3d.py | 1 + src/sage/plot/plot3d/plot_field3d.py | 34 +++-- src/sage/plot/plot3d/revolution_plot3d.py | 59 +++++--- src/sage/plot/plot3d/shapes.pyx | 88 ++++++----- src/sage/plot/plot3d/shapes2.py | 110 +++++++------- src/sage/plot/plot3d/tachyon.py | 176 ++++++++++++---------- src/sage/plot/plot_field.py | 1 + src/sage/plot/point.py | 41 ++--- src/sage/plot/polygon.py | 57 ++++--- src/sage/plot/step.py | 8 +- src/sage/plot/streamline_plot.py | 12 +- src/sage/plot/text.py | 25 +-- 16 files changed, 513 insertions(+), 360 deletions(-) diff --git a/src/sage/plot/plot3d/implicit_plot3d.py b/src/sage/plot/plot3d/implicit_plot3d.py index cfebf8a2f3b..43eae504837 100644 --- a/src/sage/plot/plot3d/implicit_plot3d.py +++ b/src/sage/plot/plot3d/implicit_plot3d.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic """ Implicit plots """ @@ -23,13 +24,13 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): marching cubes algorithm will be one less than this). Can be a triple of integers, to specify a different resolution in each of x,y,z. - - ``contour`` -- (default: 0) plot the isosurface f(x,y,z)==contour. Can be a - list, in which case multiple contours are plotted. + - ``contour`` -- (default: 0) plot the isosurface ``f(x,y,z) == contour``. + Can be a list, in which case multiple contours are plotted. - ``region`` -- (default: None) If region is given, it must be a Python - callable. Only segments of the surface where region(x,y,z) returns a - number >0 will be included in the plot. (Note that returning a Python - boolean is acceptable, since True == 1 and False == 0). + callable. Only segments of the surface where ``region(x,y,z)`` returns a + number `>0` will be included in the plot. (Note that returning a Python + boolean is acceptable, since ``True == 1`` and ``False == 0``). EXAMPLES:: @@ -51,8 +52,9 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): A nested set of spheres with a hole cut out:: sage: F = x^2 + y^2 + z^2 - sage: P = implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), plot_points=60, contour=[1,3,5], - ....: region=lambda x,y,z: x<=0.2 or y>=0.2 or z<=0.2, color='aquamarine') + sage: P = implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), plot_points=60, + ....: contour=[1,3,5], color='aquamarine', + ....: region=lambda x,y,z: x<=0.2 or y>=0.2 or z<=0.2) sage: P.show(viewer='tachyon') # long time .. PLOT:: @@ -67,9 +69,11 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): `_):: sage: T = RDF(golden_ratio) - sage: F = 2 - (cos(x+T*y) + cos(x-T*y) + cos(y+T*z) + cos(y-T*z) + cos(z-T*x) + cos(z+T*x)) + sage: F = 2 - (cos(x+T*y) + cos(x-T*y) + cos(y+T*z) + ....: + cos(y-T*z) + cos(z-T*x) + cos(z+T*x)) sage: r = 4.77 - sage: implicit_plot3d(F, (x,-r,r), (y,-r,r), (z,-r,r), plot_points=40, color='darkkhaki').show(viewer='tachyon') + sage: implicit_plot3d(F, (x,-r,r), (y,-r,r), (z,-r,r), + ....: plot_points=40, color='darkkhaki').show(viewer='tachyon') .. PLOT:: @@ -87,7 +91,8 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): sage: F = (x^2+9/4*y^2+z^2-1)^3 - x^2*z^3 - 9/(80)*y^2*z^3 sage: r = 1.5 - sage: V = implicit_plot3d(F, (x,-r,r), (y,-r,r), (z,-r,r), plot_points=80, color='red', smooth=False) + sage: V = implicit_plot3d(F, (x,-r,r), (y,-r,r), (z,-r,r), + ....: plot_points=80, color='red', smooth=False) sage: V.show(viewer='tachyon') # long time .. PLOT:: @@ -101,13 +106,16 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): The same examples also work with the default Jmol viewer; for example:: sage: T = RDF(golden_ratio) - sage: F = 2 - (cos(x + T*y) + cos(x - T*y) + cos(y + T*z) + cos(y - T*z) + cos(z - T*x) + cos(z + T*x)) + sage: F = 2 - (cos(x + T*y) + cos(x - T*y) + cos(y + T*z) + ....: + cos(y - T*z) + cos(z - T*x) + cos(z + T*x)) sage: r = 4.77 - sage: implicit_plot3d(F, (x,-r,r), (y,-r,r), (z,-r,r), plot_points=40, color='deepskyblue').show() + sage: implicit_plot3d(F, (x,-r,r), (y,-r,r), (z,-r,r), + ....: plot_points=40, color='deepskyblue').show() - Here we use smooth=True with a Tachyon graph:: + Here we use ``smooth=True`` with a Tachyon graph:: - sage: implicit_plot3d(x^2 + y^2 + z^2, (x,-2,2), (y,-2,2), (z,-2,2), contour=4, color='deepskyblue', smooth=True) + sage: implicit_plot3d(x^2 + y^2 + z^2, (x,-2,2), (y,-2,2), (z,-2,2), + ....: contour=4, color='deepskyblue', smooth=True) Graphics3d Object .. PLOT:: @@ -117,14 +125,15 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): P = implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), contour=4, color='deepskyblue', smooth=True) sphinx_plot(P) - We explicitly specify a gradient function (in conjunction with smooth=True) + We explicitly specify a gradient function (in conjunction with ``smooth=True``) and invert the normals:: sage: gx = lambda x, y, z: -(2*x + y^2 + z^2) sage: gy = lambda x, y, z: -(x^2 + 2*y + z^2) sage: gz = lambda x, y, z: -(x^2 + y^2 + 2*z) - sage: implicit_plot3d(x^2+y^2+z^2, (x,-2,2), (y,-2,2), (z,-2,2), contour=4, - ....: plot_points=40, smooth=True, gradient=(gx, gy, gz)).show(viewer='tachyon') + sage: implicit_plot3d(x^2+y^2+z^2, (x,-2,2), (y,-2,2), (z,-2,2), + ....: contour=4, plot_points=40, smooth=True, + ....: gradient=(gx, gy, gz)).show(viewer='tachyon') .. PLOT:: @@ -138,8 +147,11 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): A graph of two metaballs interacting with each other:: - sage: def metaball(x0, y0, z0): return 1 / ((x-x0)^2+(y-y0)^2+(z-z0)^2) - sage: implicit_plot3d(metaball(-0.6,0,0) + metaball(0.6,0,0), (x,-2,2), (y,-2,2), (z,-2,2), plot_points=60, contour=2, color='seagreen') + sage: def metaball(x0, y0, z0): + ....: return 1 / ((x-x0)^2+(y-y0)^2+(z-z0)^2) + sage: implicit_plot3d(metaball(-0.6,0,0) + metaball(0.6,0,0), + ....: (x,-2,2), (y,-2,2), (z,-2,2), + ....: plot_points=60, contour=2, color='seagreen') Graphics3d Object .. PLOT:: @@ -151,7 +163,7 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) One can also color the surface using a coloring function and a colormap as follows. Note that the coloring function must take - values in the interval [0,1]. :: + values in the interval `[0,1]`. :: sage: t = (sin(3*z)**2).function(x,y,z) sage: cm = colormaps.gist_rainbow @@ -173,8 +185,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) sage: x, y, z = var('x,y,z') sage: t = (x).function(x,y,z) sage: cm = colormaps.PiYG - sage: G = implicit_plot3d(x^4 + y^2 + z^2, (x,-2,2), - ....: (y,-2,2),(z,-2,2), contour=4, color=(t,cm), plot_points=40) + sage: G = implicit_plot3d(x^4 + y^2 + z^2, (x,-2,2), (y,-2,2),(z,-2,2), + ....: contour=4, color=(t,cm), plot_points=40) sage: G Graphics3d Object @@ -191,7 +203,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) A kind of saddle:: - sage: implicit_plot3d(x^3 + y^2 - z^2, (x,-2,2), (y,-2,2), (z,-2,2), plot_points=60, contour=0, color='lightcoral') + sage: implicit_plot3d(x^3 + y^2 - z^2, (x,-2,2), (y,-2,2), (z,-2,2), + ....: plot_points=60, contour=0, color='lightcoral') Graphics3d Object .. PLOT:: @@ -202,7 +215,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) A smooth surface with six radial openings:: - sage: implicit_plot3d(-(cos(x) + cos(y) + cos(z)), (x,-4,4), (y,-4,4), (z,-4,4), color='orchid') + sage: implicit_plot3d(-(cos(x) + cos(y) + cos(z)), + ....: (x,-4,4), (y,-4,4), (z,-4,4), color='orchid') Graphics3d Object .. PLOT:: @@ -267,7 +281,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Drope:: - sage: implicit_plot3d(z - 4*x*exp(-x^2-y^2), (x,-2,2), (y,-2,2), (z,-1.7,1.7), color='darkcyan') + sage: implicit_plot3d(z - 4*x*exp(-x^2-y^2), (x,-2,2), (y,-2,2), (z,-1.7,1.7), + ....: color='darkcyan') Graphics3d Object .. PLOT:: @@ -291,7 +306,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) A simple hyperbolic surface:: - sage: implicit_plot3d(x^2 + y - z^2, (x,-1,1), (y,-1,1), (z,-1,1), color='darkslategray') + sage: implicit_plot3d(x^2 + y - z^2, (x,-1,1), (y,-1,1), (z,-1,1), + ....: color='darkslategray') Graphics3d Object .. PLOT:: @@ -302,7 +318,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) A hyperboloid:: - sage: implicit_plot3d(x^2 + y^2 - z^2 -0.3, (x,-2,2), (y,-2,2), (z,-1.8,1.8), color='honeydew') + sage: implicit_plot3d(x^2 + y^2 - z^2 -0.3, (x,-2,2), (y,-2,2), (z,-1.8,1.8), + ....: color='honeydew') Graphics3d Object .. PLOT:: @@ -313,7 +330,7 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Dupin cyclide (:wikipedia:`Dupin_cyclide`) :: - sage: x, y, z , a, b, c, d = var('x,y,z,a,b,c,d') + sage: x, y, z, a, b, c, d = var('x,y,z,a,b,c,d') sage: a = 3.5 sage: b = 3 sage: c = sqrt(a^2 - b^2) @@ -335,7 +352,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Sinus:: - sage: implicit_plot3d(sin(pi*((x)^2+(y)^2))/2 + z, (x,-1,1), (y,-1,1), (z,-1,1), color='rosybrown') + sage: implicit_plot3d(sin(pi*((x)^2+(y)^2))/2 + z, (x,-1,1), (y,-1,1), (z,-1,1), + ....: color='rosybrown') Graphics3d Object .. PLOT:: @@ -346,7 +364,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) A torus:: - sage: implicit_plot3d((sqrt(x*x+y*y)-3)^2 + z*z - 1, (x,-4,4), (y,-4,4), (z,-1,1), color='indigo') + sage: implicit_plot3d((sqrt(x*x+y*y)-3)^2 + z*z - 1, (x,-4,4), (y,-4,4), (z,-1,1), + ....: color='indigo') Graphics3d Object .. PLOT:: @@ -357,7 +376,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) An octahedron:: - sage: implicit_plot3d(abs(x) + abs(y) + abs(z) - 1, (x,-1,1), (y,-1,1), (z,-1,1), color='olive') + sage: implicit_plot3d(abs(x) + abs(y) + abs(z) - 1, (x,-1,1), (y,-1,1), (z,-1,1), + ....: color='olive') Graphics3d Object .. PLOT:: @@ -368,7 +388,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) A cube:: - sage: implicit_plot3d(x^100 + y^100 + z^100 - 1, (x,-2,2), (y,-2,2), (z,-2,2), color='lightseagreen') + sage: implicit_plot3d(x^100 + y^100 + z^100 - 1, (x,-2,2), (y,-2,2), (z,-2,2), + ....: color='lightseagreen') Graphics3d Object .. PLOT:: @@ -379,7 +400,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Toupie:: - sage: implicit_plot3d((sqrt(x*x+y*y)-3)^3 + z*z - 1, (x,-4,4), (y,-4,4), (z,-6,6), color='mintcream') + sage: implicit_plot3d((sqrt(x*x+y*y)-3)^3 + z*z - 1, (x,-4,4), (y,-4,4), (z,-6,6), + ....: color='mintcream') Graphics3d Object .. PLOT:: @@ -404,7 +426,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Chmutov:: sage: F = x^4 + y^4 + z^4 - (x^2 + y^2 + z^2 - 0.3) - sage: implicit_plot3d(F, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1.5,1.5), color='lightskyblue') + sage: implicit_plot3d(F, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1.5,1.5), + ....: color='lightskyblue') Graphics3d Object .. PLOT:: @@ -417,7 +440,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Further Chmutov:: sage: F = 2*(x^2*(3-4*x^2)^2+y^2*(3-4*y^2)^2+z^2*(3-4*z^2)^2) - 3 - sage: implicit_plot3d(F, (x,-1.3,1.3), (y,-1.3,1.3), (z,-1.3,1.3), color='darksalmon') + sage: implicit_plot3d(F, (x,-1.3,1.3), (y,-1.3,1.3), (z,-1.3,1.3), + ....: color='darksalmon') Graphics3d Object .. PLOT:: @@ -454,7 +478,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Looks like a water droplet:: - sage: implicit_plot3d(x^2 +y^2 -(1-z)*z^2, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1,1), color='bisque') + sage: implicit_plot3d(x^2 + y^2 - (1-z)*z^2, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1,1), + ....: color='bisque') Graphics3d Object .. PLOT:: @@ -466,7 +491,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Sphere in a cage:: sage: F = (x^8+z^30+y^8-(x^4 + z^50 + y^4 -0.3)) * (x^2+y^2+z^2-0.5) - sage: implicit_plot3d(F, (x,-1.2,1.2), (y,-1.3,1.3), (z,-1.5,1.5), color='firebrick') + sage: implicit_plot3d(F, (x,-1.2,1.2), (y,-1.3,1.3), (z,-1.5,1.5), + ....: color='firebrick') Graphics3d Object .. PLOT:: @@ -478,8 +504,10 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Ortho circle:: - sage: F = ((x^2+y^2-1)^2+z^2) * ((y^2+z^2-1)^2+x^2) * ((z^2+x^2-1)^2+y^2)-0.075^2 * (1+3*(x^2+y^2+z^2)) - sage: implicit_plot3d(F, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1.5,1.5), color='lemonchiffon') + sage: F = (((x^2+y^2-1)^2+z^2) * ((y^2+z^2-1)^2+x^2) * ((z^2+x^2-1)^2+y^2) + ....: - 0.075^2 * (1+3*(x^2+y^2+z^2))) + sage: implicit_plot3d(F, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1.5,1.5), + ....: color='lemonchiffon') Graphics3d Object .. PLOT:: @@ -504,7 +532,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Two cylinders intersect to make a cross:: - sage: implicit_plot3d((x^2+y^2-1) * (x^2+z^2-1) - 1, (x,-3,3), (y,-3,3), (z,-3,3), color='burlywood') + sage: implicit_plot3d((x^2+y^2-1) * (x^2+z^2-1) - 1, (x,-3,3), (y,-3,3), (z,-3,3), + ....: color='burlywood') Graphics3d Object .. PLOT:: @@ -515,7 +544,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Three cylinders intersect in a similar fashion:: - sage: implicit_plot3d((x^2+y^2-1) * (x^2+z^2-1) * (y^2+z^2-1)-1, (x,-3,3), (y,-3,3), (z,-3,3), color='aqua') + sage: implicit_plot3d((x^2+y^2-1) * (x^2+z^2-1) * (y^2+z^2-1) - 1, + ....: (x,-3,3), (y,-3,3), (z,-3,3), color='aqua') Graphics3d Object .. PLOT:: @@ -526,7 +556,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) A sphere-ish object with twelve holes, four on each XYZ plane:: - sage: implicit_plot3d(3*(cos(x)+cos(y)+cos(z)) + 4*cos(x)*cos(y)*cos(z), (x,-3,3), (y,-3,3), (z,-3,3), color='orangered') + sage: implicit_plot3d(3*(cos(x)+cos(y)+cos(z)) + 4*cos(x)*cos(y)*cos(z), + ....: (x,-3,3), (y,-3,3), (z,-3,3), color='orangered') Graphics3d Object .. PLOT:: @@ -537,7 +568,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) A gyroid:: - sage: implicit_plot3d(cos(x)*sin(y) + cos(y)*sin(z) + cos(z)*sin(x), (x,-4,4), (y,-4,4), (z,-4,4), color='sandybrown') + sage: implicit_plot3d(cos(x)*sin(y) + cos(y)*sin(z) + cos(z)*sin(x), + ....: (x,-4,4), (y,-4,4), (z,-4,4), color='sandybrown') Graphics3d Object .. PLOT:: @@ -548,7 +580,8 @@ def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) Tetrahedra:: - sage: implicit_plot3d((x^2+y^2+z^2)^2 + 8*x*y*z - 10*(x^2+y^2+z^2) + 25, (x,-4,4), (y,-4,4), (z,-4,4), color='plum') + sage: implicit_plot3d((x^2+y^2+z^2)^2 + 8*x*y*z - 10*(x^2+y^2+z^2) + 25, + ....: (x,-4,4), (y,-4,4), (z,-4,4), color='plum') Graphics3d Object .. PLOT:: diff --git a/src/sage/plot/plot3d/implicit_surface.pyx b/src/sage/plot/plot3d/implicit_surface.pyx index cc3b1634c8c..8981b9e2bc7 100644 --- a/src/sage/plot/plot3d/implicit_surface.pyx +++ b/src/sage/plot/plot3d/implicit_surface.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic r""" Graphics 3D object for representing and triangulating isosurfaces diff --git a/src/sage/plot/plot3d/index_face_set.pyx b/src/sage/plot/plot3d/index_face_set.pyx index d7d5e508f2a..de30b24c0fd 100644 --- a/src/sage/plot/plot3d/index_face_set.pyx +++ b/src/sage/plot/plot3d/index_face_set.pyx @@ -248,7 +248,8 @@ def cut_edge_by_bisection(pointa, pointb, condition, eps=1.0e-6, N=100): EXAMPLES:: sage: from sage.plot.plot3d.index_face_set import cut_edge_by_bisection - sage: cut_edge_by_bisection((0.0,0.0,0.0),(1.0,1.0,0.0),( (lambda x,y,z: x**2+y**2+z**2<1) ),eps=1.0E-12) + sage: cut_edge_by_bisection((0.0,0.0,0.0), (1.0,1.0,0.0), + ....: lambda x,y,z: x**2+y**2+z**2 < 1, eps=1.0E-12) (0.7071067811864395, 0.7071067811864395, 0.0) """ cdef point_c a, b @@ -302,9 +303,10 @@ cdef class IndexFaceSet(PrimitiveObject): EXAMPLES:: sage: from sage.plot.plot3d.index_face_set import IndexFaceSet - sage: S = IndexFaceSet([[(1,0,0),(0,1,0),(0,0,1)],[(1,0,0),(0,1,0),(0,0,0)]]) + sage: S = IndexFaceSet([[(1,0,0),(0,1,0),(0,0,1)], [(1,0,0),(0,1,0),(0,0,0)]]) sage: S.face_list() - [[(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)], [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 0.0)]] + [[(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)], + [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 0.0)]] sage: S.vertex_list() [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0), (0.0, 0.0, 0.0)] @@ -317,13 +319,13 @@ cdef class IndexFaceSet(PrimitiveObject): sage: S = IndexFaceSet(face_list, point_list, color='red') sage: S.face_list() [[(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 0.0)], - [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)], - [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 2.0)], - [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 3.0)], - [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 4.0)], - [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 5.0)], - [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 6.0)], - [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 7.0)]] + [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)], + [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 2.0)], + [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 3.0)], + [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 4.0)], + [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 5.0)], + [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 6.0)], + [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 7.0)]] sage: S.show() A simple example of colored IndexFaceSet (:trac:`12212`):: @@ -698,13 +700,13 @@ cdef class IndexFaceSet(PrimitiveObject): sage: point_list = [(2,0,0),(0,2,0),(0,0,2),(0,1,1),(1,0,1),(1,1,0)] sage: face_list = [[0,4,5],[3,4,5],[2,3,4],[1,3,5]] sage: col = rainbow(10, 'rgbtuple') - sage: t_list=[Texture(col[i]) for i in range(10)] + sage: t_list = [Texture(col[i]) for i in range(10)] sage: S = IndexFaceSet(face_list, point_list, texture_list=t_list) sage: S.index_faces_with_colors() [([0, 4, 5], '#ff0000'), - ([3, 4, 5], '#ff9900'), - ([2, 3, 4], '#cbff00'), - ([1, 3, 5], '#33ff00')] + ([3, 4, 5], '#ff9900'), + ([2, 3, 4], '#cbff00'), + ([1, 3, 5], '#33ff00')] When the texture is global, an error is raised:: @@ -847,7 +849,7 @@ cdef class IndexFaceSet(PrimitiveObject): sage: point_list = [(2,0,0),(0,2,0),(0,0,2),(0,1,1),(1,0,1),(1,1,0)] sage: face_list = [[0,4,5],[3,4,5],[2,3,4],[1,3,5]] sage: col = rainbow(10, 'rgbtuple') - sage: t_list=[Texture(col[i]) for i in range(10)] + sage: t_list = [Texture(col[i]) for i in range(10)] sage: S = IndexFaceSet(face_list, point_list, texture_list=t_list) sage: print(S.x3d_geometry()) @@ -931,7 +933,7 @@ cdef class IndexFaceSet(PrimitiveObject): sage: from sage.plot.plot3d.shapes import * sage: S = Box(1,2,3) - sage: len(S.partition(lambda x,y,z : floor(x+y+z))) + sage: len(S.partition(lambda x,y,z: floor(x+y+z))) 6 """ cdef Py_ssize_t i, j, ix, face_ix @@ -1028,7 +1030,8 @@ cdef class IndexFaceSet(PrimitiveObject): ....: return bool(x*x+y*y <= 1.1) sage: cm = colormaps.hsv sage: cf = lambda x,y,z: float(x+y) % 1 - sage: P = implicit_plot3d(x**2+y**2+z**2-1-x**2*z+y**2*z,(-2,2),(-2,2),(-2,2),color=(cm,cf)) + sage: P = implicit_plot3d(x**2+y**2+z**2-1-x**2*z+y**2*z, + ....: (-2,2),(-2,2),(-2,2),color=(cm,cf)) sage: R = P.add_condition(condi,40); R Graphics3d Object @@ -1044,7 +1047,8 @@ cdef class IndexFaceSet(PrimitiveObject): An example with transparency:: - sage: P = implicit_plot3d(x**4+y**4+z**2-4,(x,-2,2),(y,-2,2),(z,-2,2),alpha=0.3) + sage: P = implicit_plot3d(x**4+y**4+z**2-4, (x,-2,2), (y,-2,2), (z,-2,2), + ....: alpha=0.3) sage: def cut(a,b,c): ....: return a*a+c*c > 2 sage: Q = P.add_condition(cut,40); Q @@ -1060,8 +1064,8 @@ cdef class IndexFaceSet(PrimitiveObject): A sombrero with quadrilaterals:: - sage: P = plot3d(-sin(2*x*x+2*y*y)*exp(-x*x-y*y),(x,-2,2),(y,-2,2), - ....: color='gold') + sage: P = plot3d(-sin(2*x*x+2*y*y)*exp(-x*x-y*y), (x,-2,2), (y,-2,2), + ....: color='gold') sage: def cut(x,y,z): ....: return x*x+y*y < 1 sage: Q = P.add_condition(cut);Q @@ -1214,7 +1218,7 @@ cdef class IndexFaceSet(PrimitiveObject): sage: point_list = [(2,0,0),(0,2,0),(0,0,2),(0,1,1),(1,0,1),(1,1,0)] sage: face_list = [[0,4,5],[3,4,5],[2,3,4],[1,3,5]] sage: col = rainbow(10, 'rgbtuple') - sage: t_list=[Texture(col[i]) for i in range(10)] + sage: t_list = [Texture(col[i]) for i in range(10)] sage: S = IndexFaceSet(face_list, point_list, texture_list=t_list) sage: S.tachyon_repr(S.default_render_params()) ['TRI V0 2 0 0 V1 1 0 1 V2 1 1 0', diff --git a/src/sage/plot/plot3d/list_plot3d.py b/src/sage/plot/plot3d/list_plot3d.py index 0158f856dbb..6a589b8b381 100644 --- a/src/sage/plot/plot3d/list_plot3d.py +++ b/src/sage/plot/plot3d/list_plot3d.py @@ -72,8 +72,9 @@ def list_plot3d(v, interpolation_type='default', point_list=None, **kwds): We plot a matrix of values of ``sin``:: - sage: pi = float(pi) - sage: m = matrix(RDF, 6, [sin(i^2 + j^2) for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) + sage: from math import pi + sage: m = matrix(RDF, 6, [sin(i^2 + j^2) + ....: for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) sage: list_plot3d(m, color='yellow', frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object @@ -85,9 +86,10 @@ def list_plot3d(v, interpolation_type='default', point_list=None, **kwds): sphinx_plot(list_plot3d(m, color='yellow', frame_aspect_ratio=[1, 1, 1/3])) Though it does not change the shape of the graph, increasing - num_points can increase the clarity of the graph:: + ``num_points`` can increase the clarity of the graph:: - sage: list_plot3d(m, color='yellow', frame_aspect_ratio=[1, 1, 1/3], num_points=40) + sage: list_plot3d(m, color='yellow', num_points=40, + ....: frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object .. PLOT:: @@ -101,7 +103,8 @@ def list_plot3d(v, interpolation_type='default', point_list=None, **kwds): sage: import warnings sage: warnings.simplefilter('ignore', UserWarning) - sage: list_plot3d(m, color='yellow', interpolation_type='clough', frame_aspect_ratio=[1, 1, 1/3]) + sage: list_plot3d(m, color='yellow', interpolation_type='clough', + ....: frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object .. PLOT:: @@ -115,7 +118,8 @@ def list_plot3d(v, interpolation_type='default', point_list=None, **kwds): We can make this look better by increasing the number of samples:: - sage: list_plot3d(m, color='yellow', interpolation_type='clough', frame_aspect_ratio=[1, 1, 1/3], num_points=40) + sage: list_plot3d(m, color='yellow', interpolation_type='clough', + ....: frame_aspect_ratio=[1, 1, 1/3], num_points=40) Graphics3d Object .. PLOT:: @@ -127,7 +131,8 @@ def list_plot3d(v, interpolation_type='default', point_list=None, **kwds): Let us try a spline:: - sage: list_plot3d(m, color='yellow', interpolation_type='spline', frame_aspect_ratio=[1, 1, 1/3]) + sage: list_plot3d(m, color='yellow', interpolation_type='spline', + ....: frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object .. PLOT:: @@ -140,7 +145,8 @@ def list_plot3d(v, interpolation_type='default', point_list=None, **kwds): That spline does not capture the oscillation very well; let's try a higher degree spline:: - sage: list_plot3d(m, color='yellow', interpolation_type='spline', degree=5, frame_aspect_ratio=[1, 1, 1/3]) + sage: list_plot3d(m, color='yellow', interpolation_type='spline', degree=5, + ....: frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object .. PLOT:: @@ -185,8 +191,11 @@ def list_plot3d(v, interpolation_type='default', point_list=None, **kwds): sage: l = [] sage: for i in range(-5, 5): ....: for j in range(-5, 5): - ....: l.append((normalvariate(0, 1), normalvariate(0, 1), normalvariate(0, 1))) - sage: L = list_plot3d(l, interpolation_type='clough', color='orange', num_points=100) + ....: l.append((normalvariate(0, 1), + ....: normalvariate(0, 1), + ....: normalvariate(0, 1))) + sage: L = list_plot3d(l, interpolation_type='clough', + ....: color='orange', num_points=100) sage: L Graphics3d Object @@ -308,7 +317,8 @@ def list_plot3d_matrix(m, **kwds): We plot a matrix that illustrates summation modulo `n`:: sage: n = 5 - sage: list_plot3d(matrix(RDF, n, [(i+j)%n for i in [1..n] for j in [1..n]])) # indirect doctest + sage: list_plot3d(matrix(RDF, n, [(i+j) % n # indirect doctest + ....: for i in [1..n] for j in [1..n]])) Graphics3d Object .. PLOT:: @@ -320,9 +330,10 @@ def list_plot3d_matrix(m, **kwds): We plot a matrix of values of `sin`:: - sage: pi = float(pi) - sage: m = matrix(RDF, 6, [sin(i^2 + j^2) for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) - sage: list_plot3d(m, color='yellow', frame_aspect_ratio=[1, 1, 1/3]) # indirect doctest + sage: from math import pi + sage: m = matrix(RDF, 6, [sin(i^2 + j^2) + ....: for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) + sage: list_plot3d(m, color='yellow', frame_aspect_ratio=[1, 1, 1/3]) # indirect doctest Graphics3d Object .. PLOT:: @@ -333,7 +344,7 @@ def list_plot3d_matrix(m, **kwds): sphinx_plot(list_plot3d(m, color='yellow', frame_aspect_ratio=[1, 1, 1/3])) :: - sage: list_plot3d(m, color='yellow', interpolation_type='linear') # indirect doctest + sage: list_plot3d(m, color='yellow', interpolation_type='linear') # indirect doctest Graphics3d Object .. PLOT:: @@ -350,7 +361,7 @@ def list_plot3d_matrix(m, **kwds): sage: n = 20 sage: cf = lambda x, y: ((2*(x-y)/n)**2) % 1 sage: list_plot3d(matrix(RDF, n, [cos(pi*(i+j)/n) for i in [1..n] - ....: for j in [1..n]]), color=(cf,cm)) + ....: for j in [1..n]]), color=(cf,cm)) Graphics3d Object .. PLOT:: @@ -412,7 +423,8 @@ def list_plot3d_array_of_arrays(v, interpolation_type, **kwds): With certain extra keywords (see :func:`list_plot3d_matrix`), this function will end up using :func:`list_plot3d_tuples`:: - sage: show(list_plot3d([[1, 1, 1, 1], [1, 2, 1, 2], [1, 1, 3, 1], [1, 2, 1, 4]], interpolation_type='spline')) + sage: show(list_plot3d([[1, 1, 1, 1], [1, 2, 1, 2], [1, 1, 3, 1], [1, 2, 1, 4]], + ....: interpolation_type='spline')) .. PLOT:: @@ -431,14 +443,14 @@ def list_plot3d_tuples(v, interpolation_type, **kwds): INPUT: - - ``v`` - something that defines a set of points in 3 + - ``v`` -- something that defines a set of points in 3 space, for example: - a matrix - This will be if using an interpolation type other than - 'linear', or if using ``num_points`` with 'linear'; otherwise - see :func:`list_plot3d_matrix`. + This will be if using an ``interpolation_type`` other than + ``'linear'``, or if using ``num_points`` with ``'linear'``; + otherwise see :func:`list_plot3d_matrix`. - a list of 3-tuples @@ -447,33 +459,34 @@ def list_plot3d_tuples(v, interpolation_type, **kwds): OPTIONAL KEYWORDS: - - ``interpolation_type`` - 'linear', 'clough' (CloughTocher2D), 'spline' + - ``interpolation_type`` -- one of ``'linear'``, ``'clough'`` + (CloughTocher2D), ``'spline'`` - 'linear' will perform linear interpolation + ``'linear'`` will perform linear interpolation The option 'clough' will interpolate by using a piecewise cubic interpolating Bezier polynomial on each triangle, using a Clough-Tocher scheme. The interpolant is guaranteed to be continuously differentiable. - The option 'spline' interpolates using a bivariate B-spline. + The option ``'spline'`` interpolates using a bivariate B-spline. - When v is a matrix the default is to use linear interpolation, when - v is a list of points the default is 'clough'. + When ``v`` is a matrix the default is to use linear interpolation, when + ``v`` is a list of points the default is ``'clough'``. - - ``degree`` - an integer between 1 and 5, controls the degree of spline + - ``degree`` -- an integer between 1 and 5, controls the degree of spline used for spline interpolation. For data that is highly oscillatory use higher values - - ``point_list`` - If point_list=True is passed, then if the array + - ``point_list`` -- If ``point_list=True`` is passed, then if the array is a list of lists of length three, it will be treated as an array of points rather than a `3\times n` array. - - ``num_points`` - Number of points to sample interpolating + - ``num_points`` -- Number of points to sample interpolating function in each direction. By default for an `n\times n` array this is `n`. - - ``**kwds`` - all other arguments are passed to the + - ``**kwds`` -- all other arguments are passed to the surface function OUTPUT: a 3d plot @@ -483,9 +496,11 @@ def list_plot3d_tuples(v, interpolation_type, **kwds): All of these use this function; see :func:`list_plot3d` for other list plots:: - sage: pi = float(pi) - sage: m = matrix(RDF, 6, [sin(i^2 + j^2) for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) - sage: list_plot3d(m, color='yellow', interpolation_type='linear', num_points=5) # indirect doctest + sage: from math import pi + sage: m = matrix(RDF, 6, [sin(i^2 + j^2) + ....: for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) + sage: list_plot3d(m, color='yellow', interpolation_type='linear', # indirect doctest + ....: num_points=5) Graphics3d Object .. PLOT:: @@ -497,7 +512,8 @@ def list_plot3d_tuples(v, interpolation_type, **kwds): :: - sage: list_plot3d(m, color='yellow', interpolation_type='spline', frame_aspect_ratio=[1, 1, 1/3]) + sage: list_plot3d(m, color='yellow', interpolation_type='spline', + ....: frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object .. PLOT:: @@ -509,15 +525,18 @@ def list_plot3d_tuples(v, interpolation_type, **kwds): :: - sage: show(list_plot3d([[1, 1, 1], [1, 2, 1], [0, 1, 3], [1, 0, 4]], point_list=True)) + sage: show(list_plot3d([[1, 1, 1], [1, 2, 1], [0, 1, 3], [1, 0, 4]], + ....: point_list=True)) .. PLOT:: - sphinx_plot(list_plot3d([[1, 1, 1], [1, 2, 1], [0, 1, 3], [1, 0, 4]], point_list=True)) + sphinx_plot(list_plot3d([[1, 1, 1], [1, 2, 1], [0, 1, 3], [1, 0, 4]], + ....: point_list=True)) :: - sage: list_plot3d([(1, 2, 3), (0, 1, 3), (2, 1, 4), (1, 0, -2)], color='yellow', num_points=50) # long time + sage: list_plot3d([(1, 2, 3), (0, 1, 3), (2, 1, 4), (1, 0, -2)], # long time + ....: color='yellow', num_points=50) Graphics3d Object .. PLOT:: diff --git a/src/sage/plot/plot3d/plot3d.py b/src/sage/plot/plot3d/plot3d.py index 7b45d9b98c1..86cb4b7bafb 100644 --- a/src/sage/plot/plot3d/plot3d.py +++ b/src/sage/plot/plot3d/plot3d.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic r""" Plotting functions diff --git a/src/sage/plot/plot3d/plot_field3d.py b/src/sage/plot/plot3d/plot_field3d.py index fe10e27f58f..2af26bf9c5d 100644 --- a/src/sage/plot/plot3d/plot_field3d.py +++ b/src/sage/plot/plot3d/plot_field3d.py @@ -1,3 +1,4 @@ +# optional - sage.symbolic """ Plotting 3D fields """ @@ -29,32 +30,33 @@ def plot_vector_field3d(functions, xrange, yrange, zrange, INPUT: - - ``functions`` - a list of three functions, representing the x-, + - ``functions`` -- a list of three functions, representing the x-, y-, and z-coordinates of a vector - - ``xrange``, ``yrange``, and ``zrange`` - three tuples of the + - ``xrange``, ``yrange``, and ``zrange`` -- three tuples of the form (var, start, stop), giving the variables and ranges for each axis - - ``plot_points`` (default 5) - either a number or list of three + - ``plot_points`` -- (default 5) either a number or list of three numbers, specifying how many points to plot for each axis - - ``colors`` (default 'jet') - a color, list of colors (which are + - ``colors`` -- (default ``'jet'``) a color, list of colors (which are interpolated between), or matplotlib colormap name, giving the coloring of the arrows. If a list of colors or a colormap is given, coloring is done as a function of length of the vector - - ``center_arrows`` (default False) - If True, draw the arrows + - ``center_arrows`` -- (default ``False``) If ``True``, draw the arrows centered on the points; otherwise, draw the arrows with the tail at the point - - any other keywords are passed on to the plot command for each arrow + - any other keywords are passed on to the :func:`plot` command for each arrow EXAMPLES: A 3d vector field:: - sage: x,y,z=var('x y z') - sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi)) + sage: x,y,z = var('x y z') + sage: plot_vector_field3d((x*cos(z), -y*cos(z), sin(z)), + ....: (x,0,pi), (y,0,pi), (z,0,pi)) Graphics3d Object .. PLOT:: @@ -64,7 +66,9 @@ def plot_vector_field3d(functions, xrange, yrange, zrange, same example with only a list of colors:: - sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),colors=['red','green','blue']) + sage: plot_vector_field3d((x*cos(z), -y*cos(z), sin(z)), + ....: (x,0,pi), (y,0,pi), (z,0,pi), + ....: colors=['red','green','blue']) Graphics3d Object .. PLOT:: @@ -74,7 +78,8 @@ def plot_vector_field3d(functions, xrange, yrange, zrange, same example with only one color:: - sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),colors='red') + sage: plot_vector_field3d((x*cos(z), -y*cos(z), sin(z)), + ....: (x,0,pi), (y,0,pi), (z,0,pi), colors='red') Graphics3d Object .. PLOT:: @@ -84,7 +89,8 @@ def plot_vector_field3d(functions, xrange, yrange, zrange, same example with the same plot points for the three axes:: - sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),plot_points=4) + sage: plot_vector_field3d((x*cos(z), -y*cos(z), sin(z)), + ....: (x,0,pi), (y,0,pi), (z,0,pi), plot_points=4) Graphics3d Object .. PLOT:: @@ -94,7 +100,8 @@ def plot_vector_field3d(functions, xrange, yrange, zrange, same example with different number of plot points for each axis:: - 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]) + 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]) Graphics3d Object .. PLOT:: @@ -104,7 +111,8 @@ def plot_vector_field3d(functions, xrange, yrange, zrange, same example with the arrows centered on the points:: - sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),center_arrows=True) + sage: plot_vector_field3d((x*cos(z), -y*cos(z), sin(z)), + ....: (x,0,pi), (y,0,pi), (z,0,pi), center_arrows=True) Graphics3d Object .. PLOT:: diff --git a/src/sage/plot/plot3d/revolution_plot3d.py b/src/sage/plot/plot3d/revolution_plot3d.py index 7c570b985f3..c99e7566688 100644 --- a/src/sage/plot/plot3d/revolution_plot3d.py +++ b/src/sage/plot/plot3d/revolution_plot3d.py @@ -39,25 +39,25 @@ def revolution_plot3d(curve,trange,phirange=None,parallel_axis='z',axis=(0,0),pr INPUT: - - ``curve`` - A curve to be revolved, specified as a function, a 2-tuple or a 3-tuple. + - ``curve`` -- A curve to be revolved, specified as a function, a 2-tuple or a 3-tuple. - - ``trange`` - A 3-tuple `(t,t_{\min},t_{\max})` where t is the independent variable of the curve. + - ``trange`` -- A 3-tuple `(t,t_{\min},t_{\max})` where t is the independent variable of the curve. - - ``phirange`` - A 2-tuple of the form `(\phi_{\min},\phi_{\max})`, (default `(0,\pi)`) that specifies the angle in which the curve is to be revolved. + - ``phirange`` -- A 2-tuple of the form `(\phi_{\min},\phi_{\max})`, (default `(0,\pi)`) that specifies the angle in which the curve is to be revolved. - - ``parallel_axis`` - A string (Either 'x', 'y', or 'z') that specifies the coordinate axis parallel to the revolution axis. + - ``parallel_axis`` -- A string (one of ``'x'``, ``'y'``, ``'z'``) that specifies the coordinate axis parallel to the revolution axis. - - ``axis`` - A 2-tuple that specifies the position of the revolution axis. If parallel is: + - ``axis`` -- A 2-tuple that specifies the position of the revolution axis. If ``parallel_axis`` is: - - 'z' - then axis is the point in which the revolution axis intersects the `x y` plane. + - ``'z'`` -- then ``axis`` is the point in which the revolution axis intersects the `x` `y` plane. - - 'x' - then axis is the point in which the revolution axis intersects the `y z` plane. + - ``'x'`` -- then ``axis`` is the point in which the revolution axis intersects the `y` `z` plane. - - 'y' - then axis is the point in which the revolution axis intersects the `x z` plane. + - ``'y'`` -- then ``axis`` is the point in which the revolution axis intersects the `x` `z` plane. - - ``print_vector`` - If True, the parametrization of the surface of revolution will be printed. + - ``print_vector`` -- If ``True``, the parametrization of the surface of revolution will be printed. - - ``show_curve`` - If True, the curve will be displayed. + - ``show_curve`` -- If ``True``, the curve will be displayed. EXAMPLES: @@ -66,7 +66,8 @@ def revolution_plot3d(curve,trange,phirange=None,parallel_axis='z',axis=(0,0),pr sage: u = var('u') sage: f = u^2 - sage: revolution_plot3d(f, (u,0,2), show_curve=True, opacity=0.7).show(aspect_ratio=(1,1,1)) + sage: revolution_plot3d(f, (u,0,2), + ....: show_curve=True, opacity=0.7).show(aspect_ratio=(1,1,1)) .. PLOT:: @@ -77,7 +78,8 @@ def revolution_plot3d(curve,trange,phirange=None,parallel_axis='z',axis=(0,0),pr If we move slightly the axis, we get a goblet-like surface:: - sage: revolution_plot3d(f, (u,0,2), axis=(1,0.2), show_curve=True, opacity=0.5).show(aspect_ratio=(1,1,1)) + sage: revolution_plot3d(f, (u,0,2), axis=(1,0.2), + ....: show_curve=True, opacity=0.5).show(aspect_ratio=(1,1,1)) .. PLOT:: @@ -90,9 +92,11 @@ def revolution_plot3d(curve,trange,phirange=None,parallel_axis='z',axis=(0,0),pr sage: line = u sage: parabola = u^2 - sage: sur1 = revolution_plot3d(line, (u,0,1), opacity=0.5, rgbcolor=(1,0.5,0), show_curve=True, parallel_axis='x') - sage: sur2 = revolution_plot3d(parabola, (u,0,1), opacity=0.5, rgbcolor=(0,1,0), show_curve=True, parallel_axis='x') - sage: (sur1+sur2).show() + sage: sur1 = revolution_plot3d(line, (u,0,1), opacity=0.5, rgbcolor=(1,0.5,0), + ....: show_curve=True, parallel_axis='x') + sage: sur2 = revolution_plot3d(parabola, (u,0,1), opacity=0.5, rgbcolor=(0,1,0), + ....: show_curve=True, parallel_axis='x') + sage: (sur1 + sur2).show() .. PLOT:: @@ -109,7 +113,8 @@ def revolution_plot3d(curve,trange,phirange=None,parallel_axis='z',axis=(0,0),pr sage: u = var('u') sage: circle = (cos(u), sin(u)) - sage: revolution_plot3d(circle, (u,0,2*pi), axis=(0,0), show_curve=True, opacity=0.5).show(aspect_ratio=(1,1,1)) + sage: revolution_plot3d(circle, (u,0,2*pi), axis=(0,0), + ....: show_curve=True, opacity=0.5).show(aspect_ratio=(1,1,1)) .. PLOT:: @@ -120,7 +125,8 @@ def revolution_plot3d(curve,trange,phirange=None,parallel_axis='z',axis=(0,0),pr An axis on `(0,y)` will produce a cylinder-like surface:: - sage: revolution_plot3d(circle, (u,0,2*pi), axis=(0,2), show_curve=True, opacity=0.5).show(aspect_ratio=(1,1,1)) + sage: revolution_plot3d(circle, (u,0,2*pi), axis=(0,2), + ....: show_curve=True, opacity=0.5).show(aspect_ratio=(1,1,1)) .. PLOT:: @@ -131,7 +137,8 @@ def revolution_plot3d(curve,trange,phirange=None,parallel_axis='z',axis=(0,0),pr And any other axis will produce a torus-like surface:: - sage: revolution_plot3d(circle, (u,0,2*pi), axis=(2,0), show_curve=True, opacity=0.5).show(aspect_ratio=(1,1,1)) + sage: revolution_plot3d(circle, (u,0,2*pi), axis=(2,0), + ....: show_curve=True, opacity=0.5).show(aspect_ratio=(1,1,1)) .. PLOT:: @@ -144,7 +151,8 @@ def revolution_plot3d(curve,trange,phirange=None,parallel_axis='z',axis=(0,0),pr sage: u = var('u') sage: curve = (u, cos(4*u), u^2) - sage: P = revolution_plot3d(curve, (u,0,2), show_curve=True, parallel_axis='z',axis=(1,.2), opacity=0.5) + sage: P = revolution_plot3d(curve, (u,0,2), parallel_axis='z', axis=(1,.2), + ....: show_curve=True, opacity=0.5) sage: P.show(aspect_ratio=(1,1,1)) .. PLOT:: @@ -158,7 +166,9 @@ def revolution_plot3d(curve,trange,phirange=None,parallel_axis='z',axis=(0,0),pr sage: u = var('u') sage: curve = (sin(3*u), .8*cos(4*u), cos(u)) - sage: revolution_plot3d(curve, (u,0,pi), (0,pi/2), show_curve=True, parallel_axis='z', opacity=0.5).show(aspect_ratio=(1,1,1),frame=False) + sage: revolution_plot3d(curve, (u,0,pi), (0,pi/2), parallel_axis='z', + ....: show_curve=True, opacity=0.5).show(aspect_ratio=(1,1,1), + ....: frame=False) .. PLOT:: @@ -169,12 +179,13 @@ def revolution_plot3d(curve,trange,phirange=None,parallel_axis='z',axis=(0,0),pr One can also color the surface using a coloring function of two parameters and a colormap as follows. Note that the coloring - function must take values in the interval [0,1]. :: + function must take values in the interval `[0,1]`. :: sage: u, phi = var('u,phi') sage: def cf(u,phi): return sin(phi+u) ^ 2 sage: curve = (1+u^2/4, 0, u) - sage: revolution_plot3d(curve, (u,-2,2), (0,2*pi), parallel_axis='z', color=(cf, colormaps.PiYG)).show(aspect_ratio=(1,1,1)) + sage: revolution_plot3d(curve, (u,-2,2), (0,2*pi), parallel_axis='z', + ....: color=(cf, colormaps.PiYG)).show(aspect_ratio=(1,1,1)) .. PLOT:: @@ -192,8 +203,8 @@ def cf(u, phi): return sin(phi+u) ** 2 sage: u, phi = var('u,phi') sage: def cf(u, phi): return float(2 * u / pi) % 1 sage: curve = (sin(u), 0, u) - sage: revolution_plot3d(curve, (u,0,pi), (0,2*pi), parallel_axis - ....: ='z', color=(colormaps.brg, cf)).show(aspect_ratio=1) + sage: revolution_plot3d(curve, (u,0,pi), (0,2*pi), parallel_axis='z', + ....: color=(colormaps.brg, cf)).show(aspect_ratio=1) .. PLOT:: diff --git a/src/sage/plot/plot3d/shapes.pyx b/src/sage/plot/plot3d/shapes.pyx index 757a718a0df..72a94213359 100644 --- a/src/sage/plot/plot3d/shapes.pyx +++ b/src/sage/plot/plot3d/shapes.pyx @@ -12,8 +12,10 @@ EXAMPLES:: sage: from sage.plot.plot3d.shapes import * sage: S = Sphere(.5, color='yellow') sage: S += Cone(.5, .5, color='red').translate(0,0,.3) - sage: S += Sphere(.1, color='white').translate(.45,-.1,.15) + Sphere(.05, color='black').translate(.51,-.1,.17) - sage: S += Sphere(.1, color='white').translate(.45, .1,.15) + Sphere(.05, color='black').translate(.51, .1,.17) + sage: S += Sphere(.1, color='white').translate(.45,-.1,.15) + sage: S += Sphere(.05, color='black').translate(.51,-.1,.17) + sage: S += Sphere(.1, color='white').translate(.45, .1,.15) + sage: S += Sphere(.05, color='black').translate(.51, .1,.17) sage: S += Sphere(.1, color='yellow').translate(.5, 0, -.2) sage: S.show() sage: S.scale(1,1,2).show() @@ -78,7 +80,7 @@ def validate_frame_size(size): Traceback (most recent call last): ... ValueError: each box dimension must be nonnegative - sage: validate_frame_size([sqrt(-1),3,2]) + sage: validate_frame_size([sqrt(-1),3,2]) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: each box dimension must coerce to a float @@ -125,7 +127,8 @@ class Box(IndexFaceSet): A stack of boxes:: - sage: show(sum([Box([2,3,1], color="red").translate((0,0,6*i)) for i in [0..3]])) + sage: show(sum(Box([2,3,1], color="red").translate((0,0,6*i)) + ....: for i in [0..3])) .. PLOT:: @@ -135,8 +138,10 @@ class Box(IndexFaceSet): A sinusoidal stack of multicolored boxes:: - sage: B = sum([Box([2,4,1/4], color=(i/4,i/5,1)).translate((sin(i),0,5-i)) for i in [0..20]]) - sage: show(B, figsize=6) + sage: B = sum(Box([2,4,1/4], # optional - sage.symbolic + ....: color=(i/4,i/5,1)).translate((sin(i),0,5-i)) + ....: for i in [0..20]) + sage: show(B, figsize=6) # optional - sage.symbolic .. PLOT:: @@ -265,7 +270,8 @@ cdef class Cone(ParametricSurface): EXAMPLES:: sage: from sage.plot.plot3d.shapes import Cone - sage: c = Cone(3/2, 1, color='red') + Cone(1, 2, color='yellow').translate(3, 0, 0) + sage: c = Cone(3/2, 1, color='red') + sage: c += Cone(1, 2, color='yellow').translate(3, 0, 0) sage: c.show(aspect_ratio=1) .. PLOT:: @@ -286,7 +292,8 @@ cdef class Cone(ParametricSurface): A spiky plot of the sine function:: - sage: sum(Cone(.1, sin(n), color='yellow').translate(n, sin(n), 0) for n in [0..10, step=.1]) + sage: sum(Cone(.1, sin(n), color='yellow').translate(n, sin(n), 0) # optional - sage.symbolic + ....: for n in [0..10, step=.1]) Graphics3d Object .. PLOT:: @@ -296,9 +303,11 @@ cdef class Cone(ParametricSurface): A Christmas tree:: - sage: T = sum(Cone(exp(-n/5), 4/3*exp(-n/5), color=(0, .5, 0)).translate(0, 0, -3*exp(-n/5)) for n in [1..7]) - sage: T += Cone(1/8, 1, color='brown').translate(0, 0, -3) - sage: T.show(aspect_ratio=1, frame=False) + sage: T = sum(Cone(exp(-n/5), 4/3*exp(-n/5), # optional - sage.symbolic + ....: color=(0, .5, 0)).translate(0, 0, -3*exp(-n/5)) + ....: for n in [1..7]) + sage: T += Cone(1/8, 1, color='brown').translate(0, 0, -3) # optional - sage.symbolic + sage: T.show(aspect_ratio=1, frame=False) # optional - sage.symbolic .. PLOT:: @@ -376,12 +385,13 @@ cdef class Cylinder(ParametricSurface): - ``closed`` -- whether or not to include the ends (default ``True``) - - ``**kwds`` -- passed to the ParametricSurface constructor + - ``**kwds`` -- passed to the :class:`ParametricSurface` constructor EXAMPLES:: sage: from sage.plot.plot3d.shapes import Cylinder - sage: c = Cylinder(3/2, 1, color='red') + Cylinder(1, 2, color='yellow').translate(3, 0, 0) + sage: c = Cylinder(3/2, 1, color='red') + sage: c += Cylinder(1, 2, color='yellow').translate(3, 0, 0) sage: c.show(aspect_ratio=1) .. PLOT:: @@ -403,10 +413,11 @@ cdef class Cylinder(ParametricSurface): Some gears:: sage: G = Cylinder(1, .5) + Cylinder(.25, 3).translate(0, 0, -3) - sage: G += sum(Cylinder(.2, 1).translate(cos(2*pi*n/9), sin(2*pi*n/9), 0) for n in [1..9]) - sage: G += G.translate(2.3, 0, -.5) - sage: G += G.translate(3.5, 2, -1) - sage: G.show(aspect_ratio=1, frame=False) + sage: G += sum(Cylinder(.2, 1).translate(cos(2*pi*n/9), sin(2*pi*n/9), 0) # optional - sage.symbolic + ....: for n in [1..9]) + sage: G += G.translate(2.3, 0, -.5) # optional - sage.symbolic + sage: G += G.translate(3.5, 2, -1) # optional - sage.symbolic + sage: G.show(aspect_ratio=1, frame=False) # optional - sage.symbolic .. PLOT:: @@ -537,7 +548,8 @@ draw %s width %s {%s %s %s} {%s %s %s}\n%s sage: from sage.plot.plot3d.transform import Transformation sage: Cylinder(1, 5).get_endpoints() ((0, 0, 0), (0, 0, 5.0)) - sage: Cylinder(1, 5).get_endpoints(Transformation(trans=(1,2,3), scale=(2,2,2))) + sage: Cylinder(1, 5).get_endpoints(Transformation(trans=(1,2,3), + ....: scale=(2,2,2))) ((1.0, 2.0, 3.0), (1.0, 2.0, 13.0)) """ if transform is None: @@ -553,7 +565,8 @@ draw %s width %s {%s %s %s} {%s %s %s}\n%s sage: from sage.plot.plot3d.transform import Transformation sage: Cylinder(3, 1).get_radius() 3.0 - sage: Cylinder(3, 1).get_radius(Transformation(trans=(1,2,3), scale=(2,2,2))) + sage: Cylinder(3, 1).get_radius(Transformation(trans=(1,2,3), + ....: scale=(2,2,2))) 6.0 """ if transform is None: @@ -670,12 +683,12 @@ def arrow3d(start, end, width=1, radius=None, head_radius=None, head_len=None, * INPUT: - - start -- (x,y,z) point; the starting point of the arrow - - end -- (x,y,z) point; the end point - - width -- (default: 1); how wide the arrow is - - radius -- (default: width/50.0) the radius of the arrow - - head_radius -- (default: 3*radius); radius of arrow head - - head_len -- (default: 3*head_radius); len of arrow head + - ``start`` -- (x,y,z) point; the starting point of the arrow + - ``end`` -- (x,y,z) point; the end point + - ``width`` -- (default: 1); how wide the arrow is + - ``radius`` -- (default: ``width/50.0``) the radius of the arrow + - ``head_radius`` -- (default: ``3*radius``); radius of arrow head + - ``head_len`` -- (default: ``3*head_radius``); len of arrow head EXAMPLES: @@ -708,7 +721,8 @@ def arrow3d(start, end, width=1, radius=None, head_radius=None, head_len=None, * A fat arrow head:: - sage: arrow3d((2,1,0), (1,1,1), color='green', head_radius=0.3, aspect_ratio=[1,1,1]) + sage: arrow3d((2,1,0), (1,1,1), color='green', head_radius=0.3, + ....: aspect_ratio=[1,1,1]) Graphics3d Object .. PLOT:: @@ -717,7 +731,8 @@ def arrow3d(start, end, width=1, radius=None, head_radius=None, head_len=None, * Many arrows arranged in a circle (flying spears?):: - sage: sum([arrow3d((cos(t),sin(t),0),(cos(t),sin(t),1)) for t in [0,0.3,..,2*pi]]) + sage: sum(arrow3d((cos(t),sin(t),0), (cos(t),sin(t),1)) # optional - sage.symbolic + ....: for t in [0,0.3,..,2*pi]) Graphics3d Object .. PLOT:: @@ -730,7 +745,7 @@ def arrow3d(start, end, width=1, radius=None, head_radius=None, head_len=None, * sphinx_plot(G) Change the width of the arrow. (Note: for an arrow that scales with zoom, please consider - the ``line3d`` function with the option ``arrow_head=True``):: + the :func:`line3d` function with the option ``arrow_head=True``):: sage: arrow3d((0,0,0), (1,1,1), width=1) Graphics3d Object @@ -804,7 +819,7 @@ cdef class Sphere(ParametricSurface): from sage.plot.plot3d.shapes import Sphere sphinx_plot(Sphere(3)) - Plot with aspect_ratio=1 to see it unsquashed:: + Plot with ``aspect_ratio=1`` to see it unsquashed:: sage: S = Sphere(3, color='blue') + Sphere(2, color='red').translate(0,3,0) sage: S.show(aspect_ratio=1) @@ -970,8 +985,8 @@ cdef class Torus(ParametricSurface): """ INPUT: - - R -- (default: 1) outer radius - - r -- (default: .3) inner radius + - ``R`` -- (default: ``1``) outer radius + - ``r`` -- (default: ``.3``) inner radius OUTPUT: @@ -998,7 +1013,8 @@ cdef class Torus(ParametricSurface): A rubberband ball:: - sage: show(sum([Torus(1, .03, color=(1, t/30.0, 0)).rotate((1,1,1),t) for t in range(30)])) + sage: show(sum(Torus(1, .03, color=(1, t/30.0, 0)).rotate((1,1,1), t) + ....: for t in range(30))) .. PLOT:: @@ -1007,8 +1023,12 @@ cdef class Torus(ParametricSurface): Mmm... doughnuts:: - sage: D = Torus(1, .4, color=(.5, .3, .2)) + Torus(1, .3, color='yellow').translate(0, 0, .15) - sage: G = sum(D.translate(RDF.random_element(-.2, .2), RDF.random_element(-.2, .2), .8*t) for t in range(10)) + sage: D = Torus(1, .4, color=(.5, .3, .2)) + sage: D += Torus(1, .3, color='yellow').translate(0, 0, .15) + sage: G = sum(D.translate(RDF.random_element(-.2, .2), + ....: RDF.random_element(-.2, .2), + ....: .8*t) + ....: for t in range(10)) sage: G.show(aspect_ratio=1, frame=False) .. PLOT:: diff --git a/src/sage/plot/plot3d/shapes2.py b/src/sage/plot/plot3d/shapes2.py index ae879508511..6eafbbcd3b1 100644 --- a/src/sage/plot/plot3d/shapes2.py +++ b/src/sage/plot/plot3d/shapes2.py @@ -64,8 +64,8 @@ def line3d(points, thickness=1, radius=None, arrow_head=False, **kwds): - ``color`` -- a string (``"red"``, ``"green"`` etc) or a tuple (r, g, b) with r, g, b numbers between 0 and 1 - - ``opacity`` -- (default: 1) if less than 1 then is - transparent + - ``opacity`` -- (default: 1) if less than 1 then is + transparent EXAMPLES: @@ -210,13 +210,13 @@ def bezier3d(path, **options): - ``thickness`` -- (default: 2) - - ``color`` -- a string (``"red"``, ``"green"`` etc) - or a tuple (r, g, b) with r, g, b numbers between 0 and 1 + - ``color`` -- a string (``"red"``, ``"green"`` etc) + or a tuple (r, g, b) with r, g, b numbers between 0 and 1 - ``opacity`` -- (default: 1) if less than 1 then is transparent - - ``aspect_ratio`` -- (default:[1,1,1]) + - ``aspect_ratio`` -- (default: [1,1,1]) The path is a list of curves, and each curve is a list of points. Each point is a tuple (x,y,z). @@ -248,9 +248,9 @@ def bezier3d(path, **options): EXAMPLES:: - sage: path = [[(0,0,0),(.5,.1,.2),(.75,3,-1),(1,1,0)],[(.5,1,.2),(1,.5,0)],[(.7,.2,.5)]] - sage: b = bezier3d(path, color='green') - sage: b + sage: path = [[(0,0,0),(.5,.1,.2),(.75,3,-1),(1,1,0)], + ....: [(.5,1,.2),(1,.5,0)], [(.7,.2,.5)]] + sage: b = bezier3d(path, color='green'); b # optional - sage.symbolic Graphics3d Object .. PLOT:: @@ -261,8 +261,7 @@ def bezier3d(path, **options): To construct a simple curve, create a list containing a single list:: sage: path = [[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]] - sage: curve = bezier3d(path, thickness=5, color='blue') - sage: curve + sage: curve = bezier3d(path, thickness=5, color='blue'); curve # optional - sage.symbolic Graphics3d Object .. PLOT:: @@ -274,12 +273,14 @@ def bezier3d(path, **options): Check for :trac:`31640`:: - sage: p2d = [[(3,0.0),(3,0.13),(2,0.2),(2,0.3)], [(2.7,0.4),(2.6,0.5),(2.5,0.5)], [(2.3,0.5),(2.2,0.4),(2.1,0.3)]] - sage: bp = bezier_path(p2d) - sage: bp.plot3d() + sage: p2d = [[(3,0.0),(3,0.13),(2,0.2),(2,0.3)], # optional - sage.symbolic + ....: [(2.7,0.4),(2.6,0.5),(2.5,0.5)], [(2.3,0.5),(2.2,0.4),(2.1,0.3)]] + sage: bp = bezier_path(p2d) # optional - sage.symbolic + sage: bp.plot3d() # optional - sage.symbolic Graphics3d Object - sage: p3d = p3d = [[(3,0,0),(3,0.1,0),(2.9,0.2,0),(2.8,0.3,0)], [(2.7,0.4,0),(2,0.5,0),(2.5,0.5,0)], [(2.3,0.5,0),(2.2,0.4,0),(2.1,0.3,0)]] + sage: p3d = [[(3,0,0),(3,0.1,0),(2.9,0.2,0),(2.8,0.3,0)], # optional - sage.symbolic + ....: [(2.7,0.4,0),(2,0.5,0),(2.5,0.5,0)], [(2.3,0.5,0),(2.2,0.4,0),(2.1,0.3,0)]] sage: bezier3d(p3d) Graphics3d Object """ @@ -336,7 +337,8 @@ def polygon3d(points, **options): Some modern art -- a random polygon:: - sage: v = [(randrange(-5,5), randrange(-5,5), randrange(-5, 5)) for _ in range(10)] + sage: v = [(randrange(-5,5), randrange(-5,5), randrange(-5, 5)) + ....: for _ in range(10)] sage: polygon3d(v) Graphics3d Object @@ -347,7 +349,8 @@ def polygon3d(points, **options): A bent transparent green triangle:: - sage: polygon3d([[1, 2, 3], [0,1,0], [1,0,1], [3,0,0]], color=(0,1,0), opacity=0.7) + sage: polygon3d([[1, 2, 3], [0,1,0], [1,0,1], [3,0,0]], + ....: color=(0,1,0), opacity=0.7) Graphics3d Object .. PLOT:: @@ -356,7 +359,8 @@ def polygon3d(points, **options): This is the same as using ``alpha=0.7``:: - sage: polygon3d([[1, 2, 3], [0,1,0], [1,0,1], [3,0,0]], color=(0,1,0), alpha=0.7) + sage: polygon3d([[1, 2, 3], [0,1,0], [1,0,1], [3,0,0]], + ....: color=(0,1,0), alpha=0.7) Graphics3d Object .. PLOT:: @@ -373,7 +377,7 @@ def polygons3d(faces, points, **options): """ Draw the union of several polygons in 3d. - Useful to plot a polyhedron as just one ``IndexFaceSet``. + Useful to plot a polyhedron as just one :class:`IndexFaceSet`. INPUT: @@ -426,8 +430,8 @@ def frame3d(lower_left, upper_right, **kwds): This is usually used for making an actual plot:: - sage: y = var('y') - sage: plot3d(sin(x^2+y^2),(x,0,pi),(y,0,pi)) + sage: y = var('y') # optional - sage.symbolic + sage: plot3d(sin(x^2+y^2), (x,0,pi), (y,0,pi)) # optional - sage.symbolic Graphics3d Object """ x0, y0, z0 = lower_left @@ -483,11 +487,11 @@ def frame_labels(lower_left, upper_right, This is usually used for making an actual plot:: - sage: y = var('y') - sage: P = plot3d(sin(x^2+y^2),(x,0,pi),(y,0,pi)) - sage: a,b = P._rescale_for_frame_aspect_ratio_and_zoom(1.0,[1,1,1],1) - sage: F = frame_labels(a,b,*P._box_for_aspect_ratio("automatic",a,b)) - sage: F.jmol_repr(F.default_render_params())[0] + sage: y = var('y') # optional - sage.symbolic + sage: P = plot3d(sin(x^2+y^2), (x,0,pi), (y,0,pi)) # optional - sage.symbolic + sage: a,b = P._rescale_for_frame_aspect_ratio_and_zoom(1.0,[1,1,1],1) # optional - sage.symbolic + sage: F = frame_labels(a, b, *P._box_for_aspect_ratio("automatic",a,b)) # optional - sage.symbolic + sage: F.jmol_repr(F.default_render_params())[0] # optional - sage.symbolic [['select atomno = 1', 'color atom [76,76,76]', 'label "0.0"']] TESTS:: @@ -749,7 +753,7 @@ def sphere(center=(0, 0, 0), size=1, **kwds): Spheres of radii 1 and 2 one stuck into the other:: sage: sphere(color='orange') + sphere(color=(0,0,0.3), - ....: center=(0,0,-2),size=2,opacity=0.9) + ....: center=(0,0,-2), size=2, opacity=0.9) Graphics3d Object .. PLOT:: @@ -758,9 +762,9 @@ def sphere(center=(0, 0, 0), size=1, **kwds): We draw a transparent sphere on a saddle. :: - sage: u,v = var('u v') - sage: saddle = plot3d(u^2 - v^2, (u,-2,2), (v,-2,2)) - sage: sphere((0,0,1), color='red', opacity=0.5, aspect_ratio=[1,1,1]) + saddle + sage: u,v = var('u v') # optional - sage.symbolic + sage: saddle = plot3d(u^2 - v^2, (u,-2,2), (v,-2,2)) # optional - sage.symbolic + sage: sphere((0,0,1), color='red', opacity=0.5, aspect_ratio=[1,1,1]) + saddle # optional - sage.symbolic Graphics3d Object .. PLOT:: @@ -1048,7 +1052,8 @@ class Line(PrimitiveObject): EXAMPLES:: sage: from sage.plot.plot3d.shapes2 import Line - sage: Line([(i*math.sin(i), i*math.cos(i), i/3) for i in range(30)], arrow_head=True) + sage: Line([(i*math.sin(i), i*math.cos(i), i/3) for i in range(30)], + ....: arrow_head=True) Graphics3d Object Smooth angles less than 90 degrees:: @@ -1060,10 +1065,10 @@ class Line(PrimitiveObject): sage: N = 11 sage: c = 0.4 - sage: sum([Line([(i,1,0), (i,0,0), (i,cos(2*pi*i/N), sin(2*pi*i/N))], - ....: corner_cutoff=c, - ....: color='red' if -cos(2*pi*i/N)<=c else 'blue') - ....: for i in range(N+1)]) + sage: sum(Line([(i,1,0), (i,0,0), (i,cos(2*pi*i/N), sin(2*pi*i/N))], # optional - sage.symbolic + ....: corner_cutoff=c, + ....: color='red' if -cos(2*pi*i/N)<=c else 'blue') + ....: for i in range(N+1)) Graphics3d Object """ def __init__(self, points, thickness=5, corner_cutoff=0.5, @@ -1099,10 +1104,10 @@ def bounding_box(self): TESTS:: sage: from sage.plot.plot3d.shapes2 import Line - sage: L = Line([(i,i^2-1,-2*ln(i)) for i in [10,20,30]]) - sage: L.bounding_box() + sage: L = Line([(i, i^2 - 1, -2*ln(i)) for i in [10,20,30]]) # optional - sage.symbolic + sage: L.bounding_box() # optional - sage.symbolic ((10.0, 99.0, -6.802394763324311), - (30.0, 899.0, -4.605170185988092)) + (30.0, 899.0, -4.605170185988092)) """ try: return self.__bounding_box @@ -1117,8 +1122,9 @@ def tachyon_repr(self, render_params): TESTS:: - sage: L = line3d([(cos(i),sin(i),i^2) for i in srange(0,10,.01)],color='red') - sage: L.tachyon_repr(L.default_render_params())[0] + sage: L = line3d([(cos(i),sin(i),i^2) for i in srange(0,10,.01)], # optional - sage.symbolic + ....: color='red') + sage: L.tachyon_repr(L.default_render_params())[0] # optional - sage.symbolic 'FCylinder base 1.0 0.0 0.0 apex 0.9999500004166653 0.009999833334166664 0.0001 rad 0.005 texture...' """ T = render_params.transform @@ -1149,8 +1155,9 @@ def obj_repr(self, render_params): TESTS:: sage: from sage.plot.plot3d.shapes2 import Line - sage: L = Line([(cos(i),sin(i),i^2) for i in srange(0,10,.01)],color='red') - sage: L.obj_repr(L.default_render_params())[0][0][0][2][:3] + sage: L = Line([(cos(i),sin(i),i^2) for i in srange(0,10,.01)], # optional - sage.symbolic + ....: color='red') + sage: L.obj_repr(L.default_render_params())[0][0][0][2][:3] # optional - sage.symbolic ['v 0.99995 0.00999983 0.0001', 'v 1.02376 0.010195 -0.00750607', 'v 1.00007 0.0102504 -0.0248984'] @@ -1172,8 +1179,9 @@ def jmol_repr(self, render_params): TESTS:: - sage: L = line3d([(cos(i),sin(i),i^2) for i in srange(0,10,.01)],color='red') - sage: L.jmol_repr(L.default_render_params())[0][:42] + sage: L = line3d([(cos(i),sin(i),i^2) for i in srange(0,10,.01)], # optional - sage.symbolic + ....: color='red') + sage: L.jmol_repr(L.default_render_params())[0][:42] # optional - sage.symbolic 'draw line_1 diameter 1 curve {1.0 0.0 0.0}' """ T = render_params.transform @@ -1410,15 +1418,15 @@ def point3d(v, size=5, **kwds): - ``size`` -- (default: 5) size of the point (or points) - - ``color`` -- a string (``"red"``, ``"green"`` etc) - or a tuple (r, g, b) with r, g, b numbers between 0 and 1 + - ``color`` -- a string (``"red"``, ``"green"`` etc) + or a tuple (r, g, b) with r, g, b numbers between 0 and 1 - ``opacity`` -- (default: 1) if less than 1 then is transparent EXAMPLES:: - sage: sum([point3d((i,i^2,i^3), size=5) for i in range(10)]) + sage: sum(point3d((i,i^2,i^3), size=5) for i in range(10)) Graphics3d Object .. PLOT:: @@ -1431,15 +1439,15 @@ def point3d(v, size=5, **kwds): sage: print(point(vector((2,3,4)))) Graphics3d Object - sage: c = polytopes.hypercube(3) - sage: v = c.vertices()[0]; v + sage: c = polytopes.hypercube(3) # optional - sage.geometry.polyhedron + sage: v = c.vertices()[0]; v # optional - sage.geometry.polyhedron A vertex at (1, -1, -1) - sage: print(point(v)) + sage: print(point(v)) # optional - sage.geometry.polyhedron Graphics3d Object We check to make sure the options work:: - sage: point3d((4,3,2),size=20,color='red',opacity=.5) + sage: point3d((4,3,2), size=20, color='red', opacity=.5) Graphics3d Object .. PLOT:: @@ -1469,7 +1477,7 @@ def point3d(v, size=5, **kwds): We check that iterators of points are accepted (:trac:`13890`):: - sage: point3d(iter([(1,1,2),(2,3,4),(3,5,8)]),size=20,color='red') + sage: point3d(iter([(1,1,2),(2,3,4),(3,5,8)]), size=20, color='red') Graphics3d Object TESTS:: diff --git a/src/sage/plot/plot3d/tachyon.py b/src/sage/plot/plot3d/tachyon.py index 88c8eba2d51..a245541544a 100644 --- a/src/sage/plot/plot3d/tachyon.py +++ b/src/sage/plot/plot3d/tachyon.py @@ -34,7 +34,7 @@ flexibility. For example, here we directly use Tachyon to draw 3 spheres on the coordinate axes:: - sage: t = Tachyon(xres=500,yres=500, camera_position=(2,0,0)) + sage: t = Tachyon(xres=500, yres=500, camera_position=(2,0,0)) sage: t.light((4,3,2), 0.2, (1,1,1)) sage: t.texture('t2', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) sage: t.texture('t3', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,1,0)) @@ -46,11 +46,12 @@ For scenes with many reflections it is helpful to increase the raydepth option, and turn on antialiasing. The following scene is an extreme case with many reflections between four cotangent spheres:: - sage: t = Tachyon(camera_position=(0,-4,1), xres = 800, yres = 600, raydepth = 12, aspectratio=.75, antialiasing = 4) + sage: t = Tachyon(camera_position=(0,-4,1), xres=800, yres=600, raydepth=12, + ....: aspectratio=.75, antialiasing=4) sage: t.light((0.02,0.012,0.001), 0.01, (1,0,0)) sage: t.light((0,0,10), 0.01, (0,0,1)) - sage: t.texture('s', color = (.8,1,1), opacity = .9, specular = .95, diffuse = .3, ambient = 0.05) - sage: t.texture('p', color = (0,0,1), opacity = 1, specular = .2) + sage: t.texture('s', color=(.8,1,1), opacity=.9, specular=.95, diffuse=.3, ambient=0.05) + sage: t.texture('p', color=(0,0,1), opacity=1, specular=.2) sage: t.sphere((-1,-.57735,-0.7071),1,'s') sage: t.sphere((1,-.57735,-0.7071),1,'s') sage: t.sphere((0,1.15465,-0.7071),1,'s') @@ -92,7 +93,7 @@ Finally there is the ``projection='perspective_dof'`` option. :: sage: T = Tachyon(xres=800, antialiasing=4, raydepth=10, - ....: projection='perspective_dof', focallength='1.0', aperture='.0025') + ....: projection='perspective_dof', focallength='1.0', aperture='.0025') sage: T.light((0,5,7), 1.0, (1,1,1)) sage: T.texture('t1', opacity=1, specular=.3) sage: T.texture('t2', opacity=1, specular=.3, color=(0,0,1)) @@ -113,7 +114,8 @@ cylinders or spheres. In this example an image is created and then used to tile the plane:: - sage: T = Tachyon(xres=800, yres=600, camera_position=(-2.0,-.1,.3), projection='fisheye', frustum=(-1.0, 1.0, -1.0, 1.0)) + sage: T = Tachyon(xres=800, yres=600, camera_position=(-2.0,-.1,.3), + ....: projection='fisheye', frustum=(-1.0, 1.0, -1.0, 1.0)) sage: T.texture('t1',color=(0,0,1)) sage: for ed in cedges: ....: T.fcylinder(ed[0], ed[1], .05, 't1') @@ -121,15 +123,19 @@ sage: fname_png = tmp_filename(ext='.png') sage: fname_ppm = tmp_filename(ext='.ppm') sage: T.save(fname_png) - sage: r2 = os.system('convert '+fname_png+' '+fname_ppm) # optional -- ImageMagick - - sage: T = Tachyon(xres=800, yres=600, camera_position=(-2.0,-.1,.3), projection='fisheye', frustum=(-1.0, 1.0, -1.0, 1.0)) # optional -- ImageMagick - sage: T.texture('t1', color=(1,0,0), specular=.9) # optional -- ImageMagick - sage: T.texture('p1', color=(1,1,1), opacity=.1, imagefile=fname_ppm, texfunc=9) # optional -- ImageMagick - sage: T.sphere((0,0,0), .5, 't1') # optional -- ImageMagick - sage: T.plane((0,0,-1), (0,0,1), 'p1') # optional -- ImageMagick - sage: T.light((-4,-4,4), .1, (1,1,1)) # optional -- ImageMagick - sage: T.show() # optional -- ImageMagick + sage: r2 = os.system('convert '+fname_png+' '+fname_ppm) # optional -- ImageMagick + + sage: T = Tachyon(xres=800, yres=600, # optional -- ImageMagick + ....: camera_position=(-2.0,-.1,.3), + ....: projection='fisheye', + ....: frustum=(-1.0, 1.0, -1.0, 1.0)) + sage: T.texture('t1', color=(1,0,0), specular=.9) # optional -- ImageMagick + sage: T.texture('p1', color=(1,1,1), opacity=.1, # optional -- ImageMagick + ....: imagefile=fname_ppm, texfunc=9) + sage: T.sphere((0,0,0), .5, 't1') # optional -- ImageMagick + sage: T.plane((0,0,-1), (0,0,1), 'p1') # optional -- ImageMagick + sage: T.light((-4,-4,4), .1, (1,1,1)) # optional -- ImageMagick + sage: T.show() # optional -- ImageMagick AUTHOR: @@ -172,24 +178,24 @@ class Tachyon(WithEqualityById, SageObject): INPUT: - - ``xres`` - (default 350) - - ``yres`` - (default 350) - - ``zoom`` - (default 1.0) - - ``antialiasing`` - (default ``False``) - - ``aspectratio`` - (default 1.0) - - ``raydepth`` - (default 8) - - ``camera_position`` - (default (-3, 0, 0)) - - ``updir`` - (default (0, 0, 1)) - - ``look_at`` - (default (0,0,0)) - - ``viewdir`` - (default ``None``), otherwise list of three numbers - - ``projection`` - ``'PERSPECTIVE'`` (default), ``'perspective_dof'`` + - ``xres`` -- (default 350) + - ``yres`` -- (default 350) + - ``zoom`` -- (default 1.0) + - ``antialiasing`` -- (default ``False``) + - ``aspectratio`` -- (default 1.0) + - ``raydepth`` -- (default 8) + - ``camera_position`` -- (default (-3, 0, 0)) + - ``updir`` -- (default (0, 0, 1)) + - ``look_at`` -- (default (0,0,0)) + - ``viewdir`` -- (default ``None``), otherwise list of three numbers + - ``projection`` -- ``'PERSPECTIVE'`` (default), ``'perspective_dof'`` or ``'fisheye'``. - - ``frustum`` - (default ''), otherwise list of four numbers. Only - used with projection='fisheye'. - - ``focallength`` - (default ''), otherwise a number. Only used - with projection='perspective_dof'. - - ``aperture`` - (default ''), otherwise a number. Only used - with projection='perspective_dof'. + - ``frustum`` -- (default ``''``), otherwise list of four numbers. Only + used with ``projection='fisheye'``. + - ``focallength`` -- (default ''), otherwise a number. Only used + with ``projection='perspective_dof'``. + - ``aperture`` -- (default ''), otherwise a number. Only used + with ``projection='perspective_dof'``. OUTPUT: A Tachyon 3d scene. @@ -205,7 +211,7 @@ class Tachyon(WithEqualityById, SageObject): sage: t.light((4,3,2), 0.2, (1,1,1)) sage: t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1.0,0,0)) sage: t.texture('t1', ambient=0.1, diffuse=0.9, specular=0.3, opacity=1.0, color=(0,1.0,0)) - sage: t.texture('t2', ambient=0.2,diffuse=0.7, specular=0.5, opacity=0.7, color=(0,0,1.0)) + sage: t.texture('t2', ambient=0.2, diffuse=0.7, specular=0.5, opacity=0.7, color=(0,0,1.0)) sage: k=0 sage: for i in srange(-1,1,0.05): ....: k += 1 @@ -257,20 +263,21 @@ class Tachyon(WithEqualityById, SageObject): sage: t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) sage: t.texture('t1', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,1,0)) sage: t.texture('t2', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,0,1)) - sage: E = EllipticCurve('37a') - sage: P = E([0,0]) - sage: Q = P + sage: E = EllipticCurve('37a') # optional - sage.schemes + sage: P = E([0,0]) # optional - sage.schemes + sage: Q = P # optional - sage.schemes sage: n = 100 - sage: for i in range(n): # increase 20 for a better plot + sage: for i in range(n): # increase 20 for a better plot # optional - sage.schemes ....: Q = Q + P ....: t.sphere((Q[1], Q[0], ZZ(i)/n), 0.1, 't%s'%(i%3)) - sage: t.show() + sage: t.show() # optional - sage.schemes A beautiful picture of rational points on a rank 1 elliptic curve. :: - sage: t = Tachyon(xres=1000, yres=800, camera_position=(2,7,4), look_at=(2,0,0), raydepth=4) + sage: t = Tachyon(xres=1000, yres=800, camera_position=(2,7,4), + ....: look_at=(2,0,0), raydepth=4) sage: t.light((10,3,2), 1, (1,1,1)) sage: t.light((10,-3,2), 1, (1,1,1)) sage: t.texture('black', color=(0,0,0)) @@ -279,29 +286,30 @@ class Tachyon(WithEqualityById, SageObject): sage: t.plane((0,0,0),(0,0,1),'grey') sage: t.cylinder((0,0,0),(1,0,0),.01,'black') sage: t.cylinder((0,0,0),(0,1,0),.01,'black') - sage: E = EllipticCurve('37a') - sage: P = E([0,0]) - sage: Q = P + sage: E = EllipticCurve('37a') # optional - sage.schemes + sage: P = E([0,0]) # optional - sage.schemes + sage: Q = P # optional - sage.schemes sage: n = 100 - sage: for i in range(n): + sage: for i in range(n): # optional - sage.schemes ....: Q = Q + P ....: c = i/n + .1 ....: t.texture('r%s'%i,color=(float(i/n),0,0)) ....: t.sphere((Q[0], -Q[1], .01), .04, 'r%s'%i) - sage: t.show() # long time, e.g., 10-20 seconds + sage: t.show() # long time, e.g., 10-20 seconds # optional - sage.schemes A beautiful spiral. :: - sage: t = Tachyon(xres=800,yres=800, camera_position=(2,5,2), look_at=(2.5,0,0)) + sage: t = Tachyon(xres=800, yres=800, camera_position=(2,5,2), look_at=(2.5,0,0)) sage: t.light((0,0,100), 1, (1,1,1)) - sage: t.texture('r', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) - sage: for i in srange(0,50,0.1): + sage: t.texture('r', ambient=0.1, diffuse=0.9, specular=0.5, + ....: opacity=1.0, color=(1,0,0)) + sage: for i in srange(0,50,0.1): # optional - sage.schemes ....: t.sphere((i/10,sin(i),cos(i)), 0.05, 'r') sage: t.texture('white', color=(1,1,1), opacity=1, specular=1, diffuse=1) sage: t.plane((0,0,-100), (0,0,-100), 'white') - sage: t.show() + sage: t.show() # optional - sage.schemes If the optional parameter ``viewdir`` is not set, the camera center should not coincide with the point which @@ -314,7 +322,8 @@ class Tachyon(WithEqualityById, SageObject): Use of a fisheye lens perspective. :: - sage: T = Tachyon(xres=800, yres=600, camera_position=(-1.5,-1.5,.3), projection='fisheye', frustum=(-1.0, 1.0, -1.0, 1.0)) + sage: T = Tachyon(xres=800, yres=600, camera_position=(-1.5,-1.5,.3), + ....: projection='fisheye', frustum=(-1.0, 1.0, -1.0, 1.0)) sage: T.texture('t1', color=(0,0,1)) sage: cedges = [[[1, 1, 1], [-1, 1, 1]], [[1, 1, 1], [1, -1, 1]], ....: [[1, 1, 1], [1, 1, -1]], [[-1, 1, 1], [-1, -1, 1]], [[-1, 1, 1], @@ -331,7 +340,8 @@ class Tachyon(WithEqualityById, SageObject): Use of the ``projection='perspective_dof'`` option. This may not be implemented correctly. :: - sage: T = Tachyon(xres=800,antialiasing=4, raydepth=10, projection='perspective_dof', focallength='1.0', aperture='.0025') + sage: T = Tachyon(xres=800, antialiasing=4, raydepth=10, + ....: projection='perspective_dof', focallength='1.0', aperture='.0025') sage: T.light((0,5,7), 1.0, (1,1,1)) sage: T.texture('t1', opacity=1, specular=.3) sage: T.texture('t2', opacity=1, specular=.3, color=(0,0,1)) @@ -544,14 +554,17 @@ def show(self, **kwds): :: - sage: h = Tachyon(xres=512,yres=512, camera_position=(4,-4,3),viewdir=(-4,4,-3), raydepth=4) + sage: h = Tachyon(xres=512, yres=512, camera_position=(4,-4,3), + ....: viewdir=(-4,4,-3), raydepth=4) sage: h.light((4.4,-4.4,4.4), 0.2, (1,1,1)) sage: def f(x,y): return float(sin(x*y)) - sage: h.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, opacity=1.0, color=(1.0,0,0)) - sage: h.plot(f,(-4,4),(-4,4),"t0",max_depth=5,initial_depth=3, num_colors=60) # increase min_depth for better picture + sage: h.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, + ....: opacity=1.0, color=(1.0,0,0)) + sage: h.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # optional -- sage.symbolic + ....: num_colors=60) # increase min_depth for better picture sage: from sage.misc.verbose import set_verbose, get_verbose sage: set_verbose(0) - sage: h.show() + sage: h.show() # optional -- sage.symbolic This second example, using a "medium" global verbosity setting of 1, displays some extra technical information then @@ -559,13 +572,16 @@ def show(self, **kwds): :: - sage: s = Tachyon(xres=512,yres=512, camera_position=(4,-4,3),viewdir=(-4,4,-3), raydepth=4) + sage: s = Tachyon(xres=512, yres=512, camera_position=(4,-4,3), + ....: viewdir=(-4,4,-3), raydepth=4) sage: s.light((4.4,-4.4,4.4), 0.2, (1,1,1)) sage: def f(x,y): return float(sin(x*y)) - sage: s.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, opacity=1.0, color=(1.0,0,0)) - sage: s.plot(f,(-4,4),(-4,4),"t0",max_depth=5,initial_depth=3, num_colors=60) # increase min_depth for better picture + sage: s.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, + ....: opacity=1.0, color=(1.0,0,0)) + sage: s.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # optional -- sage.symbolic + ....: num_colors=60) # increase min_depth for better picture sage: set_verbose(1) - sage: s.show() + sage: s.show() # optional -- sage.symbolic tachyon ... Scene contains 2713 objects. ... @@ -579,11 +595,14 @@ def show(self, **kwds): :: sage: set_verbose(0) - sage: d = Tachyon(xres=512,yres=512, camera_position=(4,-4,3),viewdir=(-4,4,-3), raydepth=4) + sage: d = Tachyon(xres=512, yres=512, camera_position=(4,-4,3), + ....: viewdir=(-4,4,-3), raydepth=4) sage: d.light((4.4,-4.4,4.4), 0.2, (1,1,1)) sage: def f(x,y): return float(sin(x*y)) - sage: d.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, opacity=1.0, color=(1.0,0,0)) - sage: d.plot(f,(-4,4),(-4,4),"t0",max_depth=5,initial_depth=3, num_colors=60) # increase min_depth for better picture + sage: d.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, # optional -- sage.symbolic + ....: opacity=1.0, color=(1.0,0,0)) + sage: d.plot(f,(-4,4),(-4,4),"t0",max_depth=5,initial_depth=3, + ....: num_colors=60) # increase min_depth for better picture sage: get_verbose() 0 sage: d.show(verbose=2) @@ -604,7 +623,7 @@ def _res(self): EXAMPLES:: - sage: t = Tachyon(xres = 300, yres = 700) + sage: t = Tachyon(xres=300, yres=700) sage: t._res() '\nresolution 300 700\n' """ @@ -617,7 +636,7 @@ def _camera(self): EXAMPLES:: - sage: t = Tachyon(raydepth = 16, zoom = 2, antialiasing = True) + sage: t = Tachyon(raydepth=16, zoom=2, antialiasing=True) sage: t._camera().split()[3:10] ['zoom', '2.0', 'aspectratio', '1.0', 'antialiasing', '1', 'raydepth'] """ @@ -764,7 +783,8 @@ def texture(self, name, ambient=0.2, diffuse=0.8, sage: t = Tachyon(camera_position=(2,5,4), look_at=(2,0,0), raydepth=6) sage: t.light((10,3,4), 1, (1,1,1)) - sage: t.texture('mirror', ambient=0.05, diffuse=0.05, specular=.9, opacity=0.9, color=(.8,.8,.8)) + sage: t.texture('mirror', ambient=0.05, diffuse=0.05, specular=.9, + ....: opacity=0.9, color=(.8,.8,.8)) sage: t.texture('grey', color=(.8,.8,.8), texfunc=3) sage: t.plane((0,0,0),(0,0,1),'grey') sage: t.sphere((4,-1,1), 1, 'mirror') @@ -987,12 +1007,15 @@ def plot(self, f, xmin_xmax, ymin_ymax, texture, grad_f=None, Flat Triangles:: - sage: t = Tachyon(xres=512,yres=512, camera_position=(4,-4,3),viewdir=(-4,4,-3), raydepth=4) + sage: t = Tachyon(xres=512, yres=512, camera_position=(4,-4,3), + ....: viewdir=(-4,4,-3), raydepth=4) sage: t.light((4.4,-4.4,4.4), 0.2, (1,1,1)) sage: def f(x,y): return float(sin(x*y)) - sage: t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, opacity=1.0, color=(1.0,0,0)) - sage: t.plot(f,(-4,4),(-4,4),"t0",max_depth=5,initial_depth=3, num_colors=60) # increase min_depth for better picture - sage: t.show(verbose=1) + sage: t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, + ....: opacity=1.0, color=(1.0,0,0)) + sage: t.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # optional -- sage.symbolic + ....: num_colors=60) # increase min_depth for better picture + sage: t.show(verbose=1) # optional -- sage.symbolic tachyon ... Scene contains 2713 objects. ... @@ -1000,13 +1023,16 @@ def plot(self, f, xmin_xmax, ymin_ymax, texture, grad_f=None, Plotting with Smooth Triangles (requires explicit gradient function):: - sage: t = Tachyon(xres=512,yres=512, camera_position=(4,-4,3),viewdir=(-4,4,-3), raydepth=4) + sage: t = Tachyon(xres=512, yres=512, camera_position=(4,-4,3), + ....: viewdir=(-4,4,-3), raydepth=4) sage: t.light((4.4,-4.4,4.4), 0.2, (1,1,1)) sage: def f(x,y): return float(sin(x*y)) - sage: def g(x,y): return ( float(y*cos(x*y)), float(x*cos(x*y)), 1 ) - sage: t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, opacity=1.0, color=(1.0,0,0)) - sage: t.plot(f,(-4,4),(-4,4),"t0",max_depth=5,initial_depth=3, grad_f = g) # increase min_depth for better picture - sage: t.show(verbose=1) + sage: def g(x,y): return (float(y*cos(x*y)), float(x*cos(x*y)), 1) + sage: t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, + ....: opacity=1.0, color=(1.0,0,0)) + sage: t.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # optional -- sage.symbolic + ....: grad_f=g) # increase min_depth for better picture + sage: t.show(verbose=1) # optional -- sage.symbolic tachyon ... Scene contains 2713 objects. ... @@ -1646,7 +1672,6 @@ def str(self): EXAMPLES:: sage: from sage.plot.plot3d.tachyon import ParametricPlot - sage: t = var('t') sage: f = lambda t: (t,t^2,t^3) sage: q = ParametricPlot(f,0,1,'s') sage: q.str()[9:69] @@ -1662,7 +1687,6 @@ def __init__(self, f, t_0, t_f, tex, r=.1, cylinders=True, EXAMPLES:: sage: from sage.plot.plot3d.tachyon import ParametricPlot - sage: t = var('t') sage: f = lambda t: (t,t^2,t^3) sage: q = ParametricPlot(f,0,1,'s') sage: q._e_rel @@ -1690,7 +1714,6 @@ def _plot_step(self, depth, t_0, t_f, f_0, f_f): EXAMPLES:: sage: from sage.plot.plot3d.tachyon import ParametricPlot - sage: t = var('t') sage: f = lambda t: (t,t^2,t^3) sage: q = ParametricPlot(f,0,1,'s') sage: q._plot_step(8,0,1,[0,0,0],[1,1,1]) @@ -1724,7 +1747,6 @@ def tol(self, est, val): EXAMPLES:: sage: from sage.plot.plot3d.tachyon import ParametricPlot - sage: t = var('t') sage: f = lambda t: (t,t^2,t^3) sage: q = ParametricPlot(f,0,1,'s') sage: q.tol([0,0,0],[1,0,0]) diff --git a/src/sage/plot/plot_field.py b/src/sage/plot/plot_field.py index b57af986b59..262541b5f81 100644 --- a/src/sage/plot/plot_field.py +++ b/src/sage/plot/plot_field.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic """ Plotting fields """ diff --git a/src/sage/plot/point.py b/src/sage/plot/point.py index 10a19a5b5e4..19af77e3296 100644 --- a/src/sage/plot/point.py +++ b/src/sage/plot/point.py @@ -4,10 +4,12 @@ TESTS:: - sage: E = EllipticCurve('37a') - sage: P = E(0,0) - sage: def get_points(n): return sum([point(list(i*P)[:2], size=3) for i in range(-n,n) if i != 0 and (i*P)[0] < 3]) - sage: sum([get_points(15*n).plot3d(z=n) for n in range(1,10)]) + sage: E = EllipticCurve('37a') # optional - sage.schemes + sage: P = E(0,0) # optional - sage.schemes + sage: def get_points(n): + ....: return sum(point(list(i*P)[:2], size=3) +....: for i in range(-n,n) if i != 0 and (i*P)[0] < 3) + sage: sum(get_points(15*n).plot3d(z=n) for n in range(1,10)) # optional - sage.schemes Graphics3d Object """ @@ -40,15 +42,15 @@ class Point(GraphicPrimitive_xydata): INPUT: - - xdata -- list of x values for points in Point object + - ``xdata`` -- list of x values for points in Point object - - ydata -- list of y values for points in Point object + - ``ydata`` -- list of y values for points in Point object - - options -- dict of valid plot options to pass to constructor + - ``options`` -- dict of valid plot options to pass to constructor EXAMPLES: - Note this should normally be used indirectly via ``point`` and friends:: + Note this should normally be used indirectly via :func:`point` and friends:: sage: from sage.plot.point import Point sage: P = Point([1,2],[2,3],{'alpha':.5}) @@ -369,9 +371,11 @@ def point(points, **kwds): Extra options will get passed on to show(), as long as they are valid:: - sage: point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)], frame=True) + sage: point([(cos(theta), sin(theta)) # optional - sage.symbolic + ....: for theta in srange(0, 2*pi, pi/8)], frame=True) Graphics object consisting of 1 graphics primitive - sage: point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)]).show(frame=True) # These are equivalent + sage: point([(cos(theta), sin(theta)) # These are equivalent # optional - sage.symbolic + ....: for theta in srange(0, 2*pi, pi/8)]).show(frame=True) TESTS: @@ -502,8 +506,9 @@ def point2d(points, **options): The legend can be colored:: - sage: P = points([(0, 0), (1, 0)], pointsize=40, legend_label='origin', legend_color='red') - sage: P + plot(x^2, (x, 0, 1), legend_label='plot', legend_color='green') + sage: P = points([(0, 0), (1, 0)], pointsize=40, + ....: legend_label='origin', legend_color='red') + sage: P + plot(x^2, (x, 0, 1), legend_label='plot', legend_color='green') # optional - sage.symbolic Graphics object consisting of 2 graphics primitives .. PLOT:: @@ -514,9 +519,11 @@ def point2d(points, **options): Extra options will get passed on to show(), as long as they are valid:: - sage: point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)], frame=True) + sage: point([(cos(theta), sin(theta)) # optional - sage.symbolic + ....: for theta in srange(0, 2*pi, pi/8)], frame=True) Graphics object consisting of 1 graphics primitive - sage: point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)]).show(frame=True) # These are equivalent + sage: point([(cos(theta), sin(theta)) # These are equivalent # optional - sage.symbolic + ....: for theta in srange(0, 2*pi, pi/8)]).show(frame=True) .. PLOT:: @@ -546,9 +553,9 @@ def point2d(points, **options): We can plot a single complex number:: - sage: point(1 + I, pointsize=100) + sage: point(1 + I, pointsize=100) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive - sage: point(sqrt(2) + I, pointsize=100) + sage: point(sqrt(2) + I, pointsize=100) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -561,7 +568,7 @@ def point2d(points, **options): We can also plot a list of complex numbers:: - sage: point([I, 1 + I, 2 + 2*I], pointsize=100) + sage: point([I, 1 + I, 2 + 2*I], pointsize=100) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: diff --git a/src/sage/plot/polygon.py b/src/sage/plot/polygon.py index 48518a36da0..70f77c22778 100644 --- a/src/sage/plot/polygon.py +++ b/src/sage/plot/polygon.py @@ -31,11 +31,11 @@ class Polygon(GraphicPrimitive_xydata): INPUT: - - xdata -- list of `x`-coordinates of points defining Polygon + - ``xdata`` -- list of `x`-coordinates of points defining Polygon - - ydata -- list of `y`-coordinates of points defining Polygon + - ``ydata`` -- list of `y`-coordinates of points defining Polygon - - options -- dict of valid plot options to pass to constructor + - ``options`` -- dict of valid plot options to pass to constructor EXAMPLES: @@ -198,7 +198,8 @@ def plot3d(self, z=0, **kwds): A pentagon:: - sage: polygon([(cos(t), sin(t)) for t in srange(0, 2*pi, 2*pi/5)]).plot3d() + sage: polygon([(cos(t), sin(t)) # optional - sage.symbolic + ....: for t in srange(0, 2*pi, 2*pi/5)]).plot3d() Graphics3d Object .. PLOT:: @@ -364,8 +365,8 @@ def polygon2d(points, **options): For filled polygons, one can use different colors for the border and the interior as follows:: - sage: L = [[0,0]]+[[i/100, 1.1+cos(i/20)] for i in range(100)]+[[1,0]] - sage: polygon2d(L, color="limegreen", edgecolor="black", axes=False) + sage: L = [[0,0]]+[[i/100, 1.1+cos(i/20)] for i in range(100)]+[[1,0]] # optional - sage.symbolic + sage: polygon2d(L, color="limegreen", edgecolor="black", axes=False) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -388,8 +389,8 @@ def polygon2d(points, **options): An aperiodic monotile, [Smi2023]_:: - sage: s = sqrt(3) - sage: polygon2d([[0, 0], [0, s], [1, s], [3/2, 3/2*s], [3, s], [3, 0], [4, 0], + sage: s = sqrt(3) # optional - sage.symbolic + sage: polygon2d([[0, 0], [0, s], [1, s], [3/2, 3/2*s], [3, s], [3, 0], [4, 0], # optional - sage.symbolic ....: [9/2, -1/2*s], [3, -s], [3/2, -1/2*s], [1, -s], [-1, -s], ....: [-3/2, -1/2*s]], axes=False) Graphics object consisting of 1 graphics primitive @@ -403,8 +404,8 @@ def polygon2d(points, **options): A purple hexagon:: - sage: L = [[cos(pi*i/3),sin(pi*i/3)] for i in range(6)] - sage: polygon2d(L, rgbcolor=(1,0,1)) + sage: L = [[cos(pi*i/3),sin(pi*i/3)] for i in range(6)] # optional - sage.symbolic + sage: polygon2d(L, rgbcolor=(1,0,1)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -415,8 +416,9 @@ def polygon2d(points, **options): A green deltoid:: - sage: L = [[-1+cos(pi*i/100)*(1+cos(pi*i/100)),2*sin(pi*i/100)*(1-cos(pi*i/100))] for i in range(200)] - sage: polygon2d(L, rgbcolor=(1/8,3/4,1/2)) + sage: L = [[-1+cos(pi*i/100)*(1+cos(pi*i/100)), # optional - sage.symbolic + ....: 2*sin(pi*i/100)*(1-cos(pi*i/100))] for i in range(200)] + sage: polygon2d(L, rgbcolor=(1/8,3/4,1/2)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -427,8 +429,9 @@ def polygon2d(points, **options): A blue hypotrochoid:: - sage: L = [[6*cos(pi*i/100)+5*cos((6/2)*pi*i/100),6*sin(pi*i/100)-5*sin((6/2)*pi*i/100)] for i in range(200)] - sage: polygon2d(L, rgbcolor=(1/8,1/4,1/2)) + sage: L = [[6*cos(pi*i/100)+5*cos((6/2)*pi*i/100), # optional - sage.symbolic + ....: 6*sin(pi*i/100)-5*sin((6/2)*pi*i/100)] for i in range(200)] + sage: polygon2d(L, rgbcolor=(1/8,1/4,1/2)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -440,8 +443,9 @@ def polygon2d(points, **options): Another one:: sage: n = 4; h = 5; b = 2 - sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100),n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] - sage: polygon2d(L, rgbcolor=(1/8,1/4,3/4)) + sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100), # optional - sage.symbolic + ....: n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] + sage: polygon2d(L, rgbcolor=(1/8,1/4,3/4)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -454,8 +458,9 @@ def polygon2d(points, **options): A purple epicycloid:: sage: m = 9; b = 1 - sage: L = [[m*cos(pi*i/100)+b*cos((m/b)*pi*i/100),m*sin(pi*i/100)-b*sin((m/b)*pi*i/100)] for i in range(200)] - sage: polygon2d(L, rgbcolor=(7/8,1/4,3/4)) + sage: L = [[m*cos(pi*i/100)+b*cos((m/b)*pi*i/100), # optional - sage.symbolic + ....: m*sin(pi*i/100)-b*sin((m/b)*pi*i/100)] for i in range(200)] + sage: polygon2d(L, rgbcolor=(7/8,1/4,3/4)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -467,8 +472,8 @@ def polygon2d(points, **options): A brown astroid:: - sage: L = [[cos(pi*i/100)^3,sin(pi*i/100)^3] for i in range(200)] - sage: polygon2d(L, rgbcolor=(3/4,1/4,1/4)) + sage: L = [[cos(pi*i/100)^3, sin(pi*i/100)^3] for i in range(200)] # optional - sage.symbolic + sage: polygon2d(L, rgbcolor=(3/4,1/4,1/4)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -479,8 +484,9 @@ def polygon2d(points, **options): And, my favorite, a greenish blob:: - sage: L = [[cos(pi*i/100)*(1+cos(pi*i/50)), sin(pi*i/100)*(1+sin(pi*i/50))] for i in range(200)] - sage: polygon2d(L, rgbcolor=(1/8,3/4,1/2)) + sage: L = [[cos(pi*i/100)*(1+cos(pi*i/50)), # optional - sage.symbolic + ....: sin(pi*i/100)*(1+sin(pi*i/50))] for i in range(200)] + sage: polygon2d(L, rgbcolor=(1/8,3/4,1/2)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -491,8 +497,9 @@ def polygon2d(points, **options): This one is for my wife:: - sage: L = [[sin(pi*i/100)+sin(pi*i/50),-(1+cos(pi*i/100)+cos(pi*i/50))] for i in range(-100,100)] - sage: polygon2d(L, rgbcolor=(1,1/4,1/2)) + sage: L = [[sin(pi*i/100)+sin(pi*i/50), # optional - sage.symbolic + ....: -(1+cos(pi*i/100)+cos(pi*i/50))] for i in range(-100,100)] + sage: polygon2d(L, rgbcolor=(1,1/4,1/2)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -503,7 +510,7 @@ def polygon2d(points, **options): One can do the same one with a colored legend label:: - sage: polygon2d(L, color='red', legend_label='For you!', legend_color='red') + sage: polygon2d(L, color='red', legend_label='For you!', legend_color='red') # optional - sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: diff --git a/src/sage/plot/step.py b/src/sage/plot/step.py index 461ab53d411..bfd79dffb88 100644 --- a/src/sage/plot/step.py +++ b/src/sage/plot/step.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic """ Step function plots """ @@ -30,10 +31,10 @@ def plot_step_function(v, vertical_lines=True, **kwds): - ``v`` -- list of pairs (a,b) - - ``vertical_lines`` -- bool (default: True) if True, draw + - ``vertical_lines`` -- bool (default: ``True``) if ``True``, draw vertical risers at each step of this step function. Technically these vertical lines are not part of the graph - of this function, but they look very nice in the plot so we + of this function, but they look very nice in the plot, so we include them by default EXAMPLES: @@ -59,7 +60,8 @@ def plot_step_function(v, vertical_lines=True, **kwds): We pass in many options and get something that looks like "Space Invaders":: sage: v = [(i, sin(i)) for i in range(5, 20)] - sage: plot_step_function(v, vertical_lines=False, thickness=30, rgbcolor='purple', axes=False) + sage: plot_step_function(v, vertical_lines=False, thickness=30, + ....: rgbcolor='purple', axes=False) Graphics object consisting of 14 graphics primitives .. PLOT:: diff --git a/src/sage/plot/streamline_plot.py b/src/sage/plot/streamline_plot.py index bd9156bf000..3960adbe051 100644 --- a/src/sage/plot/streamline_plot.py +++ b/src/sage/plot/streamline_plot.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic """ Streamline plots """ @@ -199,7 +200,8 @@ def streamline_plot(f_g, xrange, yrange, **options): We increase the density of the plot:: - sage: streamline_plot((y, (cos(x)-2) * sin(x)), (x,-pi,pi), (y,-pi,pi), density=2) + sage: streamline_plot((y, (cos(x)-2) * sin(x)), + ....: (x,-pi,pi), (y,-pi,pi), density=2) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -211,7 +213,8 @@ def streamline_plot(f_g, xrange, yrange, **options): We ignore function values that are infinite or NaN:: sage: x, y = var('x y') - sage: streamline_plot((-x/sqrt(x^2+y^2), -y/sqrt(x^2+y^2)), (x,-10,10), (y,-10,10)) + sage: streamline_plot((-x/sqrt(x^2+y^2), -y/sqrt(x^2+y^2)), + ....: (x,-10,10), (y,-10,10)) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -225,7 +228,7 @@ def streamline_plot(f_g, xrange, yrange, **options): sage: streamline_plot((x, y), (x,-2,2), (y,-2,2), xmax=10) Graphics object consisting of 1 graphics primitive - sage: streamline_plot((x, y), (x,-2,2), (y,-2,2)).show(xmax=10) # These are equivalent + sage: streamline_plot((x, y), (x,-2,2), (y,-2,2)).show(xmax=10) # These are equivalent .. PLOT:: @@ -248,7 +251,8 @@ def streamline_plot(f_g, xrange, yrange, **options): We choose some particular points the streamlines pass through:: sage: pts = [[1, 1], [-2, 2], [1, -3/2]] - sage: g = streamline_plot((x + y) / sqrt(x^2 + y^2), (x,-3,3), (y,-3,3), start_points=pts) + sage: g = streamline_plot((x + y) / sqrt(x^2 + y^2), + ....: (x,-3,3), (y,-3,3), start_points=pts) sage: g += point(pts, color='red') sage: g Graphics object consisting of 2 graphics primitives diff --git a/src/sage/plot/text.py b/src/sage/plot/text.py index 0795cf5debb..90d8d5ee533 100644 --- a/src/sage/plot/text.py +++ b/src/sage/plot/text.py @@ -81,8 +81,8 @@ def _repr_(self): EXAMPLES:: - sage: T = text("I like cool constants", (pi,e)) - sage: t=T[0];t + sage: T = text("I like cool constants", (pi,e)) # optional - sage.symbolic + sage: t = T[0];t # optional - sage.symbolic Text 'I like cool constants' at the point (3.1415926535...,2.7182818284...) """ return "Text '%s' at the point (%s,%s)" % (self.string, self.x, self.y) @@ -273,7 +273,8 @@ def text(string, xy, **options): Larger font, bold, colored red and transparent text:: - sage: text("I had a dream!", (2,12), alpha=0.3, fontsize='large', fontweight='bold', color='red') + sage: text("I had a dream!", (2,12), alpha=0.3, + ....: fontsize='large', fontweight='bold', color='red') Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -283,7 +284,8 @@ def text(string, xy, **options): By setting ``horizontal_alignment`` to 'left' the text is guaranteed to be in the lower left no matter what:: - sage: text("I got a horse and he lives in a tree", (0,0), axis_coords=True, horizontal_alignment='left') + sage: text("I got a horse and he lives in a tree", (0,0), + ....: axis_coords=True, horizontal_alignment='left') Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -293,7 +295,8 @@ def text(string, xy, **options): Various rotations:: - sage: text("noitator", (0,0), rotation=45.0, horizontal_alignment='left', vertical_alignment='bottom') + sage: text("noitator", (0,0), rotation=45.0, + ....: horizontal_alignment='left', vertical_alignment='bottom') Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -311,7 +314,7 @@ def text(string, xy, **options): You can also align text differently:: - sage: t1 = text("Hello",(1,1), vertical_alignment="top") + sage: t1 = text("Hello", (1,1), vertical_alignment="top") sage: t2 = text("World", (1,0.5), horizontal_alignment="left") sage: t1 + t2 # render the sum Graphics object consisting of 2 graphics primitives @@ -330,7 +333,7 @@ def text(string, xy, **options): Some examples of bounding box:: - sage: bbox = {'boxstyle':"rarrow,pad=0.3", 'fc':"cyan", 'ec':"b", 'lw':2} + sage: bbox = {'boxstyle': "rarrow,pad=0.3", 'fc': "cyan", 'ec': "b", 'lw': 2} sage: text("I feel good", (1,2), bounding_box=bbox) Graphics object consisting of 1 graphics primitive @@ -341,7 +344,7 @@ def text(string, xy, **options): :: - sage: text("So good", (0,0), bounding_box={'boxstyle':'round', 'fc':'w'}) + sage: text("So good", (0,0), bounding_box={'boxstyle': 'round', 'fc': 'w'}) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -371,8 +374,10 @@ def text(string, xy, **options): sage: PQ = point2d([(-a, a), (a, a)]) sage: botleft = dict(horizontal_alignment='left', vertical_alignment='bottom') sage: botright = dict(horizontal_alignment='right', vertical_alignment='bottom') - sage: tp = text(r'$z_P = e^{3i\pi/4}$', (-a, a), **botright) - sage: tq = text(r'$Q = (\frac{\sqrt{2}}{2}, \frac{\sqrt{2}}{2})$', (a, a), **botleft) + sage: tp = text(r'$z_P = e^{3i\pi/4}$', + ....: (-a, a), **botright) + sage: tq = text(r'$Q = (\frac{\sqrt{2}}{2}, \frac{\sqrt{2}}{2})$', + ....: (a, a), **botleft) sage: A + PQ + tp + tq Graphics object consisting of 4 graphics primitives From 7352e55253bc9766dc28b82b59134ada3037b562 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 17 Jun 2023 21:34:03 -0700 Subject: [PATCH 05/21] src/sage/plot/point.py: Fix up doctest formatting --- src/sage/plot/point.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/plot/point.py b/src/sage/plot/point.py index 19af77e3296..3b3d5821ba6 100644 --- a/src/sage/plot/point.py +++ b/src/sage/plot/point.py @@ -8,7 +8,7 @@ sage: P = E(0,0) # optional - sage.schemes sage: def get_points(n): ....: return sum(point(list(i*P)[:2], size=3) -....: for i in range(-n,n) if i != 0 and (i*P)[0] < 3) + ....: for i in range(-n,n) if i != 0 and (i*P)[0] < 3) sage: sum(get_points(15*n).plot3d(z=n) for n in range(1,10)) # optional - sage.schemes Graphics3d Object """ From 59900f2c4941ff2a49c618d6d24adfe9008c626f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 18 Jun 2023 13:24:07 -0700 Subject: [PATCH 06/21] sage.plot: More # optional --- src/sage/plot/animate.py | 140 +++--- src/sage/plot/arrow.py | 3 +- src/sage/plot/bezier_path.py | 8 +- src/sage/plot/circle.py | 35 +- src/sage/plot/complex_plot.pyx | 18 +- src/sage/plot/contour_plot.py | 1 + src/sage/plot/density_plot.py | 1 + src/sage/plot/disk.py | 21 +- src/sage/plot/ellipse.py | 6 +- src/sage/plot/graphics.py | 502 ++++++++++---------- src/sage/plot/hyperbolic_arc.py | 1 + src/sage/plot/hyperbolic_polygon.py | 1 + src/sage/plot/hyperbolic_regular_polygon.py | 1 + src/sage/plot/line.py | 40 +- src/sage/plot/matrix_plot.py | 42 +- src/sage/plot/misc.py | 1 + src/sage/plot/multigraphics.py | 2 +- src/sage/plot/plot.py | 1 + src/sage/plot/plot3d/base.pyx | 65 +-- src/sage/plot/plot3d/index_face_set.pyx | 56 +-- src/sage/plot/plot3d/parametric_plot3d.py | 2 +- src/sage/plot/plot3d/parametric_surface.pyx | 7 +- src/sage/plot/plot3d/platonic.py | 15 +- src/sage/plot/plot3d/plot_field3d.py | 2 +- src/sage/plot/plot3d/revolution_plot3d.py | 1 + src/sage/plot/plot3d/shapes2.py | 10 +- src/sage/plot/plot3d/tachyon.py | 6 +- 27 files changed, 549 insertions(+), 439 deletions(-) diff --git a/src/sage/plot/animate.py b/src/sage/plot/animate.py index 3d5f7565ebe..fb54a378545 100644 --- a/src/sage/plot/animate.py +++ b/src/sage/plot/animate.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.symbolic r""" Animated plots @@ -31,7 +31,8 @@ The sine function:: sage: x = SR.var("x") - sage: sines = [plot(c*sin(x), (-2*pi,2*pi), color=Color(c,0,0), ymin=-1, ymax=1) for c in sxrange(0,1,.2)] + sage: sines = [plot(c*sin(x), (-2*pi,2*pi), color=Color(c,0,0), ymin=-1, ymax=1) + ....: for c in sxrange(0,1,.2)] sage: a = animate(sines) sage: print(a) Animation with 5 frames @@ -48,15 +49,20 @@ An animated :class:`sage.plot.multigraphics.GraphicsArray` of rotating ellipses:: - sage: E = animate((graphics_array([[ellipse((0,0),a,b,angle=t,xmin=-3,xmax=3)+circle((0,0),3,color='blue') for a in range(1,3)] for b in range(2,4)]) for t in sxrange(0,pi/4,.15))) + sage: E = animate((graphics_array([[ellipse((0,0), a, b, angle=t, xmin=-3, xmax=3) + ....: + circle((0,0), 3, color='blue') + ....: for a in range(1,3)] + ....: for b in range(2,4)]) + ....: for t in sxrange(0, pi/4, .15))) sage: str(E) # animations produced from a generator do not have a known length 'Animation with unknown number of frames' sage: E.show() # long time # optional -- ImageMagick A simple animation of a circle shooting up to the right:: - sage: c = animate([circle((i,i), 1-1/(i+1), hue=i/10) for i in srange(0,2,0.2)], - ....: xmin=0,ymin=0,xmax=2,ymax=2,figsize=[2,2]) + sage: c = animate([circle((i,i), 1 - 1/(i+1), hue=i/10) + ....: for i in srange(0, 2, 0.2)], + ....: xmin=0, ymin=0, xmax=2, ymax=2, figsize=[2,2]) sage: c.show() # long time # optional -- ImageMagick @@ -64,8 +70,11 @@ sage: s,t = SR.var("s,t") sage: def sphere_and_plane(x): - ....: return sphere((0,0,0),1,color='red',opacity=.5)+parametric_plot3d([t,x,s],(s,-1,1),(t,-1,1),color='green',opacity=.7) - sage: sp = animate([sphere_and_plane(x) for x in sxrange(-1,1,.3)]) + ....: return (sphere((0,0,0), 1, color='red', opacity=.5) + ....: + parametric_plot3d([t,x,s], (s,-1,1), (t,-1,1), + ....: color='green', opacity=.7)) + sage: sp = animate([sphere_and_plane(x) + ....: for x in sxrange(-1, 1, .3)]) sage: sp[0] # first frame Graphics3d Object sage: sp[-1] # last frame @@ -74,9 +83,13 @@ sage: (x,y,z) = SR.var("x,y,z") sage: def frame(t): - ....: return implicit_plot3d((x^2 + y^2 + z^2), (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=60, contour=[1,3,5], region=lambda x,y,z: x<=t or y>=t or z<=t) - sage: a = animate([frame(t) for t in srange(.01,1.5,.2)]) - sage: a[0] # long time + ....: return implicit_plot3d((x^2 + y^2 + z^2), + ....: (x, -2, 2), (y, -2, 2), (z, -2, 2), + ....: plot_points=60, contour=[1,3,5], + ....: region=lambda x,y,z: x<=t or y>=t or z<=t) + sage: a = animate([frame(t) + ....: for t in srange(.01,1.5,.2)]) + sage: a[0] # long time Graphics3d Object sage: a.show() # long time # optional -- ImageMagick @@ -86,7 +99,8 @@ illustrated by the following example:: sage: t = SR.var("t") - sage: a = animate((sin(c*pi*t) for c in sxrange(1,2,.2))) + sage: a = animate((sin(c*pi*t) + ....: for c in sxrange(1, 2, .2))) sage: a.show() # long time # optional -- ImageMagick @@ -135,7 +149,8 @@ def animate(frames, **kwds): EXAMPLES:: sage: t = SR.var("t") - sage: a = animate((cos(c*pi*t) for c in sxrange(1,2,.2))) + sage: a = animate((cos(c*pi*t) + ....: for c in sxrange(1, 2, .2))) sage: a.show() # long time # optional -- ImageMagick See also :mod:`sage.plot.animate` for more examples. @@ -149,22 +164,23 @@ class Animation(WithEqualityById, SageObject): INPUT: - - ``v`` - iterable of Sage objects. These should preferably be - graphics objects, but if they aren't then :meth:`make_image` is + - ``v`` -- iterable of Sage objects. These should preferably be + graphics objects, but if they aren't, then :meth:`make_image` is called on them. - - ``xmin, xmax, ymin, ymax`` - the ranges of the x and y axes. + - ``xmin, xmax, ymin, ymax`` -- the ranges of the x and y axes. - - ``**kwds`` - all additional inputs are passed onto the rendering - command. E.g., use figsize to adjust the resolution and aspect + - ``**kwds`` -- all additional inputs are passed onto the rendering + command. E.g., use ``figsize`` to adjust the resolution and aspect ratio. EXAMPLES:: sage: x = SR.var("x") - sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.3)], - ....: xmin=0, xmax=2*pi, figsize=[2,1]) + sage: a = animate([sin(x + float(k)) + ....: for k in srange(0, 2*pi, 0.3)], + ....: xmin=0, xmax=2*pi, figsize=[2,1]) sage: print(a) Animation with 21 frames sage: print(a[:5]) @@ -185,9 +201,9 @@ class Animation(WithEqualityById, SageObject): sage: step = 0.1 sage: L = Graphics() sage: v = [] - sage: for i in srange(0,1,step): - ....: L += line([(i,i^2),(i+step,(i+step)^2)], rgbcolor=(1,0,0), thickness=2) - ....: v.append(L) + sage: for i in srange(0, 1, step): + ....: L += line([(i,i^2),(i+step,(i+step)^2)], rgbcolor=(1,0,0), thickness=2) + ....: v.append(L) sage: a = animate(v, xmin=0, ymin=0) sage: a.show() # long time # optional -- ImageMagick sage: show(L) @@ -427,7 +443,9 @@ def make_image(self, frame, filename, **kwds): sage: t = SR.var("t") sage: x = lambda t: cos(t) sage: y = lambda n,t: sin(t)/n - sage: B = MyAnimation([([x(t), y(i+1,t)],(t,0,1), {'color':Color((1,0,i/4)), 'aspect_ratio':1, 'ymax':1}) for i in range(4)]) + sage: B = MyAnimation([([x(t), y(i+1,t)], (t,0,1), + ....: {'color':Color((1,0,i/4)), 'aspect_ratio':1, 'ymax':1}) + ....: for i in range(4)]) sage: d = B.png(); v = os.listdir(d); v.sort(); v # long time ['00000000.png', '00000001.png', '00000002.png', '00000003.png'] @@ -436,10 +454,12 @@ def make_image(self, frame, filename, **kwds): sage: class MyAnimation(Animation): ....: def make_image(self, frame, filename, **kwds): ....: G = frame.plot() - ....: G.set_axes_range(floor(G.xmin()),ceil(G.xmax()),floor(G.ymin()),ceil(G.ymax())) + ....: G.set_axes_range(floor(G.xmin()), ceil(G.xmax()), + ....: floor(G.ymin()), ceil(G.ymax())) ....: G.save_image(filename, **kwds) - sage: B = MyAnimation([graphs.CompleteGraph(n) for n in range(7,11)], figsize=5) + sage: B = MyAnimation([graphs.CompleteGraph(n) + ....: for n in range(7,11)], figsize=5) sage: d = B.png() sage: v = os.listdir(d); v.sort(); v ['00000000.png', '00000001.png', '00000002.png', '00000003.png'] @@ -506,26 +526,27 @@ def graphics_array(self, ncols=3): EXAMPLES:: - sage: E = EllipticCurve('37a') - sage: v = [E.change_ring(GF(p)).plot(pointsize=30) for p in [97, 101, 103]] - sage: a = animate(v, xmin=0, ymin=0, axes=False) - sage: print(a) + sage: E = EllipticCurve('37a') # optional - sage.schemes + sage: v = [E.change_ring(GF(p)).plot(pointsize=30) # optional - sage.rings.finite_rings sage.schemes + ....: for p in [97, 101, 103]] + sage: a = animate(v, xmin=0, ymin=0, axes=False) # optional - sage.rings.finite_rings sage.schemes + sage: print(a) # optional - sage.rings.finite_rings sage.schemes Animation with 3 frames - sage: a.show() # optional -- ImageMagick + sage: a.show() # optional -- ImageMagick # optional - sage.rings.finite_rings sage.schemes Modify the default arrangement of array:: - sage: g = a.graphics_array(); print(g) + sage: g = a.graphics_array(); print(g) # optional - sage.rings.finite_rings sage.schemes Graphics Array of size 1 x 3 - sage: g.show(figsize=[6,3]) + sage: g.show(figsize=[6,3]) # optional - sage.rings.finite_rings sage.schemes Specify different arrangement of array and save it with a given file name:: - sage: g = a.graphics_array(ncols=2); print(g) + sage: g = a.graphics_array(ncols=2); print(g) # optional - sage.rings.finite_rings sage.schemes Graphics Array of size 2 x 2 - sage: f = tmp_filename(ext='.png'); print(f) + sage: f = tmp_filename(ext='.png'); print(f) # optional - sage.rings.finite_rings sage.schemes ...png - sage: g.save(f) + sage: g.save(f) # optional - sage.rings.finite_rings sage.schemes Frames can be specified as a generator too; it is internally converted to a list:: @@ -580,16 +601,21 @@ def gif(self, delay=20, savefile=None, iterations=0, show_path=False, EXAMPLES:: sage: x = SR.var("x") - sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)], + sage: a = animate([sin(x + float(k)) + ....: for k in srange(0,2*pi,0.7)], ....: xmin=0, xmax=2*pi, ymin=-1, ymax=1, figsize=[2,1]) sage: td = tmp_dir() sage: a.gif() # not tested - sage: a.gif(savefile=td + 'my_animation.gif', delay=35, iterations=3) # long time # optional -- ImageMagick - sage: with open(td + 'my_animation.gif', 'rb') as f: print(b'GIF8' in f.read()) # long time # optional -- ImageMagick + sage: a.gif(savefile=td + 'my_animation.gif', # long time # optional -- ImageMagick + ....: delay=35, iterations=3) + sage: with open(td + 'my_animation.gif', 'rb') as f: # long time # optional -- ImageMagick + ....: print(b'GIF8' in f.read()) True - sage: a.gif(savefile=td + 'my_animation.gif', show_path=True) # long time # optional -- ImageMagick + sage: a.gif(savefile=td + 'my_animation.gif', # long time # optional -- ImageMagick + ....: show_path=True) Animation saved to .../my_animation.gif. - sage: a.gif(savefile=td + 'my_animation_2.gif', show_path=True, use_ffmpeg=True) # long time # optional -- ffmpeg + sage: a.gif(savefile=td + 'my_animation_2.gif', # long time # optional -- ffmpeg + ....: show_path=True, use_ffmpeg=True) Animation saved to .../my_animation_2.gif. .. NOTE:: @@ -810,8 +836,9 @@ def show(self, delay=None, iterations=None, **kwds): EXAMPLES:: sage: x = SR.var("x") - sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)], - ....: xmin=0, xmax=2*pi, figsize=[2,1]) + sage: a = animate([sin(x + float(k)) + ....: for k in srange(0,2*pi,0.7)], + ....: xmin=0, xmax=2*pi, figsize=[2,1]) sage: a.show() # long time # optional -- ImageMagick The preceding will loop the animation forever. If you want to show @@ -922,7 +949,8 @@ def ffmpeg(self, savefile=None, show_path=False, output_format=None, EXAMPLES:: sage: x = SR.var("x") - sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)], + sage: a = animate([sin(x + float(k)) + ....: for k in srange(0, 2*pi, 0.7)], ....: xmin=0, xmax=2*pi, ymin=-1, ymax=1, figsize=[2,1]) sage: td = tmp_dir() sage: a.ffmpeg(savefile=td + 'new.mpg') # long time # optional -- ffmpeg @@ -1042,8 +1070,9 @@ def apng(self, savefile=None, show_path=False, delay=20, iterations=0): EXAMPLES:: sage: x = SR.var("x") - sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)], - ....: xmin=0, xmax=2*pi, figsize=[2,1]) + sage: a = animate([sin(x + float(k)) + ....: for k in srange(0,2*pi,0.7)], + ....: xmin=0, xmax=2*pi, figsize=[2,1]) sage: dir = tmp_dir() sage: a.apng(show_path=True) # long time Animation saved to ....png. @@ -1053,7 +1082,8 @@ def apng(self, savefile=None, show_path=False, delay=20, iterations=0): If the individual frames have different sizes, an error will be raised:: - sage: a = animate([plot(sin(x), (x, 0, k)) for k in range(1,4)], + sage: a = animate([plot(sin(x), (x, 0, k)) + ....: for k in range(1,4)], ....: ymin=-1, ymax=1, aspect_ratio=1, figsize=[2,1]) sage: a.apng() # long time Traceback (most recent call last): @@ -1111,7 +1141,8 @@ def save(self, filename=None, show_path=False, use_ffmpeg=False, **kwds): EXAMPLES:: sage: x = SR.var("x") - sage: a = animate([sin(x + float(k)) for k in srange(0,2*pi,0.7)], + sage: a = animate([sin(x + float(k)) + ....: for k in srange(0, 2*pi, 0.7)], ....: xmin=0, xmax=2*pi, ymin=-1, ymax=1, figsize=[2,1]) sage: td = tmp_dir() sage: a.save() # not tested @@ -1194,7 +1225,8 @@ def interactive(self, **kwds): EXAMPLES:: sage: x = SR.var("x") - sage: frames = [point3d((sin(x), cos(x), x)) for x in (0, pi/16, .., 2*pi)] + sage: frames = [point3d((sin(x), cos(x), x)) + ....: for x in (0, pi/16, .., 2*pi)] sage: animate(frames).interactive(online=True) Graphics3d Object @@ -1245,16 +1277,16 @@ class APngAssembler(): INPUT: - - ``out`` -- a file opened for binary writing to which the data - will be written + - ``out`` -- a file opened for binary writing to which the data + will be written - - ``num_frames`` -- the number of frames in the animation + - ``num_frames`` -- the number of frames in the animation - - ``num_plays`` -- how often to iterate, 0 means infinitely + - ``num_plays`` -- how often to iterate, 0 means infinitely - - ``delay`` -- numerator of the delay fraction in seconds + - ``delay`` -- numerator of the delay fraction in seconds - - ``delay_denominator`` -- denominator of the delay in seconds + - ``delay_denominator`` -- denominator of the delay in seconds EXAMPLES:: diff --git a/src/sage/plot/arrow.py b/src/sage/plot/arrow.py index 0d09c2881d9..c2e08d38dd8 100644 --- a/src/sage/plot/arrow.py +++ b/src/sage/plot/arrow.py @@ -586,7 +586,8 @@ def arrow2d(tailpoint=None, headpoint=None, path=None, **options): A pretty circle of arrows:: - sage: sum([arrow2d((0,0), (cos(x),sin(x)), hue=x/(2*pi)) for x in [0..2*pi,step=0.1]]) + sage: sum(arrow2d((0,0), (cos(x),sin(x)), hue=x/(2*pi)) # optional - sage.symbolic + ....: for x in [0..2*pi, step=0.1]) Graphics object consisting of 63 graphics primitives .. PLOT:: diff --git a/src/sage/plot/bezier_path.py b/src/sage/plot/bezier_path.py index 27c95f10c0c..cbaa4de4049 100644 --- a/src/sage/plot/bezier_path.py +++ b/src/sage/plot/bezier_path.py @@ -168,9 +168,9 @@ def plot3d(self, z=0, **kwds): EXAMPLES:: sage: b = bezier_path([[(0,0),(0,1),(1,0)]]) - sage: A = b.plot3d() - sage: B = b.plot3d(z=2) - sage: A + B + sage: A = b.plot3d() # optional - sage.symbolic + sage: B = b.plot3d(z=2) # optional - sage.symbolic + sage: A + B # optional - sage.symbolic Graphics3d Object .. PLOT:: @@ -182,7 +182,7 @@ def plot3d(self, z=0, **kwds): :: - sage: bezier3d([[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]]) + sage: bezier3d([[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]]) # optional - sage.symbolic Graphics3d Object .. PLOT:: diff --git a/src/sage/plot/circle.py b/src/sage/plot/circle.py index 1dc58e02e39..512080a6ed8 100644 --- a/src/sage/plot/circle.py +++ b/src/sage/plot/circle.py @@ -25,18 +25,18 @@ class Circle(GraphicPrimitive): """ - Primitive class for the Circle graphics type. See circle? for information + Primitive class for the :class:`Circle` graphics type. See ``circle?`` for information about actually plotting circles. INPUT: - - x -- `x`-coordinate of center of Circle + - ``x`` -- `x`-coordinate of center of Circle - - y -- `y`-coordinate of center of Circle + - ``y`` -- `y`-coordinate of center of Circle - - r -- radius of Circle object + - ``r`` -- radius of Circle object - - options -- dict of valid plot options to pass to constructor + - ``options`` -- dict of valid plot options to pass to constructor EXAMPLES: @@ -80,7 +80,7 @@ def __init__(self, x, y, r, options): def get_minmax_data(self): """ - Returns a dictionary with the bounding box data. + Return a dictionary with the bounding box data. EXAMPLES:: @@ -139,6 +139,7 @@ def _render_on_subplot(self, subplot): """ TESTS:: + sage: from math import pi sage: C = circle((2,pi), 2, edgecolor='black', facecolor='green', fill=True) """ import matplotlib.patches as patches @@ -182,7 +183,8 @@ def plot3d(self, z=0, **kwds): This example uses this method implicitly, but does not pass the optional parameter z to this method:: - sage: sum([circle((random(),random()), random()).plot3d(z=random()) for _ in range(20)]) + sage: sum(circle((random(),random()), random()).plot3d(z=random()) + ....: for _ in range(20)) Graphics3d Object .. PLOT:: @@ -192,6 +194,7 @@ def plot3d(self, z=0, **kwds): These examples are explicit, and pass z to this method:: + sage: from math import pi sage: C = circle((2,pi), 2, hue=.8, alpha=.3, fill=True) sage: c = C[0] sage: d = c.plot3d(z=2) @@ -304,14 +307,16 @@ def circle(center, radius, **options): Here we make a more complicated plot, with many circles of different colors:: sage: g = Graphics() - sage: step=6; ocur=1/5; paths=16 + sage: step = 6; ocur = 1/5; paths = 16 sage: PI = math.pi # numerical for speed -- fine for graphics sage: for r in range(1,paths+1): - ....: for x,y in [((r+ocur)*math.cos(n), (r+ocur)*math.sin(n)) for n in srange(0, 2*PI+PI/step, PI/step)]: + ....: for x,y in [((r+ocur)*math.cos(n), (r+ocur)*math.sin(n)) + ....: for n in srange(0, 2*PI+PI/step, PI/step)]: ....: g += circle((x,y), ocur, rgbcolor=hue(r/paths)) ....: rnext = (r+1)^2 ....: ocur = (rnext-r)-ocur - sage: g.show(xmin=-(paths+1)^2, xmax=(paths+1)^2, ymin=-(paths+1)^2, ymax=(paths+1)^2, figsize=[6,6]) + sage: g.show(xmin=-(paths+1)^2, xmax=(paths+1)^2, + ....: ymin=-(paths+1)^2, ymax=(paths+1)^2, figsize=[6,6]) .. PLOT:: @@ -358,7 +363,8 @@ def circle(center, radius, **options): And circles with legends:: - sage: circle((4,5), 1, rgbcolor='yellow', fill=True, legend_label='the sun').show(xmin=0, ymin=0) + sage: circle((4,5), 1, rgbcolor='yellow', fill=True, + ....: legend_label='the sun').show(xmin=0, ymin=0) .. PLOT:: @@ -368,7 +374,8 @@ def circle(center, radius, **options): :: - sage: circle((4,5), 1, legend_label='the sun', legend_color='yellow').show(xmin=0, ymin=0) + sage: circle((4,5), 1, + ....: legend_label='the sun', legend_color='yellow').show(xmin=0, ymin=0) .. PLOT:: @@ -378,12 +385,12 @@ def circle(center, radius, **options): Extra options will get passed on to show(), as long as they are valid:: - sage: circle((0, 0), 2, figsize=[10,10]) # That circle is huge! + sage: circle((0, 0), 2, figsize=[10,10]) # That circle is huge! Graphics object consisting of 1 graphics primitive :: - sage: circle((0, 0), 2).show(figsize=[10,10]) # These are equivalent + sage: circle((0, 0), 2).show(figsize=[10,10]) # These are equivalent TESTS: diff --git a/src/sage/plot/complex_plot.pyx b/src/sage/plot/complex_plot.pyx index e17c970d521..933bcea9894 100644 --- a/src/sage/plot/complex_plot.pyx +++ b/src/sage/plot/complex_plot.pyx @@ -1143,14 +1143,14 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Test to make sure that using fast_callable functions works:: - sage: f(x) = x^2 - sage: g = fast_callable(f, domain=CC, vars='x') - sage: h = fast_callable(f, domain=CDF, vars='x') - sage: P = complex_plot(f, (-10, 10), (-10, 10)) - sage: Q = complex_plot(g, (-10, 10), (-10, 10)) - sage: R = complex_plot(h, (-10, 10), (-10, 10)) - sage: S = complex_plot(exp(x)-sin(x), (-10, 10), (-10, 10)) - sage: P; Q; R; S + sage: f(x) = x^2 # optional - sage.symbolic + sage: g = fast_callable(f, domain=CC, vars='x') # optional - sage.symbolic + sage: h = fast_callable(f, domain=CDF, vars='x') # optional - sage.symbolic + sage: P = complex_plot(f, (-10, 10), (-10, 10)) # optional - sage.symbolic + sage: Q = complex_plot(g, (-10, 10), (-10, 10)) # optional - sage.symbolic + sage: R = complex_plot(h, (-10, 10), (-10, 10)) # optional - sage.symbolic + sage: S = complex_plot(exp(x)-sin(x), (-10, 10), (-10, 10)) # optional - sage.symbolic + sage: P; Q; R; S # optional - sage.symbolic Graphics object consisting of 1 graphics primitive Graphics object consisting of 1 graphics primitive Graphics object consisting of 1 graphics primitive @@ -1162,7 +1162,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, :: - sage: complex_plot(sqrt, (-5, 5), (-5, 5)) + sage: complex_plot(sqrt, (-5, 5), (-5, 5)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive """ import matplotlib as mpl diff --git a/src/sage/plot/contour_plot.py b/src/sage/plot/contour_plot.py index 9a46eaefe76..b909dc3d7b4 100644 --- a/src/sage/plot/contour_plot.py +++ b/src/sage/plot/contour_plot.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic """ Contour plots """ diff --git a/src/sage/plot/density_plot.py b/src/sage/plot/density_plot.py index 155ac8d7a8e..bf4f26aec2f 100644 --- a/src/sage/plot/density_plot.py +++ b/src/sage/plot/density_plot.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic """ Density plots """ diff --git a/src/sage/plot/disk.py b/src/sage/plot/disk.py index d84b883d6e2..91891b84550 100644 --- a/src/sage/plot/disk.py +++ b/src/sage/plot/disk.py @@ -46,10 +46,12 @@ class Disk(GraphicPrimitive): Note this should normally be used indirectly via ``disk``:: + sage: from math import pi sage: from sage.plot.disk import Disk sage: D = Disk((1,2), 2, (pi/2,pi), {'zorder':3}) sage: D - Disk defined by (1.0,2.0) with r=2.0 spanning (1.5707963267..., 3.1415926535...) radians + Disk defined by (1.0,2.0) with r=2.0 + spanning (1.5707963267..., 3.1415926535...) radians sage: D.options()['zorder'] 3 sage: D.x @@ -68,6 +70,7 @@ def __init__(self, point, r, angle, options): EXAMPLES:: + sage: from math import pi sage: D = disk((2,3), 1, (pi/2, pi), fill=False, color='red', thickness=1, alpha=.5) sage: D[0].x 2.0 @@ -95,6 +98,7 @@ def get_minmax_data(self): EXAMPLES:: + sage: from math import pi sage: D = disk((5,4), 1, (pi/2, pi)) sage: d = D.get_minmax_data() sage: d['xmin'] @@ -118,6 +122,7 @@ def _allowed_options(self): EXAMPLES:: + sage: from math import pi sage: p = disk((3, 3), 1, (0, pi/2)) sage: p[0]._allowed_options()['alpha'] 'How transparent the figure is.' @@ -139,6 +144,7 @@ def _repr_(self): EXAMPLES:: + sage: from math import pi sage: P = disk((3, 3), 1, (0, pi/2)) sage: p = P[0]; p Disk defined by (3.0,3.0) with r=1.0 spanning (0.0, 1.5707963267...) radians @@ -149,6 +155,7 @@ def _render_on_subplot(self, subplot): """ TESTS:: + sage: from math import pi sage: D = disk((2,-1), 2, (0, pi), color='black', thickness=3, fill=False); D Graphics object consisting of 1 graphics primitive @@ -192,6 +199,7 @@ def plot3d(self, z=0, **kwds): EXAMPLES:: + sage: from math import pi sage: disk((0,0), 1, (0, pi/2)).plot3d() Graphics3d Object sage: disk((0,0), 1, (0, pi/2)).plot3d(z=2) @@ -253,12 +261,13 @@ def disk(point, radius, angle, **options): Make some dangerous disks:: + sage: from math import pi sage: bl = disk((0.0,0.0), 1, (pi, 3*pi/2), color='yellow') sage: tr = disk((0.0,0.0), 1, (0, pi/2), color='yellow') sage: tl = disk((0.0,0.0), 1, (pi/2, pi), color='black') sage: br = disk((0.0,0.0), 1, (3*pi/2, 2*pi), color='black') - sage: P = tl+tr+bl+br - sage: P.show(xmin=-2,xmax=2,ymin=-2,ymax=2) + sage: P = tl + tr + bl + br + sage: P.show(xmin=-2, xmax=2, ymin=-2, ymax=2) .. PLOT:: @@ -318,9 +327,11 @@ def disk(point, radius, angle, **options): Extra options will get passed on to ``show()``, as long as they are valid:: - sage: disk((0, 0), 5, (0, pi/2), xmin=0, xmax=5, ymin=0, ymax=5, figsize=(2,2), rgbcolor=(1, 0, 1)) + sage: disk((0, 0), 5, (0, pi/2), rgbcolor=(1, 0, 1), + ....: xmin=0, xmax=5, ymin=0, ymax=5, figsize=(2,2)) Graphics object consisting of 1 graphics primitive - sage: disk((0, 0), 5, (0, pi/2), rgbcolor=(1, 0, 1)).show(xmin=0, xmax=5, ymin=0, ymax=5, figsize=(2,2)) # These are equivalent + sage: disk((0, 0), 5, (0, pi/2), rgbcolor=(1, 0, 1)).show( # These are equivalent + ....: xmin=0, xmax=5, ymin=0, ymax=5, figsize=(2,2)) TESTS: diff --git a/src/sage/plot/ellipse.py b/src/sage/plot/ellipse.py index c35bed574ef..6d99cc90401 100644 --- a/src/sage/plot/ellipse.py +++ b/src/sage/plot/ellipse.py @@ -41,6 +41,7 @@ class Ellipse(GraphicPrimitive): Note that this construction should be done using ``ellipse``:: + sage: from math import pi sage: from sage.plot.ellipse import Ellipse sage: Ellipse(0, 0, 2, 1, pi/4, {}) Ellipse centered at (0.0, 0.0) with radii (2.0, 1.0) and angle 0.78539816339... @@ -94,6 +95,7 @@ def get_minmax_data(self): The same example with a rotation of angle `\pi/2`:: + sage: from math import pi sage: p = ellipse((-2, 3), 1, 2, pi/2) sage: d = p.get_minmax_data() sage: d['xmin'] @@ -178,6 +180,7 @@ def _render_on_subplot(self, subplot): TESTS:: + sage: from math import pi sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3) Graphics object consisting of 1 graphics primitive @@ -280,7 +283,8 @@ def ellipse(center, r1, r2, angle=0, **options): More complicated examples with tilted axes and drawing options:: - sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3,linestyle="dashed") + sage: from math import pi + sage: ellipse((0,0), 3, 1, pi/6, fill=True, alpha=0.3, linestyle="dashed") Graphics object consisting of 1 graphics primitive .. PLOT:: diff --git a/src/sage/plot/graphics.py b/src/sage/plot/graphics.py index cdc99ced263..1070d9e262e 100644 --- a/src/sage/plot/graphics.py +++ b/src/sage/plot/graphics.py @@ -130,23 +130,23 @@ class Graphics(WithEqualityById, SageObject): sage: G = Graphics(); print(G) Graphics object consisting of 0 graphics primitives sage: c = circle((1,1), 1) - sage: G+=c; print(G) + sage: G += c; print(G) Graphics object consisting of 1 graphics primitive Here we make a graphic of embedded isosceles triangles, coloring each one with a different color as we go:: - sage: h=10; c=0.4; p=0.5 + sage: h = 10; c = 0.4; p = 0.5 sage: G = Graphics() - sage: for x in srange(1,h+1): + sage: for x in srange(1, h+1): # optional - sage.symbolic ....: l = [[0,x*sqrt(3)],[-x/2,-x*sqrt(3)/2],[x/2,-x*sqrt(3)/2],[0,x*sqrt(3)]] - ....: G+=line(l,color=hue(c + p*(x/h))) - sage: G.show(figsize=[5,5]) + ....: G + =line(l, color=hue(c + p*(x/h))) + sage: G.show(figsize=[5,5]) # optional - sage.symbolic We can change the scale of the axes in the graphics before displaying.:: - sage: G = plot(exp, 1, 10) # long time - sage: G.show(scale='semilogy') # long time + sage: G = plot(exp, 1, 10) # long time # optional - sage.symbolic + sage: G.show(scale='semilogy') # long time # optional - sage.symbolic TESTS: @@ -212,32 +212,32 @@ def set_aspect_ratio(self, ratio): EXAMPLES: We create a plot of the upper half of a circle, but it doesn't look round because the aspect ratio is off:: - sage: P = plot(sqrt(1-x^2),(x,-1,1)); P + sage: P = plot(sqrt(1-x^2),(x,-1,1)); P # optional - sage.symbolic Graphics object consisting of 1 graphics primitive So we set the aspect ratio and now it is round:: - sage: P.set_aspect_ratio(1) - sage: P.aspect_ratio() + sage: P.set_aspect_ratio(1) # optional - sage.symbolic + sage: P.aspect_ratio() # optional - sage.symbolic 1.0 - sage: P + sage: P # optional - sage.symbolic Graphics object consisting of 1 graphics primitive Note that the aspect ratio is inherited upon addition (which takes the max of aspect ratios of objects whose aspect ratio has been set):: - sage: P + plot(sqrt(4-x^2),(x,-2,2)) + sage: P + plot(sqrt(4-x^2),(x,-2,2)) # optional - sage.symbolic Graphics object consisting of 2 graphics primitives In the following example, both plots produce a circle that looks twice as tall as wide:: sage: Q = circle((0,0), 0.5); Q.set_aspect_ratio(2) - sage: (P + Q).aspect_ratio(); P+Q + sage: (P + Q).aspect_ratio(); P + Q # optional - sage.symbolic 2.0 Graphics object consisting of 2 graphics primitives - sage: (Q + P).aspect_ratio(); Q+P + sage: (Q + P).aspect_ratio(); Q + P # optional - sage.symbolic 2.0 Graphics object consisting of 2 graphics primitives """ @@ -252,20 +252,20 @@ def set_aspect_ratio(self, ratio): def aspect_ratio(self): """ Get the current aspect ratio, which is the ratio of height to - width of a unit square, or 'automatic'. + width of a unit square, or ``'automatic'``. - OUTPUT: a positive float (height/width of a unit square), or 'automatic' + OUTPUT: a positive float (height/width of a unit square), or ``'automatic'`` (expand to fill the figure). EXAMPLES: - The default aspect ratio for a new blank Graphics object is 'automatic':: + The default aspect ratio for a new blank :class:`Graphics` object is ``'automatic'``:: sage: P = Graphics() sage: P.aspect_ratio() 'automatic' - The aspect ratio can be explicitly set different than the object's default:: + The aspect ratio can be explicitly set different from the object's default:: sage: P = circle((1,1), 1) sage: P.aspect_ratio() @@ -285,7 +285,7 @@ def legend(self, show=None): INPUT: - - ``show`` - (default: None) a boolean + - ``show`` -- (default: ``None``) a boolean If called with no input, return the current legend setting. @@ -293,23 +293,23 @@ def legend(self, show=None): By default no legend is displayed:: - sage: P = plot(sin) - sage: P.legend() + sage: P = plot(sin) # optional - sage.symbolic + sage: P.legend() # optional - sage.symbolic False But if we put a label then the legend is shown:: - sage: P = plot(sin, legend_label='sin') - sage: P.legend() + sage: P = plot(sin, legend_label='sin') # optional - sage.symbolic + sage: P.legend() # optional - sage.symbolic True We can turn it on or off:: - sage: P.legend(False) - sage: P.legend() + sage: P.legend(False) # optional - sage.symbolic + sage: P.legend() # optional - sage.symbolic False - sage: P.legend(True) - sage: P # show with the legend + sage: P.legend(True) # optional - sage.symbolic + sage: P # show with the legend # optional - sage.symbolic Graphics object consisting of 1 graphics primitive """ if show is None: @@ -405,30 +405,30 @@ def set_legend_options(self, **kwds): By default, no options are set:: - sage: p = plot(tan, legend_label='tan') - sage: p.set_legend_options() + sage: p = plot(tan, legend_label='tan') # optional - sage.symbolic + sage: p.set_legend_options() # optional - sage.symbolic {} We build a legend without a shadow:: - sage: p.set_legend_options(shadow=False) - sage: p.set_legend_options()['shadow'] + sage: p.set_legend_options(shadow=False) # optional - sage.symbolic + sage: p.set_legend_options()['shadow'] # optional - sage.symbolic False To set the legend position to the center of the plot, all these methods are roughly equivalent:: - sage: p.set_legend_options(loc='center'); p + sage: p.set_legend_options(loc='center'); p # optional - sage.symbolic Graphics object consisting of 1 graphics primitive :: - sage: p.set_legend_options(loc=10); p + sage: p.set_legend_options(loc=10); p # optional - sage.symbolic Graphics object consisting of 1 graphics primitive :: - sage: p.set_legend_options(loc=(0.5,0.5)); p # aligns the bottom of the box to the center + sage: p.set_legend_options(loc=(0.5,0.5)); p # aligns the bottom of the box to the center # optional - sage.symbolic Graphics object consisting of 1 graphics primitive """ if len(kwds) == 0: @@ -623,16 +623,16 @@ def axes_labels_size(self, s=None): EXAMPLES:: - sage: p = plot(sin(x^2), (x, -3, 3), axes_labels=['$x$','$y$']) - sage: p.axes_labels_size() # default value + sage: p = plot(sin(x^2), (x, -3, 3), axes_labels=['$x$','$y$']) # optional - sage.symbolic + sage: p.axes_labels_size() # default value # optional - sage.symbolic 1.6 - sage: p.axes_labels_size(2.5) - sage: p.axes_labels_size() + sage: p.axes_labels_size(2.5) # optional - sage.symbolic + sage: p.axes_labels_size() # optional - sage.symbolic 2.5 Now the axes labels are large w.r.t. the tick marks:: - sage: p + sage: p # optional - sage.symbolic Graphics object consisting of 1 graphics primitive """ @@ -759,20 +759,20 @@ def axes_labels(self, l=None): :: - sage: p = plot(sin(x), (x, 0, 10)) - sage: p.axes_labels(['$x$','$y$']) - sage: p.axes_labels() + sage: p = plot(sin(x), (x, 0, 10)) # optional - sage.symbolic + sage: p.axes_labels(['$x$','$y$']) # optional - sage.symbolic + sage: p.axes_labels() # optional - sage.symbolic ('$x$', '$y$') Now when you plot p, you see x and y axes labels:: - sage: p + sage: p # optional - sage.symbolic Graphics object consisting of 1 graphics primitive Notice that some may prefer axes labels which are not typeset:: - sage: plot(sin(x), (x, 0, 10), axes_labels=['x','y']) + sage: plot(sin(x), (x, 0, 10), axes_labels=['x','y']) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive TESTS: @@ -805,7 +805,7 @@ def axes_label_color(self, c=None): Set the color of the axes labels. The axes labels are placed at the edge of the x and y axes, and are - not on by default (use the ``axes_labels`` command to + not on by default (use the :meth:`axes_labels` command to set them; see the example below). This function just changes their color. @@ -823,25 +823,25 @@ def axes_label_color(self, c=None): :: - sage: p = plot(sin, (-1,1)) - sage: p.axes_label_color() + sage: p = plot(sin, (-1,1)) # optional - sage.symbolic + sage: p.axes_label_color() # optional - sage.symbolic (0, 0, 0) We change the labels to be red, and confirm this:: - sage: p.axes_label_color((1,0,0)) - sage: p.axes_label_color() + sage: p.axes_label_color((1,0,0)) # optional - sage.symbolic + sage: p.axes_label_color() # optional - sage.symbolic (1.0, 0.0, 0.0) We set labels, since otherwise we won't see anything. :: - sage: p.axes_labels(['$x$ axis', '$y$ axis']) + sage: p.axes_labels(['$x$ axis', '$y$ axis']) # optional - sage.symbolic In the plot below, notice that the labels are red:: - sage: p + sage: p # optional - sage.symbolic Graphics object consisting of 1 graphics primitive """ if c is None: @@ -860,7 +860,7 @@ def axes_width(self, w=None): INPUT: - - ``w`` - a float + - ``w`` -- a float If called with no input, return the current @@ -871,11 +871,11 @@ def axes_width(self, w=None): :: - sage: p = plot(cos, (-3,3)) - sage: p.axes_width() + sage: p = plot(cos, (-3,3)) # optional - sage.symbolic + sage: p.axes_width() # optional - sage.symbolic 0.8 - sage: p.axes_width(10) - sage: p.axes_width() + sage: p.axes_width(10) # optional - sage.symbolic + sage: p.axes_width() # optional - sage.symbolic 10.0 Finally we plot the result, which is a graph with very fat axes. @@ -908,13 +908,13 @@ def tick_label_color(self, c=None): EXAMPLES:: - sage: p = plot(cos, (-3,3)) - sage: p.tick_label_color() + sage: p = plot(cos, (-3,3)) # optional - sage.symbolic + sage: p.tick_label_color() # optional - sage.symbolic (0, 0, 0) - sage: p.tick_label_color((1,0,0)) - sage: p.tick_label_color() + sage: p.tick_label_color((1,0,0)) # optional - sage.symbolic + sage: p.tick_label_color() # optional - sage.symbolic (1.0, 0.0, 0.0) - sage: p + sage: p # optional - sage.symbolic Graphics object consisting of 1 graphics primitive """ if c is None: @@ -938,27 +938,27 @@ def _repr_(self): We create a plot and call :meth:`show` on it, which causes it to be displayed as a plot:: - sage: P = plot(cos, (-1,1)) - sage: P.show() + sage: P = plot(cos, (-1,1)) # optional - sage.symbolic + sage: P.show() # optional - sage.symbolic Just doing this also displays the plot:: - sage: P + sage: P # optional - sage.symbolic Graphics object consisting of 1 graphics primitive Using the Python `repr` or `str` commands do not display the plot:: - sage: repr(P) + sage: repr(P) # optional - sage.symbolic 'Graphics object consisting of 1 graphics primitive' - sage: str(P) + sage: str(P) # optional - sage.symbolic 'Graphics object consisting of 1 graphics primitive' - sage: print(P) + sage: print(P) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive TESTS:: - sage: P._repr_() + sage: P._repr_() # optional - sage.symbolic 'Graphics object consisting of 1 graphics primitive' """ return str(self) @@ -1071,8 +1071,8 @@ def __delitem__(self, i): def __setitem__(self, i, x): """ - You can replace a GraphicPrimitive (point, line, circle, etc...) in - a Graphics object G with any other GraphicPrimitive + You can replace a :class:`GraphicPrimitive` (point, line, circle, etc...) in + a :class:`Graphics` object G with any other :class:`GraphicPrimitive` EXAMPLES:: @@ -1125,7 +1125,7 @@ def __add__(self, other): """ If you have any Graphics object G1, you can always add any other amount of Graphics objects G2,G3,... to form a new Graphics object: - G4 = G1 + G2 + G3. + ``G4 = G1 + G2 + G3``. The xmin, xmax, ymin, and ymax properties of the graphics objects are expanded to include all objects in both scenes. If the aspect @@ -1140,50 +1140,51 @@ def __add__(self, other): EXAMPLES:: - sage: g1 = plot(abs(sqrt(x^3-1)), (x,1,5), frame=True) - sage: g2 = plot(-abs(sqrt(x^3-1)), (x,1,5), color='red') - sage: g1 + g2 # displays the plot + sage: g1 = plot(abs(sqrt(x^3-1)), (x,1,5), frame=True) # optional - sage.symbolic + sage: g2 = plot(-abs(sqrt(x^3-1)), (x,1,5), color='red') # optional - sage.symbolic + sage: g1 + g2 # displays the plot # optional - sage.symbolic Graphics object consisting of 2 graphics primitives TESTS: Extra keywords to show are propagated:: - sage: (g1 + g2)._extra_kwds=={'aspect_ratio': 'automatic', 'frame': True} + sage: (g1 + g2)._extra_kwds=={'aspect_ratio': 'automatic', 'frame': True} # optional - sage.symbolic True - sage: g1.set_aspect_ratio(2) - sage: (g1+g2).aspect_ratio() + sage: g1.set_aspect_ratio(2) # optional - sage.symbolic + sage: (g1+g2).aspect_ratio() # optional - sage.symbolic 2.0 - sage: g2.set_aspect_ratio(3) - sage: (g1+g2).aspect_ratio() + sage: g2.set_aspect_ratio(3) # optional - sage.symbolic + sage: (g1+g2).aspect_ratio() # optional - sage.symbolic 3.0 As are legend options, :trac:`12936`:: - sage: p1 = plot(x, x, 0, 1) - sage: p2 = p1 - sage: p1.set_legend_options(back_color = 'black') - sage: p2.set_legend_options(shadow = False) - sage: p3 = p1 + p2 - sage: p3._legend_opts + sage: p1 = plot(x, x, 0, 1) # optional - sage.symbolic + sage: p2 = p1 # optional - sage.symbolic + sage: p1.set_legend_options(back_color='black') # optional - sage.symbolic + sage: p2.set_legend_options(shadow=False) # optional - sage.symbolic + sage: p3 = p1 + p2 # optional - sage.symbolic + sage: p3._legend_opts # optional - sage.symbolic {'back_color': 'black', 'shadow': False} If the same legend option is specified more than once, the latter takes precedence:: - sage: p1 = plot(x, x, 0, 1) - sage: p2 = p1 - sage: p1.set_legend_options(shadow = True) - sage: p2.set_legend_options(shadow = False) - sage: p3 = p1 + p2 - sage: p3._legend_opts + sage: p1 = plot(x, x, 0, 1) # optional - sage.symbolic + sage: p2 = p1 # optional - sage.symbolic + sage: p1.set_legend_options(shadow=True) # optional - sage.symbolic + sage: p2.set_legend_options(shadow=False) # optional - sage.symbolic + sage: p3 = p1 + p2 # optional - sage.symbolic + sage: p3._legend_opts # optional - sage.symbolic {'shadow': False} Flipped axes take precedence over non-flipped axes:: - sage: p1 = plot(x, x, 0, 1, flip_x=True, flip_y=True) - sage: p2 = plot(x^2, x, 0, 1) - sage: [p._extra_kwds[k] for p in [p1 + p2, p2 + p1] for k in ['flip_x', 'flip_y']] + sage: p1 = plot(x, x, 0, 1, flip_x=True, flip_y=True) # optional - sage.symbolic + sage: p2 = plot(x^2, x, 0, 1) # optional - sage.symbolic + sage: [p._extra_kwds[k] for p in [p1 + p2, p2 + p1] # optional - sage.symbolic + ....: for k in ['flip_x', 'flip_y']] [True, True, True, True] """ if isinstance(other, int) and other == 0: @@ -1224,10 +1225,15 @@ def add_primitive(self, primitive): We give a very explicit example:: sage: G = Graphics() + sage: from math import e sage: from sage.plot.line import Line sage: from sage.plot.arrow import Arrow - sage: L = Line([3,4,2,7,-2],[1,2,e,4,5.],{'alpha':1,'thickness':2,'rgbcolor':(0,1,1),'legend_label':''}) - sage: A = Arrow(2,-5,.1,.2,{'width':3,'head':0,'rgbcolor':(1,0,0),'linestyle':'dashed','zorder':8,'legend_label':''}) + sage: L = Line([3,4,2,7,-2], [1,2,e,4,5.], + ....: {'alpha': 1, 'thickness': 2, 'rgbcolor': (0,1,1), + ....: 'legend_label': ''}) + sage: A = Arrow(2, -5, .1, .2, + ....: {'width': 3, 'head': 0, 'rgbcolor': (1,0,0), + ....: 'linestyle': 'dashed', 'zorder': 8, 'legend_label': ''}) sage: G.add_primitive(L) sage: G.add_primitive(A) sage: G @@ -1262,13 +1268,14 @@ def plot(self): def plot3d(self, z=0, **kwds): """ - Returns an embedding of this 2D plot into the xy-plane of 3D space, - as a 3D plot object. An optional parameter z can be given to + Return an embedding of this 2D plot into the xy-plane of 3D space, + as a 3D plot object. An optional parameter ``z`` can be given to specify the z-coordinate. EXAMPLES:: - sage: sum([plot(z*sin(x), 0, 10).plot3d(z) for z in range(6)]) # long time + sage: sum(plot(z*sin(x), 0, 10).plot3d(z) # long time # optional - sage.symbolic + ....: for z in range(6)) Graphics3d Object """ from sage.plot.plot3d.base import Graphics3dGroup @@ -1286,7 +1293,7 @@ def _extract_kwds_for_show(cls, kwds, ignore=[]): sage: kwds = {'f': lambda x: x, 'xmin': 0, 'figsize': [1,1], 'plot_points': (40, 40)} sage: G_kwds = Graphics._extract_kwds_for_show(kwds, ignore='xmin') - sage: kwds # Note how this action modifies the passed dictionary + sage: kwds # Note how this action modifies the passed dictionary {'f': at 0x...>, 'plot_points': (40, 40), 'xmin': 0} @@ -1296,7 +1303,7 @@ def _extract_kwds_for_show(cls, kwds, ignore=[]): This method is intended to be used with _set_extra_kwds(). Here is an idiom to ensure the correct keywords will get passed on to show():: - sage: options = {} # Usually this will come from an argument + sage: options = {} # Usually this will come from an argument sage: g = Graphics() sage: g._set_extra_kwds(Graphics._extract_kwds_for_show(options)) """ @@ -1321,7 +1328,7 @@ def _set_extra_kwds(self, kwds): sage: g._set_extra_kwds({'figsize': [10,10]}) sage: g._extra_kwds {'figsize': [10, 10]} - sage: g.show() # Now the (blank) plot will be extra large + sage: g.show() # Now the (blank) plot will be extra large """ self._extra_kwds = kwds @@ -1714,117 +1721,117 @@ def show(self, **kwds): height each having a maximum value of 327 inches at default dpi:: sage: p = ellipse((0,0),4,1) - sage: p.show(figsize=[327,10],dpi=100) - sage: p.show(figsize=[328,10],dpi=80) + sage: p.show(figsize=[327,10], dpi=100) + sage: p.show(figsize=[328,10], dpi=80) You can turn off the drawing of the axes:: - sage: show(plot(sin,-4,4), axes=False) + sage: show(plot(sin,-4,4), axes=False) # optional - sage.symbolic You can also label the axes. Putting something in dollar signs formats it as a mathematical expression:: - sage: show(plot(sin,-4,4), axes_labels=('$x$','$y$')) + sage: show(plot(sin,-4,4), axes_labels=('$x$','$y$')) # optional - sage.symbolic You can add a title to a plot:: - sage: show(plot(sin,-4,4), title=r'A plot of $\sin(x)$') + sage: show(plot(sin,-4,4), title=r'A plot of $\sin(x)$') # optional - sage.symbolic You can also provide the position for the title to the plot. In the plot below the title is placed on the bottom left of the figure.:: - sage: plot(sin, -4, 4, title='Plot sin(x)', title_pos=(0.05,-0.05)) + sage: plot(sin, -4, 4, title='Plot sin(x)', title_pos=(0.05,-0.05)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive If you want all the text to be rendered by using an external LaTeX installation then set the ``typeset`` to ``"latex"``. This requires that LaTeX, dvipng and Ghostscript be installed:: - sage: plot(x, typeset='latex') # optional - latex + sage: plot(x, typeset='latex') # optional - latex sage.symbolic Graphics object consisting of 1 graphics primitive If you want all the text in your plot to use Type 1 fonts, then set the ``typeset`` option to ``"type1"``. This requires that LaTeX, dvipng and Ghostscript be installed:: - sage: plot(x, typeset='type1') # optional - latex + sage: plot(x, typeset='type1') # optional - latex sage.symbolic Graphics object consisting of 1 graphics primitive You can turn on the drawing of a frame around the plots:: - sage: show(plot(sin,-4,4), frame=True) + sage: show(plot(sin,-4,4), frame=True) # optional - sage.symbolic You can make the background transparent:: - sage: plot(sin(x), (x, -4, 4), transparent=True) + sage: plot(sin(x), (x, -4, 4), transparent=True) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive Prior to :trac:`19485`, legends by default had a shadowless gray background. This behavior can be recovered by passing in certain ``legend_options``:: - sage: p = plot(sin(x), legend_label=r'$\sin(x)$') - sage: p.show(legend_options={'back_color': (0.9,0.9,0.9), + sage: p = plot(sin(x), legend_label=r'$\sin(x)$') # optional - sage.symbolic + sage: p.show(legend_options={'back_color': (0.9,0.9,0.9), # optional - sage.symbolic ....: 'shadow': False}) We can change the scale of the axes in the graphics before displaying:: - sage: G = plot(exp, 1, 10) - sage: G.show(scale='semilogy') + sage: G = plot(exp, 1, 10) # optional - sage.symbolic + sage: G.show(scale='semilogy') # optional - sage.symbolic We can change the base of the logarithm too. The following changes the vertical axis to be on log scale, and with base 2. Note that the ``base`` argument will ignore any changes to the axis which is in linear scale.:: - sage: G.show(scale='semilogy', base=2) # long time # y axis as powers of 2 + sage: G.show(scale='semilogy', base=2) # y axis as powers of 2 # long time, optional - sage.symbolic :: - sage: G.show(scale='semilogy', base=(3,2)) # base ignored for x-axis + sage: G.show(scale='semilogy', base=(3,2)) # base ignored for x-axis # optional - sage.symbolic The scale can be also given as a 2-tuple or a 3-tuple.:: - sage: G.show(scale=('loglog', 2.1)) # long time # both x and y axes in base 2.1 + sage: G.show(scale=('loglog', 2.1)) # both x and y axes in base 2.1 # long time, optional - sage.symbolic :: - sage: G.show(scale=('loglog', 2, 3)) # long time # x in base 2, y in base 3 + sage: G.show(scale=('loglog', 2, 3)) # x in base 2, y in base 3 # long time, optional - sage.symbolic The base need not be an integer, though it does have to be made a float.:: - sage: G.show(scale='semilogx', base=float(e)) # base is e + sage: G.show(scale='semilogx', base=float(e)) # base is e # optional - sage.symbolic Logarithmic scale can be used for various kinds of plots. Here are some examples.:: - sage: G = list_plot([10**i for i in range(10)]) # long time - sage: G.show(scale='semilogy') # long time + sage: G = list_plot([10**i for i in range(10)]) # long time, optional - sage.symbolic + sage: G.show(scale='semilogy') # long time :: - sage: G = parametric_plot((x, x**2), (x, 1, 10)) - sage: G.show(scale='loglog') + sage: G = parametric_plot((x, x**2), (x, 1, 10)) # optional - sage.symbolic + sage: G.show(scale='loglog') # optional - sage.symbolic :: - sage: disk((5,5), 4, (0, 3*pi/2)).show(scale='loglog',base=2) + sage: disk((5,5), 4, (0, 3*pi/2)).show(scale='loglog',base=2) # optional - sage.symbolic :: - sage: x, y = var('x, y') - sage: G = plot_vector_field((2^x,y^2),(x,1,10),(y,1,100)) - sage: G.show(scale='semilogx',base=2) + sage: x, y = var('x, y') # optional - sage.symbolic + sage: G = plot_vector_field((2^x,y^2), (x,1,10), (y,1,100)) # optional - sage.symbolic + sage: G.show(scale='semilogx',base=2) # optional - sage.symbolic Flip the horizontal or vertical axis. :: - sage: G = plot(x^3, -2, 3) - sage: G.show(flip_x=True) - sage: G.show(flip_y=True) + sage: G = plot(x^3, -2, 3) # optional - sage.symbolic + sage: G.show(flip_x=True) # optional - sage.symbolic + sage: G.show(flip_y=True) # optional - sage.symbolic Add grid lines at the major ticks of the axes. @@ -1839,27 +1846,27 @@ def show(self, **kwds): :: - sage: u,v = var('u v') - sage: f = exp(-(u^2+v^2)) - sage: p = plot_vector_field(f.gradient(), (u,-2,2), (v,-2,2)) - sage: p.show(gridlines="minor") + sage: u,v = var('u v') # optional - sage.symbolic + sage: f = exp(-(u^2+v^2)) # optional - sage.symbolic + sage: p = plot_vector_field(f.gradient(), (u,-2,2), (v,-2,2)) # optional - sage.symbolic + sage: p.show(gridlines="minor") # optional - sage.symbolic Add only horizontal or vertical grid lines. :: - sage: p = plot(sin,-10,20) - sage: p.show(gridlines=[None, "automatic"]) - sage: p.show(gridlines=["minor", False]) + sage: p = plot(sin, -10, 20) # optional - sage.symbolic + sage: p.show(gridlines=[None, "automatic"]) # optional - sage.symbolic + sage: p.show(gridlines=["minor", False]) # optional - sage.symbolic Add grid lines at specific positions (using lists/tuples). :: - sage: x, y = var('x, y') - sage: p = implicit_plot((y^2-x^2)*(x-1)*(2*x-3)-4*(x^2+y^2-2*x)^2, \ - ....: (x,-2,2), (y,-2,2), plot_points=1000) - sage: p.show(gridlines=[[1,0],[-1,0,1]]) + sage: x, y = var('x, y') # optional - sage.symbolic + sage: p = implicit_plot((y^2-x^2)*(x-1)*(2*x-3) - 4*(x^2+y^2-2*x)^2, # optional - sage.symbolic + ....: (x,-2,2), (y,-2,2), plot_points=1000) + sage: p.show(gridlines=[[1,0],[-1,0,1]]) # optional - sage.symbolic Add grid lines at specific positions (using iterators). @@ -1867,44 +1874,45 @@ def show(self, **kwds): sage: def maple_leaf(t): ....: return (100/(100+(t-pi/2)^8))*(2-sin(7*t)-cos(30*t)/2) - sage: p = polar_plot(maple_leaf, -pi/4, 3*pi/2, color="red",plot_points=1000) # long time - sage: p.show(gridlines=([-3,-2.75,..,3], range(-1,5,2))) # long time + sage: p = polar_plot(maple_leaf, -pi/4, 3*pi/2, # long time, optional - sage.symbolic + ....: color="red",plot_points=1000) + sage: p.show(gridlines=([-3,-2.75,..,3], range(-1,5,2))) # long time, optional - sage.symbolic Add grid lines at specific positions (using functions). :: - sage: y = x^5 + 4*x^4 - 10*x^3 - 40*x^2 + 9*x + 36 - sage: p = plot(y, -4.1, 1.1) - sage: xlines = lambda a,b: [z for z,m in y.roots()] - sage: p.show(gridlines=[xlines, [0]], frame=True, axes=False) + sage: y = x^5 + 4*x^4 - 10*x^3 - 40*x^2 + 9*x + 36 # optional - sage.symbolic + sage: p = plot(y, -4.1, 1.1) # optional - sage.symbolic + sage: xlines = lambda a, b: [z for z, m in y.roots()] # optional - sage.symbolic + sage: p.show(gridlines=[xlines, [0]], frame=True, axes=False) # optional - sage.symbolic Change the style of all the grid lines. :: sage: b = bar_chart([-3,5,-6,11], color='red') - sage: b.show(gridlines=([-1,-0.5,..,4],True), - ....: gridlinesstyle=dict(color="blue", linestyle=":")) + sage: b.show(gridlines=([-1,-0.5,..,4], True), + ....: gridlinesstyle=dict(color="blue", linestyle=":")) Change the style of the horizontal or vertical grid lines separately. :: - sage: p = polar_plot(2 + 2*cos(x), 0, 2*pi, color=hue(0.3)) - sage: p.show(gridlines=True, - ....: hgridlinesstyle=dict(color="orange", linewidth=1.0), - ....: vgridlinesstyle=dict(color="blue", linestyle=":")) + sage: p = polar_plot(2 + 2*cos(x), 0, 2*pi, color=hue(0.3)) # optional - sage.symbolic + sage: p.show(gridlines=True, # optional - sage.symbolic + ....: hgridlinesstyle=dict(color="orange", linewidth=1.0), + ....: vgridlinesstyle=dict(color="blue", linestyle=":")) Change the style of each grid line individually. :: - sage: x, y = var('x, y') - sage: p = implicit_plot((y^2-x^2)*(x-1)*(2*x-3)-4*(x^2+y^2-2*x)^2, - ....: (x,-2,2), (y,-2,2), plot_points=1000) - sage: p.show(gridlines=( + sage: x, y = var('x, y') # optional - sage.symbolic + sage: p = implicit_plot((y^2-x^2)*(x-1)*(2*x-3) - 4*(x^2+y^2-2*x)^2, # optional - sage.symbolic + ....: (x,-2,2), (y,-2,2), plot_points=1000) + sage: p.show(gridlines=( # optional - sage.symbolic ....: [ ....: (1,{"color":"red","linestyle":":"}), ....: (0,{"color":"blue","linestyle":"--"}) @@ -1921,9 +1929,10 @@ def show(self, **kwds): :: - sage: f = sin(x^2 + y^2)*cos(x)*sin(y) - sage: c = contour_plot(f, (x, -4, 4), (y, -4, 4), plot_points=100) - sage: c.show(gridlines=True, gridlinesstyle={'linestyle':':','linewidth':1, 'color':'red'}) + sage: f = sin(x^2 + y^2)*cos(x)*sin(y) # optional - sage.symbolic + sage: c = contour_plot(f, (x, -4, 4), (y, -4, 4), plot_points=100) # optional - sage.symbolic + sage: c.show(gridlines=True, # optional - sage.symbolic + ....: gridlinesstyle={'linestyle': ':', 'linewidth': 1, 'color': 'red'}) Grid lines can be added to matrix plots. @@ -1942,9 +1951,11 @@ def show(self, **kwds): :: - sage: plot(sin(x), (x, -pi, pi),thickness=2)+point((pi, -1), pointsize=15) + sage: (plot(sin(x), (x, -pi, pi), thickness=2) # optional - sage.symbolic + ....: + point((pi, -1), pointsize=15)) Graphics object consisting of 2 graphics primitives - sage: plot(sin(x), (x, -pi, pi),thickness=2,axes_pad=0)+point((pi, -1), pointsize=15) + sage: (plot(sin(x), (x, -pi, pi), thickness=2, axes_pad=0) # optional - sage.symbolic + ....: + point((pi, -1), pointsize=15)) Graphics object consisting of 2 graphics primitives The behavior of the ``axes_pad`` parameter is different if the axis @@ -1956,10 +1967,10 @@ def show(self, **kwds): :: - sage: plot_loglog(x, (1.1*10**-2, 9990)) + sage: plot_loglog(x, (1.1*10**-2, 9990)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive - sage: plot_loglog(x, (1.1*10**-2, 9990), axes_pad=0) + sage: plot_loglog(x, (1.1*10**-2, 9990), axes_pad=0) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive Via matplotlib, Sage allows setting of custom ticks. See above @@ -1967,38 +1978,39 @@ def show(self, **kwds): Here the labels are not so useful:: - sage: plot(sin(pi*x), (x, -8, 8)) + sage: plot(sin(pi*x), (x, -8, 8)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive Now put ticks at multiples of 2:: - sage: plot(sin(pi*x), (x, -8, 8), ticks=2) + sage: plot(sin(pi*x), (x, -8, 8), ticks=2) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive Or just choose where you want the ticks:: - sage: plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7],[-1/2,0,1/2]]) + sage: plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7], [-1/2,0,1/2]]) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive Or no ticks at all:: - sage: plot(sin(pi*x), (x, -8, 8), ticks=[[],[]]) + sage: plot(sin(pi*x), (x, -8, 8), ticks=[[], []]) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive This can be very helpful in showing certain features of plots. :: - sage: plot(1.5/(1+e^(-x)), (x, -10, 10)) # doesn't quite show value of inflection point + sage: plot(1.5/(1+e^(-x)), (x, -10, 10)) # doesn't quite show value of inflection point # optional - sage.symbolic Graphics object consisting of 1 graphics primitive :: - sage: plot(1.5/(1+e^(-x)), (x, -10, 10), ticks=[None, 1.5/4]) # It's right at f(x)=0.75! + sage: plot(1.5/(1+e^(-x)), (x, -10, 10), # It's right at f(x)=0.75! # optional - sage.symbolic + ....: ticks=[None, 1.5/4]) Graphics object consisting of 1 graphics primitive But be careful to leave enough room for at least two major ticks, so that the user can tell what the scale is:: - sage: plot(x^2,(x,1,8),ticks=6).show() + sage: plot(x^2, (x,1,8), ticks=6).show() # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Expand the range of the independent variable to @@ -2007,7 +2019,9 @@ def show(self, **kwds): We can also do custom formatting if you need it. See above for full details:: - sage: plot(2*x+1,(x,0,5),ticks=[[0,1,e,pi,sqrt(20)],2],tick_formatter="latex") # not tested (broken with matplotlib 3.6) + sage: plot(2*x + 1, (x,0,5), # not tested (broken with matplotlib 3.6) # optional - sage.symbolic + ....: ticks=[[0,1,e,pi,sqrt(20)], 2], + ....: tick_formatter="latex") Graphics object consisting of 1 graphics primitive This is particularly useful when setting custom ticks in multiples @@ -2015,41 +2029,47 @@ def show(self, **kwds): :: - sage: plot(sin(x),(x,0,2*pi),ticks=pi/3,tick_formatter=pi) + sage: plot(sin(x), (x,0,2*pi), ticks=pi/3, tick_formatter=pi) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive But keep in mind that you will get exactly the formatting you asked for if you specify both formatters. The first syntax is recommended for best style in that case. :: - sage: plot(arcsin(x),(x,-1,1),ticks=[None,pi/6],tick_formatter=["latex",pi]) # Nice-looking! + sage: plot(arcsin(x), (x,-1,1), ticks=[None, pi/6], # Nice-looking! # optional - sage.symbolic + ....: tick_formatter=["latex", pi]) Graphics object consisting of 1 graphics primitive :: - sage: plot(arcsin(x),(x,-1,1),ticks=[None,pi/6],tick_formatter=[None,pi]) # Not so nice-looking + sage: plot(arcsin(x), (x,-1,1), ticks=[None, pi/6], # Not so nice-looking # optional - sage.symbolic + ....: tick_formatter=[None, pi]) Graphics object consisting of 1 graphics primitive Custom tick labels can be provided by providing the keyword ``tick_formatter`` with the list of labels, and simultaneously providing the keyword ``ticks`` with the positions of the labels. :: - sage: plot(x, (x,0,3), ticks=[[1,2.5],[0.5,1,2]], tick_formatter=[["$x_1$","$x_2$"],["$y_1$","$y_2$","$y_3$"]]) + sage: plot(x, (x,0,3), ticks=[[1,2.5], [0.5,1,2]], # optional - sage.symbolic + ....: tick_formatter=[["$x_1$","$x_2$"], ["$y_1$","$y_2$","$y_3$"]]) Graphics object consisting of 1 graphics primitive The following sets the custom tick labels only along the horizontal axis. :: - sage: plot(x**2, (x,0,2), ticks=[[1,2], None], tick_formatter=[["$x_1$","$x_2$"], None]) + sage: plot(x**2, (x,0,2), ticks=[[1,2], None], # optional - sage.symbolic + ....: tick_formatter=[["$x_1$","$x_2$"], None]) Graphics object consisting of 1 graphics primitive If the number of tick labels do not match the number of positions of tick labels, then it results in an error.:: - sage: plot(x**2, (x,0,2), ticks=[[2], None], tick_formatter=[["$x_1$","$x_2$"], None]).show() + sage: plot(x**2, (x,0,2), ticks=[[2], None], # optional - sage.symbolic + ....: tick_formatter=[["$x_1$","$x_2$"], None]).show() Traceback (most recent call last): ... - ValueError: If the first component of the list `tick_formatter` is a list then the first component of `ticks` must also be a list of equal length. + ValueError: If the first component of the list `tick_formatter` is a list + then the first component of `ticks` must also be a list of equal length. When using logarithmic scale along the axis, make sure to have enough room for two ticks so that the user can tell what the scale @@ -2083,8 +2103,9 @@ def show(self, **kwds): When using ``title_pos``, it must be ensured that a list or a tuple of length two is used. Otherwise, a warning is raised:: - sage: plot(x, -4, 4, title='Plot x', title_pos=0.05) - doctest:...: ...RichReprWarning: Exception in _rich_repr_ while displaying object: 'title_pos' must be a list or tuple of two real numbers. + sage: plot(x, -4, 4, title='Plot x', title_pos=0.05) # optional - sage.symbolic + doctest:...: ...RichReprWarning: Exception in _rich_repr_ while displaying + object: 'title_pos' must be a list or tuple of two real numbers. Graphics object consisting of 1 graphics primitive TESTS: @@ -2111,24 +2132,25 @@ def show(self, **kwds): The following tests ensure we give a good error message for negative figsizes:: - sage: P = plot(x^2,(x,0,1)) - sage: P.show(figsize=[-1,1]) + sage: P = plot(x^2,(x,0,1)) # optional - sage.symbolic + sage: P.show(figsize=[-1,1]) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: figsize should be positive numbers, not -1.0 and 1.0 - sage: P.show(figsize=-1) + sage: P.show(figsize=-1) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: figsize should be positive, not -1.0 - sage: P.show(figsize=x^2) + sage: P.show(figsize=x^2) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: figsize should be a positive number, not x^2 - sage: P.show(figsize=[2,3,4]) + sage: P.show(figsize=[2,3,4]) # optional - sage.symbolic Traceback (most recent call last): ... - ValueError: figsize should be a positive number or a list of two positive numbers, not [2, 3, 4] - sage: P.show(figsize=[sqrt(2),sqrt(3)]) + ValueError: figsize should be a positive number or + a list of two positive numbers, not [2, 3, 4] + sage: P.show(figsize=[sqrt(2),sqrt(3)]) # optional - sage.symbolic """ from sage.repl.rich_output import get_display_manager dm = get_display_manager() @@ -2240,7 +2262,8 @@ def get_minmax_data(self): 'ymin': -1.0} sage: l = line([(0,0), (1,1)], aspect_ratio=1e19) sage: l.get_minmax_data() - {'xmax': 5000.50000000000, 'xmin': -4999.50000000000, 'ymax': 1.0, 'ymin': 0.0} + {'xmax': 5000.50000000000, 'xmin': -4999.50000000000, + 'ymax': 1.0, 'ymin': 0.0} """ objects = self._objects if objects: @@ -2332,15 +2355,16 @@ def _matplotlib_tick_formatter(self, subplot, base=(10, 10), the ticks formatting. This function is only for internal use. INPUT: + - ``subplot`` -- the subplot instance. EXAMPLES:: sage: from matplotlib.figure import Figure - sage: p = plot(x); d = p.get_minmax_data() - sage: subplot = Figure().add_subplot(111) - sage: p._objects[0]._render_on_subplot(subplot) - sage: p._matplotlib_tick_formatter(subplot, **d) + sage: p = plot(x); d = p.get_minmax_data() # optional - sage.symbolic + sage: subplot = Figure().add_subplot(111) # optional - sage.symbolic + sage: p._objects[0]._render_on_subplot(subplot) # optional - sage.symbolic + sage: p._matplotlib_tick_formatter(subplot, **d) # optional - sage.symbolic (, , , @@ -2649,40 +2673,41 @@ def matplotlib(self, filename=None, :: - sage: p = plot(sin(x), (x, -2*pi, 2*pi)) - sage: figure = p.matplotlib() - sage: axes = figure.axes[0] + sage: p = plot(sin(x), (x, -2*pi, 2*pi)) # optional - sage.symbolic + sage: figure = p.matplotlib() # optional - sage.symbolic + sage: axes = figure.axes[0] # optional - sage.symbolic TESTS: We verify that :trac:`10291` is fixed:: - sage: p = plot(sin(x), (x, -2*pi, 2*pi)) - sage: figure = p.matplotlib() - sage: axes_range = p.get_axes_range() - sage: figure = p.matplotlib() - sage: axes_range2 = p.get_axes_range() - sage: axes_range == axes_range2 + sage: p = plot(sin(x), (x, -2*pi, 2*pi)) # optional - sage.symbolic + sage: figure = p.matplotlib() # optional - sage.symbolic + sage: axes_range = p.get_axes_range() # optional - sage.symbolic + sage: figure = p.matplotlib() # optional - sage.symbolic + sage: axes_range2 = p.get_axes_range() # optional - sage.symbolic + sage: axes_range == axes_range2 # optional - sage.symbolic True We verify that legend options are properly handled (:trac:`12960`). First, we test with no options, and next with an incomplete set of options.:: - sage: p = plot(x, legend_label='aha') - sage: p.legend(True) - sage: pm = p.matplotlib() - sage: pm = p.matplotlib(legend_options={'font_size':'small'}) + sage: p = plot(x, legend_label='aha') # optional - sage.symbolic + sage: p.legend(True) # optional - sage.symbolic + sage: pm = p.matplotlib() # optional - sage.symbolic + sage: pm = p.matplotlib(legend_options={'font_size': 'small'}) # optional - sage.symbolic The title should not overlap with the axes labels nor the frame in the following plot (see :trac:`10512`):: - sage: plot(sin(x^2), (x, -3, 3), title='Plot of sin(x^2)', axes_labels=['x','y'],frame=True) + sage: plot(sin(x^2), (x, -3, 3), title='Plot of sin(x^2)', # optional - sage.symbolic + ....: axes_labels=['x','y'], frame=True) Graphics object consisting of 1 graphics primitive ``typeset`` must not be set to an arbitrary string:: - sage: plot(x, typeset='garbage') + sage: plot(x, typeset='garbage') # optional - sage.symbolic doctest:...: ...RichReprWarning: Exception in _rich_repr_ while displaying object: typeset must be set to one of 'default', 'latex', or 'type1'; got 'garbage'. @@ -2692,17 +2717,17 @@ def matplotlib(self, filename=None, By default, Sage 5.10 changes float objects to the `RealLiteral` type. The patch changes them to float before creating `matplotlib` objects.:: - sage: f = lambda x, y : (abs(cos((x + I * y) ** 4)) - 1) # long time - sage: g = implicit_plot(f,(-4, 4),(-3, 3),linewidth=0.6) # long time - sage: gm = g.matplotlib() # long time # without the patch, this goes BOOM -- er, TypeError + sage: f = lambda x, y: abs(cos((x + I * y) ** 4)) - 1 # long time # optional - sage.symbolic + sage: g = implicit_plot(f, (-4, 4), (-3, 3), linewidth=0.6) # long time # optional - sage.symbolic + sage: gm = g.matplotlib() # long time # without the patch, this goes BOOM -- er, TypeError # optional - sage.symbolic If the axes are flipped, the limits of the axes get swapped:: - sage: p = plot(2*x, 1, 2) - sage: sub, = p.matplotlib(flip_y=True, flip_x=True).axes - sage: xmin, xmax = sub.get_xlim() - sage: ymin, ymax = sub.get_ylim() - sage: xmin > xmax, ymin > ymax + sage: p = plot(2*x, 1, 2) # optional - sage.symbolic + sage: sub, = p.matplotlib(flip_y=True, flip_x=True).axes # optional - sage.symbolic + sage: xmin, xmax = sub.get_xlim() # optional - sage.symbolic + sage: ymin, ymax = sub.get_ylim() # optional - sage.symbolic + sage: xmin > xmax, ymin > ymax # optional - sage.symbolic (True, True) """ if not isinstance(ticks, (list, tuple)): @@ -3251,16 +3276,16 @@ def save(self, filename, **kwds): ``fig_tight=False``:: sage: c.save(f.name, figsize=[8,4], fig_tight=False, - ....: xmin=-1, xmax=3, ymin=-1, ymax=3) + ....: xmin=-1, xmax=3, ymin=-1, ymax=3) You can also pass extra options to the plot command instead of this method, e.g. :: - sage: plot(x^2 - 5, (x, 0, 5), ymin=0).save(tmp_filename(ext='.png')) + sage: plot(x^2 - 5, (x, 0, 5), ymin=0).save(tmp_filename(ext='.png')) # optional - sage.symbolic will save the same plot as the one shown by this command:: - sage: plot(x^2 - 5, (x, 0, 5), ymin=0) + sage: plot(x^2 - 5, (x, 0, 5), ymin=0) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive (This test verifies that :trac:`8632` is fixed.) @@ -3269,21 +3294,21 @@ def save(self, filename, **kwds): Legend labels should save correctly:: - sage: P = plot(x,(x,0,1),legend_label='$xyz$') - sage: P.set_legend_options(back_color=(1,0,0)) - sage: P.set_legend_options(loc=7) + sage: P = plot(x,(x,0,1),legend_label='$xyz$') # optional - sage.symbolic + sage: P.set_legend_options(back_color=(1,0,0)) # optional - sage.symbolic + sage: P.set_legend_options(loc=7) # optional - sage.symbolic sage: import tempfile - sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # optional - sage.symbolic ....: P.save(f.name) This plot should save with the frame shown, showing :trac:`7524` is fixed (same issue as :trac:`7981` and :trac:`8632`):: - sage: var('x,y') + sage: var('x,y') # optional - sage.symbolic (x, y) - sage: a = plot_vector_field((x,-y),(x,-1,1),(y,-1,1)) + sage: a = plot_vector_field((x,-y),(x,-1,1),(y,-1,1)) # optional - sage.symbolic sage: import tempfile - sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # optional - sage.symbolic ....: a.save(f.name) The following plot should show the axes; fixes :trac:`14782` :: @@ -3403,7 +3428,7 @@ def description(self): EXAMPLES:: - sage: print(polytopes.hypercube(2).plot().description()) + sage: print(polytopes.hypercube(2).plot().description()) # optional - sage.geometry.polyhedron Polygon defined by 4 points: [(-1.0, -1.0), (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0)] Line defined by 2 points: [(-1.0, 1.0), (-1.0, -1.0)] Line defined by 2 points: [(1.0, -1.0), (-1.0, -1.0)] @@ -3448,11 +3473,11 @@ def inset(self, graphics, pos=None, fontsize=None): EXAMPLES:: - sage: f(x) = x^2*sin(1/x) - sage: g1 = plot(f(x), (x, -2, 2), axes_labels=['$x$', '$y$']) - sage: g2 = plot(f(x), (x, -0.3, 0.3), axes_labels=['$x$', '$y$'], + sage: f(x) = x^2*sin(1/x) # optional - sage.symbolic + sage: g1 = plot(f(x), (x, -2, 2), axes_labels=['$x$', '$y$']) # optional - sage.symbolic + sage: g2 = plot(f(x), (x, -0.3, 0.3), axes_labels=['$x$', '$y$'], # optional - sage.symbolic ....: frame=True) - sage: g1.inset(g2) + sage: g1.inset(g2) # optional - sage.symbolic Multigraphics with 2 elements .. PLOT:: @@ -3465,7 +3490,7 @@ def inset(self, graphics, pos=None, fontsize=None): Using non-default values for the position/size and the font size:: - sage: g1.inset(g2, pos=(0.15, 0.7, 0.25, 0.25), fontsize=8) + sage: g1.inset(g2, pos=(0.15, 0.7, 0.25, 0.25), fontsize=8) # optional - sage.symbolic Multigraphics with 2 elements .. PLOT:: @@ -3478,10 +3503,10 @@ def inset(self, graphics, pos=None, fontsize=None): We can add another inset by invoking ``inset`` on the last output:: - sage: g1g2 = _ - sage: g3 = plot(f(x), (x, -0.05, 0.05), axes_labels=['$x$', '$y$'], + sage: g1g2 = _ # optional - sage.symbolic + sage: g3 = plot(f(x), (x, -0.05, 0.05), axes_labels=['$x$', '$y$'], # optional - sage.symbolic ....: frame=True) - sage: g1g2.inset(g3, pos=(0.65, 0.12, 0.25, 0.25)) + sage: g1g2.inset(g3, pos=(0.65, 0.12, 0.25, 0.25)) # optional - sage.symbolic Multigraphics with 3 elements .. PLOT:: @@ -3518,7 +3543,8 @@ def GraphicsArray(*args, **kwargs): sage: from sage.plot.graphics import GraphicsArray sage: c = circle((0,0), 1) sage: G = GraphicsArray([c, c]) - doctest:...: DeprecationWarning: GraphicsArray must be imported from sage.plot.multigraphics and no longer from sage.plot.graphics. + doctest:...: DeprecationWarning: GraphicsArray must be imported from + sage.plot.multigraphics and no longer from sage.plot.graphics. See https://github.com/sagemath/sage/issues/28675 for details. sage: G Graphics Array of size 1 x 2 diff --git a/src/sage/plot/hyperbolic_arc.py b/src/sage/plot/hyperbolic_arc.py index 0ab3f2744c8..914cd77654c 100644 --- a/src/sage/plot/hyperbolic_arc.py +++ b/src/sage/plot/hyperbolic_arc.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic r""" Arcs in hyperbolic geometry diff --git a/src/sage/plot/hyperbolic_polygon.py b/src/sage/plot/hyperbolic_polygon.py index 1726525ff43..5539ddf63ab 100644 --- a/src/sage/plot/hyperbolic_polygon.py +++ b/src/sage/plot/hyperbolic_polygon.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic """ Polygons and triangles in hyperbolic geometry diff --git a/src/sage/plot/hyperbolic_regular_polygon.py b/src/sage/plot/hyperbolic_regular_polygon.py index 5874073b549..41c153882ec 100644 --- a/src/sage/plot/hyperbolic_regular_polygon.py +++ b/src/sage/plot/hyperbolic_regular_polygon.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic """ Regular polygons in the upper half model for hyperbolic plane diff --git a/src/sage/plot/line.py b/src/sage/plot/line.py index 8c2d8ec0ad1..bff28b3d34d 100644 --- a/src/sage/plot/line.py +++ b/src/sage/plot/line.py @@ -131,9 +131,9 @@ def plot3d(self, z=0, **kwds): EXAMPLES:: - sage: E = EllipticCurve('37a').plot(thickness=5).plot3d() - sage: F = EllipticCurve('37a').plot(thickness=5).plot3d(z=2) - sage: E + F # long time (5s on sage.math, 2012) + sage: E = EllipticCurve('37a').plot(thickness=5).plot3d() # optional - sage.schemes + sage: F = EllipticCurve('37a').plot(thickness=5).plot3d(z=2) # optional - sage.schemes + sage: E + F # long time (5s on sage.math, 2012) # optional - sage.schemes Graphics3d Object .. PLOT:: @@ -442,7 +442,9 @@ def line2d(points, **options): A blue conchoid of Nicomedes:: - sage: L = [[1+5*cos(pi/2+pi*i/100), tan(pi/2+pi*i/100)*(1+5*cos(pi/2+pi*i/100))] for i in range(1,100)] + sage: from math import pi + sage: L = [[1 + 5*cos(pi/2+pi*i/100), + ....: tan(pi/2+pi*i/100) * (1+5*cos(pi/2+pi*i/100))] for i in range(1,100)] sage: line(L, rgbcolor=(1/4,1/8,3/4)) Graphics object consisting of 1 graphics primitive @@ -454,7 +456,7 @@ def line2d(points, **options): A line with 2 complex points:: sage: i = CC(0,1) - sage: line([1+i, 2+3*i]) + sage: line([1 + i, 2 + 3*i]) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -466,7 +468,8 @@ def line2d(points, **options): A blue hypotrochoid (3 leaves):: sage: n = 4; h = 3; b = 2 - sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100),n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] + sage: L = [[n*cos(pi*i/100) + h*cos((n/b)*pi*i/100), + ....: n*sin(pi*i/100) - h*sin((n/b)*pi*i/100)] for i in range(200)] sage: line(L, rgbcolor=(1/4,1/4,3/4)) Graphics object consisting of 1 graphics primitive @@ -482,7 +485,8 @@ def line2d(points, **options): A blue hypotrochoid (4 leaves):: sage: n = 6; h = 5; b = 2 - sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100),n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] + sage: L = [[n*cos(pi*i/100) + h*cos((n/b)*pi*i/100), + ....: n*sin(pi*i/100) - h*sin((n/b)*pi*i/100)] for i in range(200)] sage: line(L, rgbcolor=(1/4,1/4,3/4)) Graphics object consisting of 1 graphics primitive @@ -493,7 +497,8 @@ def line2d(points, **options): A red limacon of Pascal:: - sage: L = [[sin(pi*i/100)+sin(pi*i/50),-(1+cos(pi*i/100)+cos(pi*i/50))] for i in range(-100,101)] + sage: L = [[sin(pi*i/100) + sin(pi*i/50), + ....: -(1 + cos(pi*i/100) + cos(pi*i/50))] for i in range(-100,101)] sage: line(L, rgbcolor=(1,1/4,1/2)) Graphics object consisting of 1 graphics primitive @@ -504,7 +509,8 @@ def line2d(points, **options): A light green trisectrix of Maclaurin:: - sage: L = [[2*(1-4*cos(-pi/2+pi*i/100)^2),10*tan(-pi/2+pi*i/100)*(1-4*cos(-pi/2+pi*i/100)^2)] for i in range(1,100)] + sage: L = [[2 * (1-4*cos(-pi/2+pi*i/100)^2), + ....: 10 * tan(-pi/2+pi*i/100) * (1-4*cos(-pi/2+pi*i/100)^2)] for i in range(1,100)] sage: line(L, rgbcolor=(1/4,1,1/8)) Graphics object consisting of 1 graphics primitive @@ -530,8 +536,8 @@ def line2d(points, **options): A red plot of the Jacobi elliptic function `\text{sn}(x,2)`, `-3 < x < 3`:: - sage: L = [(i/100.0, real_part(jacobi('sn', i/100.0, 2.0))) for i in - ....: range(-300, 300, 30)] + sage: L = [(i/100.0, real_part(jacobi('sn', i/100.0, 2.0))) + ....: for i in range(-300, 300, 30)] sage: line(L, rgbcolor=(3/4, 1/4, 1/8)) Graphics object consisting of 1 graphics primitive @@ -543,7 +549,7 @@ def line2d(points, **options): A red plot of `J`-Bessel function `J_2(x)`, `0 < x < 10`:: sage: L = [(i/10.0, bessel_J(2,i/10.0)) for i in range(100)] - sage: line(L, rgbcolor=(3/4,1/4,5/8)) + sage: line(L, rgbcolor=(3/4, 1/4, 5/8)) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -556,7 +562,7 @@ def line2d(points, **options): sage: i = CDF.gen() sage: v = [zeta(0.5 + n/10 * i) for n in range(300)] sage: L = [(z.real(), z.imag()) for z in v] - sage: line(L, rgbcolor=(3/4,1/2,5/8)) + sage: line(L, rgbcolor=(3/4, 1/2, 5/8)) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -568,10 +574,10 @@ def line2d(points, **options): A purple plot of the Hasse-Weil `L`-function `L(E, 1 + it)`, `-1 < t < 10`:: - sage: E = EllipticCurve('37a') - sage: vals = E.lseries().values_along_line(1-I, 1+10*I, 100) # critical line - sage: L = [(z[1].real(), z[1].imag()) for z in vals] - sage: line(L, rgbcolor=(3/4,1/2,5/8)) + sage: E = EllipticCurve('37a') # optional - sage.schemes + sage: vals = E.lseries().values_along_line(1-I, 1+10*I, 100) # critical line # optional - sage.schemes + sage: L = [(z[1].real(), z[1].imag()) for z in vals] # optional - sage.schemes + sage: line(L, rgbcolor=(3/4,1/2,5/8)) # optional - sage.schemes Graphics object consisting of 1 graphics primitive .. PLOT :: diff --git a/src/sage/plot/matrix_plot.py b/src/sage/plot/matrix_plot.py index 65df86e50a9..0999d7068d4 100644 --- a/src/sage/plot/matrix_plot.py +++ b/src/sage/plot/matrix_plot.py @@ -132,8 +132,8 @@ def _allowed_options(self): EXAMPLES:: - sage: M = matrix_plot([[sin(i*j) for i in range(5)] for j in range(5)]) - sage: isinstance(M[0]._allowed_options(),dict) + sage: M = matrix_plot([[sin(i*j) for i in range(5)] for j in range(5)]) # optional - sage.symbolic + sage: isinstance(M[0]._allowed_options(), dict) # optional - sage.symbolic True """ return {'cmap':"""the name of a predefined colormap, @@ -158,8 +158,8 @@ def _repr_(self): EXAMPLES:: - sage: M = matrix_plot([[sin(i*j) for i in range(5)] for j in range(5)]) - sage: m = M[0]; m + sage: M = matrix_plot([[sin(i*j) for i in range(5)] for j in range(5)]) # optional - sage.symbolic + sage: m = M[0]; m # optional - sage.symbolic MatrixPlot defined by a 5 x 5 data grid """ return "MatrixPlot defined by a %s x %s data grid"%(self.xy_array_row, self.xy_array_col) @@ -388,14 +388,17 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): sage: m=random_matrix(RR,10) sage: m.subdivide([2,4],[6,8]) - sage: matrix_plot(m, subdivisions=True, subdivision_style=dict(color='red',thickness=3)) + sage: matrix_plot(m, subdivisions=True, + ....: subdivision_style=dict(color='red',thickness=3)) Graphics object consisting of 1 graphics primitive You can also specify your own subdivisions and separate styles for row or column subdivisions:: sage: m=random_matrix(RR,10) - sage: matrix_plot(m, subdivisions=True, subdivision_boundaries=[[2,4],[6,8]], subdivision_style=[dict(color='red',thickness=3),dict(linestyle='--',thickness=6)]) + sage: matrix_plot(m, subdivisions=True, subdivision_boundaries=[[2,4],[6,8]], + ....: subdivision_style=[dict(color='red',thickness=3), + ....: dict(linestyle='--',thickness=6)]) Graphics object consisting of 1 graphics primitive Generally matrices are plotted with the (0,0) entry in the upper @@ -409,10 +412,9 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): A custom bounding box in which to draw the matrix can be specified using the ``xrange`` and ``yrange`` arguments:: - sage: P = matrix_plot(identity_matrix(10), xrange=(0, pi), yrange=(-pi, 0)) - sage: P + sage: P = matrix_plot(identity_matrix(10), xrange=(0, pi), yrange=(-pi, 0)); P # optional - sage.symbolic Graphics object consisting of 1 graphics primitive - sage: P.get_minmax_data() + sage: P.get_minmax_data() # optional - sage.symbolic {'xmax': 3.14159..., 'xmin': 0.0, 'ymax': 0.0, 'ymin': -3.14159...} If the horizontal and vertical dimension of the image are very different, @@ -425,18 +427,19 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): Another random plot, but over `\GF{389}`:: - sage: m = random_matrix(GF(389), 10) - sage: matrix_plot(m, cmap='Oranges') + sage: m = random_matrix(GF(389), 10) # optional - sage.rings.finite_rings + sage: matrix_plot(m, cmap='Oranges') # optional - sage.rings.finite_rings Graphics object consisting of 1 graphics primitive It also works if you lift it to the polynomial ring:: - sage: matrix_plot(m.change_ring(GF(389)['x']), cmap='Oranges') + sage: matrix_plot(m.change_ring(GF(389)['x']), cmap='Oranges') # optional - sage.rings.finite_rings Graphics object consisting of 1 graphics primitive We have several options for colorbars:: - sage: matrix_plot(random_matrix(RDF, 50), colorbar=True, colorbar_orientation='horizontal') + sage: matrix_plot(random_matrix(RDF, 50), colorbar=True, + ....: colorbar_orientation='horizontal') Graphics object consisting of 1 graphics primitive :: @@ -456,27 +459,28 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): Here we plot a random sparse matrix:: - sage: sparse = matrix(dict([((randint(0, 10), randint(0, 10)), 1) for i in range(100)])) + sage: sparse = matrix(dict(((randint(0, 10), randint(0, 10)), 1) + ....: for i in range(100))) sage: matrix_plot(sparse) Graphics object consisting of 1 graphics primitive :: - sage: A=random_matrix(ZZ,100000,density=.00001,sparse=True) - sage: matrix_plot(A,marker=',') + sage: A = random_matrix(ZZ, 100000, density=.00001, sparse=True) + sage: matrix_plot(A, marker=',') Graphics object consisting of 1 graphics primitive As with dense matrices, sparse matrix entries are automatically converted to floating point numbers before plotting. Thus the following works:: - sage: b=random_matrix(GF(2),200,sparse=True,density=0.01) + sage: b = random_matrix(GF(2), 200, sparse=True, density=0.01) # optional - sage.rings.finite_rings sage: matrix_plot(b) Graphics object consisting of 1 graphics primitive While this returns an error:: - sage: b=random_matrix(CDF,200,sparse=True,density=0.01) + sage: b = random_matrix(CDF, 200, sparse=True, density=0.01) sage: matrix_plot(b) Traceback (most recent call last): ... @@ -485,7 +489,7 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): To plot the absolute value of a complex matrix, use the ``apply_map`` method:: - sage: b=random_matrix(CDF,200,sparse=True,density=0.01) + sage: b = random_matrix(CDF, 200, sparse=True, density=0.01) sage: matrix_plot(b.apply_map(abs)) Graphics object consisting of 1 graphics primitive diff --git a/src/sage/plot/misc.py b/src/sage/plot/misc.py index d0ec1c60295..f6421b53d65 100644 --- a/src/sage/plot/misc.py +++ b/src/sage/plot/misc.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic """ Plotting utilities """ diff --git a/src/sage/plot/multigraphics.py b/src/sage/plot/multigraphics.py index ae85183dc93..bae3c3308b4 100644 --- a/src/sage/plot/multigraphics.py +++ b/src/sage/plot/multigraphics.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.symbolic r""" Graphics arrays and insets diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index d83fb24cad7..e42400c49f0 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.symbolic r""" 2D plotting diff --git a/src/sage/plot/plot3d/base.pyx b/src/sage/plot/plot3d/base.pyx index 84acb7f6c89..771fff25e54 100644 --- a/src/sage/plot/plot3d/base.pyx +++ b/src/sage/plot/plot3d/base.pyx @@ -841,6 +841,7 @@ cdef class Graphics3d(SageObject): EXAMPLES:: + sage: from math import pi sage: from sage.plot.plot3d.shapes import Cone sage: v = (1,2,3) sage: G = arrow3d((0, 0, 0), v) @@ -861,6 +862,7 @@ cdef class Graphics3d(SageObject): EXAMPLES:: + sage: from math import pi sage: from sage.plot.plot3d.shapes import Cone sage: G = Cone(1/5, 1) + Cone(1/5, 1, opacity=.25).rotateX(pi/2) sage: G.show(aspect_ratio=1) @@ -873,6 +875,7 @@ cdef class Graphics3d(SageObject): EXAMPLES:: + sage: from math import pi sage: from sage.plot.plot3d.shapes import Cone sage: G = Cone(1/5, 1) + Cone(1/5, 1, opacity=.25).rotateY(pi/3) sage: G.show(aspect_ratio=1) @@ -885,6 +888,7 @@ cdef class Graphics3d(SageObject): EXAMPLES:: + sage: from math import pi sage: from sage.plot.plot3d.shapes import Box sage: G = Box(1/2, 1/3, 1/5) + Box(1/2, 1/3, 1/5, opacity=.25).rotateZ(pi/5) sage: G.show(aspect_ratio=1) @@ -1761,17 +1765,17 @@ end_scene""".format( EXAMPLES: We illustrate use of the ``aspect_ratio`` option:: - sage: x, y = var('x,y') - sage: p = plot3d(2*sin(x*y), (x, -pi, pi), (y, -pi, pi)) - sage: p.show(aspect_ratio=[1,1,1]) + sage: x, y = var('x,y') # optional -- sage.symbolic + sage: p = plot3d(2*sin(x*y), (x, -pi, pi), (y, -pi, pi)) # optional -- sage.symbolic + sage: p.show(aspect_ratio=[1,1,1]) # optional -- sage.symbolic This looks flattened, but filled with the plot:: - sage: p.show(frame_aspect_ratio=[1,1,1/16]) + sage: p.show(frame_aspect_ratio=[1,1,1/16]) # optional -- sage.symbolic This looks flattened, but the plot is square and smaller:: - sage: p.show(aspect_ratio=[1,1,1], frame_aspect_ratio=[1,1,1/8]) + sage: p.show(aspect_ratio=[1,1,1], frame_aspect_ratio=[1,1,1/8]) # optional -- sage.symbolic This example shows indirectly that the defaults from :func:`~sage.plot.plot.plot` are dealt with properly:: @@ -1782,17 +1786,17 @@ end_scene""".format( We use the 'canvas3d' backend from inside the notebook to get a view of the plot rendered inline using HTML canvas:: - sage: p.show(viewer='canvas3d') + sage: p.show(viewer='canvas3d') # optional -- sage.symbolic Sometimes shadows in Tachyon-produced images can lead to confusing plots. To remove them:: - sage: p.show(viewer="tachyon", shade="medium") + sage: p.show(viewer="tachyon", shade="medium") # optional -- sage.symbolic One can also pass Tachyon command line flags directly. For example, the following line produces the same result as the previous one:: - sage: p.show(viewer="tachyon", extra_opts="-mediumshade") + sage: p.show(viewer="tachyon", extra_opts="-mediumshade") # optional -- sage.symbolic """ from sage.repl.rich_output import get_display_manager dm = get_display_manager() @@ -1986,10 +1990,10 @@ end_scene""".format( EXAMPLES:: - sage: x,y,z = var('x,y,z') - sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) - sage: astl = a.stl_binary() - sage: print(astl[:40].decode('ascii')) + sage: x,y,z = var('x,y,z') # optional -- sage.symbolic + sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) # optional -- sage.symbolic + sage: astl = a.stl_binary() # optional -- sage.symbolic + sage: print(astl[:40].decode('ascii')) # optional -- sage.symbolic STL binary file / made by SageMath / ### sage: p = polygon3d([[0,0,0], [1,2,3], [3,0,0]]) @@ -1998,9 +2002,9 @@ end_scene""".format( This works when faces have more then 3 sides:: - sage: P = polytopes.dodecahedron() - sage: Q = P.plot().all[-1] - sage: print(Q.stl_binary()[:40].decode('ascii')) + sage: P = polytopes.dodecahedron() # optional -- sage.geometry.polyhedron + sage: Q = P.plot().all[-1] # optional -- sage.geometry.polyhedron + sage: print(Q.stl_binary()[:40].decode('ascii')) # optional -- sage.geometry.polyhedron STL binary file / made by SageMath / ### """ import struct @@ -2033,10 +2037,10 @@ end_scene""".format( EXAMPLES:: - sage: x,y,z = var('x,y,z') - sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) - sage: astl = a.stl_ascii_string() - sage: astl.splitlines()[:7] # abs tol 1e-10 + sage: x,y,z = var('x,y,z') # optional -- sage.symbolic + sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) # optional -- sage.symbolic + sage: astl = a.stl_ascii_string() # optional -- sage.symbolic + sage: astl.splitlines()[:7] # abs tol 1e-10 # optional -- sage.symbolic ['solid surface', 'facet normal 0.9733285267845754 -0.16222142113076257 -0.16222142113076257', ' outer loop', @@ -2059,9 +2063,9 @@ end_scene""".format( Now works when faces have more then 3 sides:: - sage: P = polytopes.dodecahedron() - sage: Q = P.plot().all[-1] - sage: print(Q.stl_ascii_string().splitlines()[:7]) + sage: P = polytopes.dodecahedron() # optional -- sage.geometry.polyhedron + sage: Q = P.plot().all[-1] # optional -- sage.geometry.polyhedron + sage: print(Q.stl_ascii_string().splitlines()[:7]) # optional -- sage.geometry.polyhedron ['solid surface', 'facet normal 0.0 0.5257311121191338 0.8506508083520399', ' outer loop', @@ -2128,10 +2132,10 @@ end_scene""".format( EXAMPLES:: - sage: x,y,z = var('x,y,z') - sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) - sage: astl = a.ply_ascii_string() - sage: astl.splitlines()[:10] + sage: x,y,z = var('x,y,z') # optional -- sage.symbolic + sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) # optional -- sage.symbolic + sage: astl = a.ply_ascii_string() # optional -- sage.symbolic + sage: astl.splitlines()[:10] # optional -- sage.symbolic ['ply', 'format ascii 1.0', 'comment surface', @@ -2202,10 +2206,10 @@ end_scene""".format( EXAMPLES:: - sage: x,y,z = var('x,y,z') - sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) - sage: a_amf = a.amf_ascii_string() - sage: a_amf[:160] + sage: x,y,z = var('x,y,z') # optional -- sage.symbolic + sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) # optional -- sage.symbolic + sage: a_amf = a.amf_ascii_string() # optional -- sage.symbolic + sage: a_amf[:160] # optional -- sage.symbolic '2.948717948717948-0.384615384615385-0.3935' sage: p = polygon3d([[0,0,0], [1,2,3], [3,0,0]]) @@ -2601,6 +2605,7 @@ class TransformGroup(Graphics3dGroup): EXAMPLES:: + sage: from math import pi sage: G = cube() sage: G.bounding_box() ((-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)) diff --git a/src/sage/plot/plot3d/index_face_set.pyx b/src/sage/plot/plot3d/index_face_set.pyx index de30b24c0fd..16421d54726 100644 --- a/src/sage/plot/plot3d/index_face_set.pyx +++ b/src/sage/plot/plot3d/index_face_set.pyx @@ -398,19 +398,21 @@ cdef class IndexFaceSet(PrimitiveObject): EXAMPLES:: - sage: var('x,y,z') + sage: var('x,y,z') # optional - sage.symbolic (x, y, z) - sage: G = implicit_plot3d(x^2+y^2+z^2 - 1, (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=6) - sage: G.triangulate() # indirect doctest - sage: len(G.face_list()) + sage: G = implicit_plot3d(x^2+y^2+z^2 - 1, # optional - sage.symbolic + ....: (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=6) + sage: G.triangulate() # indirect doctest # optional - sage.symbolic + sage: len(G.face_list()) # optional - sage.symbolic 44 - sage: len(G.vertex_list()) + sage: len(G.vertex_list()) # optional - sage.symbolic 132 - sage: G = implicit_plot3d(x^2+y^2+z^2 - 100, (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=6) - sage: G.triangulate() # indirect doctest - sage: len(G.face_list()) + sage: G = implicit_plot3d(x^2+y^2+z^2 - 100, # optional - sage.symbolic + ....: (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=6) + sage: G.triangulate() # indirect doctest # optional - sage.symbolic + sage: len(G.face_list()) # optional - sage.symbolic 0 - sage: len(G.vertex_list()) + sage: len(G.vertex_list()) # optional - sage.symbolic 0 """ self.vs = check_reallocarray(self.vs, vcount, sizeof(point_c)) @@ -898,9 +900,9 @@ cdef class IndexFaceSet(PrimitiveObject): EXAMPLES:: - sage: x,y = var('x,y') - sage: p = plot3d(sqrt(sin(x)*sin(y)), (x,0,2*pi),(y,0,2*pi)) - sage: p.bounding_box() + sage: x,y = var('x,y') # optional - sage.symbolic + sage: p = plot3d(sqrt(sin(x)*sin(y)), (x,0,2*pi), (y,0,2*pi)) # optional - sage.symbolic + sage: p.bounding_box() # optional - sage.symbolic ((0.0, 0.0, 0.0), (6.283185307179586, 6.283185307179586, 0.9991889981715697)) """ if self.vcount == 0: @@ -1008,12 +1010,12 @@ cdef class IndexFaceSet(PrimitiveObject): EXAMPLES:: - sage: var('x,y,z') + sage: var('x,y,z') # optional - sage.symbolic (x, y, z) - sage: P = implicit_plot3d(z-x*y,(-2,2),(-2,2),(-2,2)) + sage: P = implicit_plot3d(z-x*y,(-2,2),(-2,2),(-2,2)) # optional - sage.symbolic sage: def condi(x,y,z): ....: return bool(x*x+y*y+z*z <= Integer(1)) - sage: R = P.add_condition(condi,20);R + sage: R = P.add_condition(condi, 20); R # optional - sage.symbolic Graphics3d Object .. PLOT:: @@ -1030,9 +1032,9 @@ cdef class IndexFaceSet(PrimitiveObject): ....: return bool(x*x+y*y <= 1.1) sage: cm = colormaps.hsv sage: cf = lambda x,y,z: float(x+y) % 1 - sage: P = implicit_plot3d(x**2+y**2+z**2-1-x**2*z+y**2*z, + sage: P = implicit_plot3d(x**2+y**2+z**2-1-x**2*z+y**2*z, # optional - sage.symbolic ....: (-2,2),(-2,2),(-2,2),color=(cm,cf)) - sage: R = P.add_condition(condi,40); R + sage: R = P.add_condition(condi,40); R # optional - sage.symbolic Graphics3d Object .. PLOT:: @@ -1047,11 +1049,11 @@ cdef class IndexFaceSet(PrimitiveObject): An example with transparency:: - sage: P = implicit_plot3d(x**4+y**4+z**2-4, (x,-2,2), (y,-2,2), (z,-2,2), + sage: P = implicit_plot3d(x**4+y**4+z**2-4, (x,-2,2), (y,-2,2), (z,-2,2), # optional - sage.symbolic ....: alpha=0.3) sage: def cut(a,b,c): ....: return a*a+c*c > 2 - sage: Q = P.add_condition(cut,40); Q + sage: Q = P.add_condition(cut,40); Q # optional - sage.symbolic Graphics3d Object .. PLOT:: @@ -1064,11 +1066,11 @@ cdef class IndexFaceSet(PrimitiveObject): A sombrero with quadrilaterals:: - sage: P = plot3d(-sin(2*x*x+2*y*y)*exp(-x*x-y*y), (x,-2,2), (y,-2,2), + sage: P = plot3d(-sin(2*x*x+2*y*y)*exp(-x*x-y*y), (x,-2,2), (y,-2,2), # optional - sage.symbolic ....: color='gold') sage: def cut(x,y,z): ....: return x*x+y*y < 1 - sage: Q = P.add_condition(cut);Q + sage: Q = P.add_condition(cut);Q # optional - sage.symbolic Graphics3d Object .. PLOT:: @@ -1083,13 +1085,13 @@ cdef class IndexFaceSet(PrimitiveObject): One test for preservation of transparency :trac:`28783`:: - sage: x,y,z = var('x,y,z') - sage: P = plot3d(cos(x*y),(x,-2,2),(y,-2,2),color='red',opacity=0.1) + sage: x,y,z = var('x,y,z') # optional - sage.symbolic + sage: P = plot3d(cos(x*y),(x,-2,2),(y,-2,2),color='red',opacity=0.1) # optional - sage.symbolic sage: def condi(x,y,z): ....: return not(x*x+y*y <= 1) - sage: Q = P.add_condition(condi, 40) - sage: L = Q.json_repr(Q.default_render_params()) - sage: '"opacity":0.1' in L[-1] + sage: Q = P.add_condition(condi, 40) # optional - sage.symbolic + sage: L = Q.json_repr(Q.default_render_params()) # optional - sage.symbolic + sage: '"opacity":0.1' in L[-1] # optional - sage.symbolic True A test that this works with polygons:: @@ -1097,7 +1099,7 @@ cdef class IndexFaceSet(PrimitiveObject): sage: p = polygon3d([[2,0,0], [0,2,0], [0,0,3]]) sage: def f(x,y,z): ....: return bool(x*x+y*y+z*z<=5) - sage: cut = p.add_condition(f,60,1.0e-12); cut.face_list() + sage: cut = p.add_condition(f,60,1.0e-12); cut.face_list() # optional - sage.symbolic [[(0.556128491210302, 0.0, 2.165807263184547), (2.0, 0.0, 0.0), (0.0, 2.0, 0.0), diff --git a/src/sage/plot/plot3d/parametric_plot3d.py b/src/sage/plot/plot3d/parametric_plot3d.py index d1b352410da..fece32eda71 100644 --- a/src/sage/plot/plot3d/parametric_plot3d.py +++ b/src/sage/plot/plot3d/parametric_plot3d.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.symbolic """ Parametric plots """ diff --git a/src/sage/plot/plot3d/parametric_surface.pyx b/src/sage/plot/plot3d/parametric_surface.pyx index 4396c303561..e1f778215b5 100644 --- a/src/sage/plot/plot3d/parametric_surface.pyx +++ b/src/sage/plot/plot3d/parametric_surface.pyx @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.symbolic r""" Parametric surface @@ -468,7 +468,8 @@ cdef class ParametricSurface(IndexFaceSet): sage: from sage.plot.plot3d.parametric_surface import MoebiusStrip sage: M = MoebiusStrip(7,3,2) sage: M.bounding_box() - ((-10.0, -7.53907349250478..., -2.9940801852848145), (10.0, 7.53907349250478..., 2.9940801852848145)) + ((-10.0, -7.53907349250478..., -2.9940801852848145), + (10.0, 7.53907349250478..., 2.9940801852848145)) """ # We must triangulate before computing the bounding box; otherwise # we'll get an empty bounding box, as the bounding box is computed @@ -493,7 +494,7 @@ cdef class ParametricSurface(IndexFaceSet): sage: def f(x,y): return x+y, sin(x)*sin(y), x*y # indirect doctests sage: P = ParametricSurface(f, (srange(0,10,0.1), srange(-5,5.0,0.1))) # indirect doctests sage: P.show() # indirect doctests - sage: S = MoebiusStrip(1,.2) # indirect doctests + sage: S = MoebiusStrip(1, .2) # indirect doctests sage: S.show() # indirect doctests """ cdef double u, v diff --git a/src/sage/plot/plot3d/platonic.py b/src/sage/plot/plot3d/platonic.py index eee95d3290f..be590739c3e 100644 --- a/src/sage/plot/plot3d/platonic.py +++ b/src/sage/plot/plot3d/platonic.py @@ -226,13 +226,14 @@ def tetrahedron(center=(0, 0, 0), size=1, **kwds): A Dodecahedral complex of 5 tetrahedra (a more elaborate example from Peter Jipsen):: - sage: v=(sqrt(5.)/2-5/6, 5/6*sqrt(3.)-sqrt(15.)/2, sqrt(5.)/3) - sage: t=acos(sqrt(5.)/3)/2 - sage: t1=tetrahedron(aspect_ratio=(1,1,1), opacity=0.5).rotateZ(t) - sage: t2=tetrahedron(color='red', opacity=0.5).rotateZ(t).rotate(v,2*pi/5) - sage: t3=tetrahedron(color='green', opacity=0.5).rotateZ(t).rotate(v,4*pi/5) - sage: t4=tetrahedron(color='yellow', opacity=0.5).rotateZ(t).rotate(v,6*pi/5) - sage: t5=tetrahedron(color='orange', opacity=0.5).rotateZ(t).rotate(v,8*pi/5) + sage: from math import pi + sage: v = (sqrt(5.)/2-5/6, 5/6*sqrt(3.)-sqrt(15.)/2, sqrt(5.)/3) + sage: t = acos(sqrt(5.)/3)/2 + sage: t1 = tetrahedron(aspect_ratio=(1,1,1), opacity=0.5).rotateZ(t) + sage: t2 = tetrahedron(color='red', opacity=0.5).rotateZ(t).rotate(v,2*pi/5) + sage: t3 = tetrahedron(color='green', opacity=0.5).rotateZ(t).rotate(v,4*pi/5) + sage: t4 = tetrahedron(color='yellow', opacity=0.5).rotateZ(t).rotate(v,6*pi/5) + sage: t5 = tetrahedron(color='orange', opacity=0.5).rotateZ(t).rotate(v,8*pi/5) sage: show(t1+t2+t3+t4+t5, frame=False, zoom=1.3) .. PLOT:: diff --git a/src/sage/plot/plot3d/plot_field3d.py b/src/sage/plot/plot3d/plot_field3d.py index 2af26bf9c5d..fa84e05b307 100644 --- a/src/sage/plot/plot3d/plot_field3d.py +++ b/src/sage/plot/plot3d/plot_field3d.py @@ -1,4 +1,4 @@ -# optional - sage.symbolic +# sage.doctest: optional - sage.symbolic """ Plotting 3D fields """ diff --git a/src/sage/plot/plot3d/revolution_plot3d.py b/src/sage/plot/plot3d/revolution_plot3d.py index c99e7566688..dbbd3c77eb6 100644 --- a/src/sage/plot/plot3d/revolution_plot3d.py +++ b/src/sage/plot/plot3d/revolution_plot3d.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.plot """ Surfaces of revolution diff --git a/src/sage/plot/plot3d/shapes2.py b/src/sage/plot/plot3d/shapes2.py index 6eafbbcd3b1..7a53e9da179 100644 --- a/src/sage/plot/plot3d/shapes2.py +++ b/src/sage/plot/plot3d/shapes2.py @@ -117,6 +117,7 @@ def line3d(points, thickness=1, radius=None, arrow_head=False, **kwds): ....: (-sqrt(2.)/3,-sqrt(6.)/3,-1./3), (2*sqrt(2.)/3,0,-1./3)],\ ....: color=col, thickness=10, aspect_ratio=[1,1,1]) + sage: from math import pi sage: v = (sqrt(5.)/2-5/6, 5/6*sqrt(3.)-sqrt(15.)/2, sqrt(5.)/3) sage: t = acos(sqrt(5.)/3)/2 sage: t1 = tetra('blue').rotateZ(t) @@ -273,15 +274,16 @@ def bezier3d(path, **options): Check for :trac:`31640`:: - sage: p2d = [[(3,0.0),(3,0.13),(2,0.2),(2,0.3)], # optional - sage.symbolic + sage: p2d = [[(3,0.0),(3,0.13),(2,0.2),(2,0.3)], ....: [(2.7,0.4),(2.6,0.5),(2.5,0.5)], [(2.3,0.5),(2.2,0.4),(2.1,0.3)]] sage: bp = bezier_path(p2d) # optional - sage.symbolic sage: bp.plot3d() # optional - sage.symbolic Graphics3d Object - sage: p3d = [[(3,0,0),(3,0.1,0),(2.9,0.2,0),(2.8,0.3,0)], # optional - sage.symbolic - ....: [(2.7,0.4,0),(2,0.5,0),(2.5,0.5,0)], [(2.3,0.5,0),(2.2,0.4,0),(2.1,0.3,0)]] - sage: bezier3d(p3d) + sage: p3d = [[(3,0,0),(3,0.1,0),(2.9,0.2,0),(2.8,0.3,0)], + ....: [(2.7,0.4,0),(2,0.5,0),(2.5,0.5,0)], + ....: [(2.3,0.5,0),(2.2,0.4,0),(2.1,0.3,0)]] + sage: bezier3d(p3d) # optional - sage.symbolic Graphics3d Object """ from . import parametric_plot3d as P3D diff --git a/src/sage/plot/plot3d/tachyon.py b/src/sage/plot/plot3d/tachyon.py index a245541544a..b2130f39cd9 100644 --- a/src/sage/plot/plot3d/tachyon.py +++ b/src/sage/plot/plot3d/tachyon.py @@ -599,13 +599,13 @@ def show(self, **kwds): ....: viewdir=(-4,4,-3), raydepth=4) sage: d.light((4.4,-4.4,4.4), 0.2, (1,1,1)) sage: def f(x,y): return float(sin(x*y)) - sage: d.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, # optional -- sage.symbolic + sage: d.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, ....: opacity=1.0, color=(1.0,0,0)) - sage: d.plot(f,(-4,4),(-4,4),"t0",max_depth=5,initial_depth=3, + sage: d.plot(f,(-4,4),(-4,4),"t0",max_depth=5,initial_depth=3, # optional -- sage.symbolic ....: num_colors=60) # increase min_depth for better picture sage: get_verbose() 0 - sage: d.show(verbose=2) + sage: d.show(verbose=2) # optional -- sage.symbolic tachyon ... Scene contains 2713 objects. ... From adf8e486fadb63a3ed45c4ad70dec27d3c6d6747 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 19 Jun 2023 23:43:13 -0700 Subject: [PATCH 07/21] More # optional --- src/sage/plot/arc.py | 5 +++++ src/sage/plot/plot3d/shapes2.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sage/plot/arc.py b/src/sage/plot/arc.py index f65973bcbd5..84a62554118 100644 --- a/src/sage/plot/arc.py +++ b/src/sage/plot/arc.py @@ -45,6 +45,7 @@ class Arc(GraphicPrimitive): Note that the construction should be done using ``arc``:: + sage: from math import pi sage: from sage.plot.arc import Arc sage: print(Arc(0,0,1,1,pi/4,pi/4,pi/2,{})) Arc with center (0.0,0.0) radii (1.0,1.0) angle 0.78539816339... inside the sector (0.78539816339...,1.5707963267...) @@ -115,6 +116,7 @@ def get_minmax_data(self): The same example with a rotation of angle `\pi/2`:: + sage: from math import pi sage: p = arc((-2, 3), 1, 2, pi/2) sage: d = p.get_minmax_data() sage: d['xmin'] @@ -293,6 +295,7 @@ def bezier_path(self): sage: Arc(2,3,2.2,2.2,0,2,3,op).bezier_path() Graphics object consisting of 1 graphics primitive + sage: from math import pi sage: a = arc((0,0),2,1,0,(pi/5,pi/2+pi/12), linestyle="--", color="red") sage: b = a[0].bezier_path() sage: b[0] @@ -348,6 +351,7 @@ def _render_on_subplot(self, subplot): """ TESTS:: + sage: from math import pi sage: A = arc((1,1),3,4,pi/4,(pi,4*pi/3)); A Graphics object consisting of 1 graphics primitive """ @@ -421,6 +425,7 @@ def arc(center, r1, r2=None, angle=0.0, sector=(0.0, 2 * pi), **options): Plot an arc of circle centered at (0,0) with radius 1 in the sector `(\pi/4,3*\pi/4)`:: + sage: from math import pi sage: arc((0,0), 1, sector=(pi/4,3*pi/4)) Graphics object consisting of 1 graphics primitive diff --git a/src/sage/plot/plot3d/shapes2.py b/src/sage/plot/plot3d/shapes2.py index 7a53e9da179..55e87b2f53a 100644 --- a/src/sage/plot/plot3d/shapes2.py +++ b/src/sage/plot/plot3d/shapes2.py @@ -161,7 +161,7 @@ def tetra(col): This function should work for anything than can be turned into a list, such as iterators and such (see :trac:`10478`):: - sage: line3d(iter([(0,0,0), (sqrt(3), 2, 4)])) + sage: line3d(iter([(0,0,0), (sqrt(3), 2, 4)])) # optional - sage.symbolic Graphics3d Object sage: line3d((x, x^2, x^3) for x in range(5)) Graphics3d Object From ba4c9e4e399d8aca6483557dcdf4f3a36002c4b2 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 19:28:26 -0700 Subject: [PATCH 08/21] src/sage/plot/graphics.py: Fix doctest --- src/sage/plot/graphics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/plot/graphics.py b/src/sage/plot/graphics.py index 1070d9e262e..1518c7ec7a0 100644 --- a/src/sage/plot/graphics.py +++ b/src/sage/plot/graphics.py @@ -140,7 +140,7 @@ class Graphics(WithEqualityById, SageObject): sage: G = Graphics() sage: for x in srange(1, h+1): # optional - sage.symbolic ....: l = [[0,x*sqrt(3)],[-x/2,-x*sqrt(3)/2],[x/2,-x*sqrt(3)/2],[0,x*sqrt(3)]] - ....: G + =line(l, color=hue(c + p*(x/h))) + ....: G += line(l, color=hue(c + p*(x/h))) sage: G.show(figsize=[5,5]) # optional - sage.symbolic We can change the scale of the axes in the graphics before displaying.:: From 9f6c58c910c0fe118ebb2f2fb6f972e6bb4c7298 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 19:33:41 -0700 Subject: [PATCH 09/21] Update # optional / # needs --- src/sage/plot/matrix_plot.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/sage/plot/matrix_plot.py b/src/sage/plot/matrix_plot.py index 0999d7068d4..d34bd473829 100644 --- a/src/sage/plot/matrix_plot.py +++ b/src/sage/plot/matrix_plot.py @@ -132,8 +132,8 @@ def _allowed_options(self): EXAMPLES:: - sage: M = matrix_plot([[sin(i*j) for i in range(5)] for j in range(5)]) # optional - sage.symbolic - sage: isinstance(M[0]._allowed_options(), dict) # optional - sage.symbolic + sage: M = matrix_plot([[sin(i*j) for i in range(5)] for j in range(5)]) # needs sage.symbolic + sage: isinstance(M[0]._allowed_options(), dict) # needs sage.symbolic True """ return {'cmap':"""the name of a predefined colormap, @@ -158,8 +158,8 @@ def _repr_(self): EXAMPLES:: - sage: M = matrix_plot([[sin(i*j) for i in range(5)] for j in range(5)]) # optional - sage.symbolic - sage: m = M[0]; m # optional - sage.symbolic + sage: M = matrix_plot([[sin(i*j) for i in range(5)] for j in range(5)]) # needs sage.symbolic + sage: m = M[0]; m # needs sage.symbolic MatrixPlot defined by a 5 x 5 data grid """ return "MatrixPlot defined by a %s x %s data grid"%(self.xy_array_row, self.xy_array_col) @@ -412,9 +412,9 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): A custom bounding box in which to draw the matrix can be specified using the ``xrange`` and ``yrange`` arguments:: - sage: P = matrix_plot(identity_matrix(10), xrange=(0, pi), yrange=(-pi, 0)); P # optional - sage.symbolic + sage: P = matrix_plot(identity_matrix(10), xrange=(0, pi), yrange=(-pi, 0)); P # needs sage.symbolic Graphics object consisting of 1 graphics primitive - sage: P.get_minmax_data() # optional - sage.symbolic + sage: P.get_minmax_data() # needs sage.symbolic {'xmax': 3.14159..., 'xmin': 0.0, 'ymax': 0.0, 'ymin': -3.14159...} If the horizontal and vertical dimension of the image are very different, @@ -427,13 +427,13 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): Another random plot, but over `\GF{389}`:: - sage: m = random_matrix(GF(389), 10) # optional - sage.rings.finite_rings - sage: matrix_plot(m, cmap='Oranges') # optional - sage.rings.finite_rings + sage: m = random_matrix(GF(389), 10) # needs sage.rings.finite_rings + sage: matrix_plot(m, cmap='Oranges') # needs sage.rings.finite_rings Graphics object consisting of 1 graphics primitive It also works if you lift it to the polynomial ring:: - sage: matrix_plot(m.change_ring(GF(389)['x']), cmap='Oranges') # optional - sage.rings.finite_rings + sage: matrix_plot(m.change_ring(GF(389)['x']), cmap='Oranges') # needs sage.rings.finite_rings Graphics object consisting of 1 graphics primitive We have several options for colorbars:: @@ -474,8 +474,8 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): converted to floating point numbers before plotting. Thus the following works:: - sage: b = random_matrix(GF(2), 200, sparse=True, density=0.01) # optional - sage.rings.finite_rings - sage: matrix_plot(b) + sage: b = random_matrix(GF(2), 200, sparse=True, density=0.01) # needs sage.rings.finite_rings + sage: matrix_plot(b) # needs sage.rings.finite_rings Graphics object consisting of 1 graphics primitive While this returns an error:: @@ -500,8 +500,8 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): As does plotting of NumPy arrays:: - sage: import numpy # optional - numpy - sage: matrix_plot(numpy.random.rand(10, 10)) # optional - numpy + sage: import numpy # needs numpy + sage: matrix_plot(numpy.random.rand(10, 10)) # needs numpy Graphics object consisting of 1 graphics primitive A plot title can be added to the matrix plot.:: From 44f3ec5c70ceaf1131e2f64fc96da169d91d1d74 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 5 Aug 2023 15:25:25 -0700 Subject: [PATCH 10/21] src/sage/plot: sage -fixdoctests --only-tags, use more block tags --- src/sage/plot/animate.py | 60 ++-- src/sage/plot/arrow.py | 2 +- src/sage/plot/bezier_path.py | 8 +- src/sage/plot/complex_plot.pyx | 103 +++--- src/sage/plot/graphics.py | 426 ++++++++++++------------ src/sage/plot/line.py | 19 +- src/sage/plot/plot.py | 145 ++++---- src/sage/plot/plot3d/base.pyx | 64 ++-- src/sage/plot/plot3d/index_face_set.pyx | 56 ++-- src/sage/plot/plot3d/shapes.pyx | 24 +- src/sage/plot/plot3d/shapes2.py | 57 ++-- src/sage/plot/plot3d/tachyon.py | 74 ++-- src/sage/plot/point.py | 22 +- src/sage/plot/polygon.py | 44 +-- src/sage/plot/text.py | 4 +- 15 files changed, 579 insertions(+), 529 deletions(-) diff --git a/src/sage/plot/animate.py b/src/sage/plot/animate.py index fb54a378545..7a766674099 100644 --- a/src/sage/plot/animate.py +++ b/src/sage/plot/animate.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic r""" Animated plots @@ -526,27 +526,28 @@ def graphics_array(self, ncols=3): EXAMPLES:: - sage: E = EllipticCurve('37a') # optional - sage.schemes - sage: v = [E.change_ring(GF(p)).plot(pointsize=30) # optional - sage.rings.finite_rings sage.schemes + sage: # needs sage.schemes + sage: E = EllipticCurve('37a') + sage: v = [E.change_ring(GF(p)).plot(pointsize=30) ....: for p in [97, 101, 103]] - sage: a = animate(v, xmin=0, ymin=0, axes=False) # optional - sage.rings.finite_rings sage.schemes - sage: print(a) # optional - sage.rings.finite_rings sage.schemes + sage: a = animate(v, xmin=0, ymin=0, axes=False) + sage: print(a) Animation with 3 frames - sage: a.show() # optional -- ImageMagick # optional - sage.rings.finite_rings sage.schemes + sage: a.show() # optional - imagemagick Modify the default arrangement of array:: - sage: g = a.graphics_array(); print(g) # optional - sage.rings.finite_rings sage.schemes + sage: g = a.graphics_array(); print(g) # needs sage.schemes Graphics Array of size 1 x 3 - sage: g.show(figsize=[6,3]) # optional - sage.rings.finite_rings sage.schemes + sage: g.show(figsize=[6,3]) # needs sage.schemes Specify different arrangement of array and save it with a given file name:: - sage: g = a.graphics_array(ncols=2); print(g) # optional - sage.rings.finite_rings sage.schemes + sage: g = a.graphics_array(ncols=2); print(g) # needs sage.schemes Graphics Array of size 2 x 2 - sage: f = tmp_filename(ext='.png'); print(f) # optional - sage.rings.finite_rings sage.schemes + sage: f = tmp_filename(ext='.png'); print(f) # needs sage.schemes ...png - sage: g.save(f) # optional - sage.rings.finite_rings sage.schemes + sage: g.save(f) # needs sage.schemes Frames can be specified as a generator too; it is internally converted to a list:: @@ -852,18 +853,20 @@ def show(self, delay=None, iterations=None, **kwds): You can also make use of the HTML5 video element in the Sage Notebook:: - sage: a.show(format="ogg") # long time # optional -- ffmpeg - sage: a.show(format="webm") # long time # optional -- ffmpeg - sage: a.show(format="mp4") # long time # optional -- ffmpeg - sage: a.show(format="webm", iterations=1) # long time # optional -- ffmpeg + sage: # long time, optional - ffmpeg + sage: a.show(format="ogg") + sage: a.show(format="webm") + sage: a.show(format="mp4") + sage: a.show(format="webm", iterations=1) Other backends may support other file formats as well:: - sage: a.show(format="flash") # long time # optional -- ffmpeg - sage: a.show(format="matroska") # long time # optional -- ffmpeg - sage: a.show(format="avi") # long time # optional -- ffmpeg - sage: a.show(format="wmv") # long time # optional -- ffmpeg - sage: a.show(format="quicktime") # long time # optional -- ffmpeg + sage: # long time, optional - ffmpeg + sage: a.show(format="flash") + sage: a.show(format="matroska") + sage: a.show(format="avi") + sage: a.show(format="wmv") + sage: a.show(format="quicktime") TESTS: @@ -1163,22 +1166,23 @@ def save(self, filename=None, show_path=False, use_ffmpeg=False, **kwds): Ensure that we can pass delay and iteration count to the saved GIF image (see :trac:`18176`):: - sage: a.save(td + 'wave.gif') # long time # optional -- ImageMagick - sage: with open(td + 'wave.gif', 'rb') as f: # long time # optional -- ImageMagick + sage: # long time, optional - imagemagick + sage: a.save(td + 'wave.gif') + sage: with open(td + 'wave.gif', 'rb') as f: ....: print(b'GIF8' in f.read()) True - sage: with open(td + 'wave.gif', 'rb') as f: # long time # optional -- ImageMagick + sage: with open(td + 'wave.gif', 'rb') as f: ....: print(b'!\xff\x0bNETSCAPE2.0\x03\x01\x00\x00\x00' in f.read()) True - sage: a.save(td + 'wave.gif', delay=35) # long time # optional -- ImageMagick - sage: with open(td + 'wave.gif', 'rb') as f: # long time # optional -- ImageMagick + sage: a.save(td + 'wave.gif', delay=35) + sage: with open(td + 'wave.gif', 'rb') as f: ....: print(b'GIF8' in f.read()) True - sage: a.save(td + 'wave.gif', iterations=3) # long time # optional -- ImageMagick - sage: with open(td + 'wave.gif', 'rb') as f: # long time # optional -- ImageMagick + sage: a.save(td + 'wave.gif', iterations=3) + sage: with open(td + 'wave.gif', 'rb') as f: ....: print(b'!\xff\x0bNETSCAPE2.0\x03\x01\x00\x00\x00' in f.read()) False - sage: with open(td + 'wave.gif', 'rb') as f: # long time # optional -- ImageMagick + sage: with open(td + 'wave.gif', 'rb') as f: ....: check1 = b'!\xff\x0bNETSCAPE2.0\x03\x01\x02\x00\x00' ....: check2 = b'!\xff\x0bNETSCAPE2.0\x03\x01\x03\x00\x00' ....: data = f.read() diff --git a/src/sage/plot/arrow.py b/src/sage/plot/arrow.py index c2e08d38dd8..179e026d2e4 100644 --- a/src/sage/plot/arrow.py +++ b/src/sage/plot/arrow.py @@ -586,7 +586,7 @@ def arrow2d(tailpoint=None, headpoint=None, path=None, **options): A pretty circle of arrows:: - sage: sum(arrow2d((0,0), (cos(x),sin(x)), hue=x/(2*pi)) # optional - sage.symbolic + sage: sum(arrow2d((0,0), (cos(x),sin(x)), hue=x/(2*pi)) # needs sage.symbolic ....: for x in [0..2*pi, step=0.1]) Graphics object consisting of 63 graphics primitives diff --git a/src/sage/plot/bezier_path.py b/src/sage/plot/bezier_path.py index cbaa4de4049..a8bffed51ba 100644 --- a/src/sage/plot/bezier_path.py +++ b/src/sage/plot/bezier_path.py @@ -168,9 +168,9 @@ def plot3d(self, z=0, **kwds): EXAMPLES:: sage: b = bezier_path([[(0,0),(0,1),(1,0)]]) - sage: A = b.plot3d() # optional - sage.symbolic - sage: B = b.plot3d(z=2) # optional - sage.symbolic - sage: A + B # optional - sage.symbolic + sage: A = b.plot3d() # needs sage.symbolic + sage: B = b.plot3d(z=2) # needs sage.symbolic + sage: A + B # needs sage.symbolic Graphics3d Object .. PLOT:: @@ -182,7 +182,7 @@ def plot3d(self, z=0, **kwds): :: - sage: bezier3d([[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]]) # optional - sage.symbolic + sage: bezier3d([[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]]) # needs sage.symbolic Graphics3d Object .. PLOT:: diff --git a/src/sage/plot/complex_plot.pyx b/src/sage/plot/complex_plot.pyx index 933bcea9894..c2342341ab8 100644 --- a/src/sage/plot/complex_plot.pyx +++ b/src/sage/plot/complex_plot.pyx @@ -669,11 +669,13 @@ def add_lightness_smoothing_to_rgb(rgb, delta): We can call this on grids of values:: - sage: import numpy as np # optional - numpy - sage: from sage.plot.complex_plot import add_lightness_smoothing_to_rgb # optional - numpy - sage: add_lightness_smoothing_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 # optional - numpy + sage: import numpy as np # needs numpy + sage: from sage.plot.complex_plot import add_lightness_smoothing_to_rgb # needs numpy + sage: add_lightness_smoothing_to_rgb( # abs tol 1e-4 # needs numpy + ....: np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) array([[[0.75 , 0.8125, 0.875 ]]]) - sage: add_lightness_smoothing_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 # optional - numpy + sage: add_lightness_smoothing_to_rgb( # abs tol 1e-4 # needs numpy + ....: np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) array([[[0.75 , 0.8125, 0.875 ]]]) """ import numpy as np @@ -731,21 +733,25 @@ def add_contours_to_rgb(rgb, delta, dark_rate=0.5): EXAMPLES:: - sage: import numpy as np # optional - numpy - sage: from sage.plot.complex_plot import add_contours_to_rgb # optional - numpy - sage: add_contours_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 # optional - numpy + sage: # needs numpy + sage: import numpy as np # needs numpy + sage: from sage.plot.complex_plot import add_contours_to_rgb # needs numpy + sage: add_contours_to_rgb(np.array([[[0, 0.25, 0.5]]]), # abs tol 1e-4 # needs numpy + ....: np.array([[0.75]])) array([[[0.25 , 0.625, 1. ]]]) - sage: add_contours_to_rgb(np.array([[[0, 0, 0]]]), np.array([[1]])) # abs tol 1e-4 # optional - numpy + sage: add_contours_to_rgb(np.array([[[0, 0, 0]]]), # abs tol 1e-4 # needs numpy + ....: np.array([[1]])) array([[[0.5, 0.5, 0.5]]]) - sage: add_contours_to_rgb(np.array([[[1, 1, 1]]]), np.array([[-0.5]])) # abs tol 1e-4 # optional - numpy + sage: add_contours_to_rgb(np.array([[[1, 1, 1]]]), # abs tol 1e-4 # needs numpy + ....: np.array([[-0.5]])) array([[[0.75, 0.75, 0.75]]]) Raising ``dark_rate`` leads to bigger adjustments:: - sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 # optional - numpy + sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 # needs numpy ....: np.array([[0.5]]), dark_rate=0.1) array([[[0.55, 0.55, 0.55]]]) - sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 # optional - numpy + sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 # needs numpy ....: np.array([[0.5]]), dark_rate=0.5) array([[[0.75, 0.75, 0.75]]]) """ @@ -927,7 +933,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Here we plot a couple of simple functions:: - sage: complex_plot(sqrt(x), (-5, 5), (-5, 5)) # optional - sage.symbolic + sage: complex_plot(sqrt(x), (-5, 5), (-5, 5)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -936,7 +942,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, :: - sage: complex_plot(sin(x), (-5, 5), (-5, 5)) # optional - sage.symbolic + sage: complex_plot(sin(x), (-5, 5), (-5, 5)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -945,7 +951,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, :: - sage: complex_plot(log(x), (-10, 10), (-10, 10)) # optional - sage.symbolic + sage: complex_plot(log(x), (-10, 10), (-10, 10)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -954,7 +960,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, :: - sage: complex_plot(exp(x), (-10, 10), (-10, 10)) # optional - sage.symbolic + sage: complex_plot(exp(x), (-10, 10), (-10, 10)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -963,7 +969,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, A plot with a different choice of colormap:: - sage: complex_plot(exp(x), (-10, 10), (-10, 10), cmap='viridis') # optional - sage.symbolic + sage: complex_plot(exp(x), (-10, 10), (-10, 10), cmap='viridis') # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -972,8 +978,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, A function with some nice zeros and a pole:: - sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic - sage: complex_plot(f, (-3, 3), (-3, 3)) # optional - sage.symbolic + sage: f(z) = z^5 + z - 1 + 1/z # needs sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -984,8 +990,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, The same function as above, but with contours. Contours render poorly with few plot points, so we use 300 here:: - sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic - sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, contoured=True) # optional - sage.symbolic + sage: f(z) = z^5 + z - 1 + 1/z # needs sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, contoured=True) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -995,8 +1001,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, The same function as above, but tiled and with the *plasma* colormap:: - sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic - sage: complex_plot(f, (-3, 3), (-3, 3), # optional - sage.symbolic + sage: f(z) = z^5 + z - 1 + 1/z # needs sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), # needs sage.symbolic ....: plot_points=300, tiled=True, cmap='plasma') Graphics object consisting of 1 graphics primitive @@ -1009,8 +1015,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, controlled by adjusting ``nphases``. We make the same plot with fewer tilings:: - sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic - sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, # optional - sage.symbolic + sage: f(z) = z^5 + z - 1 + 1/z # needs sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, # needs sage.symbolic ....: tiled=True, nphases=5, cmap='plasma') Graphics object consisting of 1 graphics primitive @@ -1022,8 +1028,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, It is also possible to use *linear* contours. We plot the same function above on an inset, setting contours to appear `1` apart:: - sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic - sage: complex_plot(f, (0, 1), (0, 1), plot_points=300, # optional - sage.symbolic + sage: f(z) = z^5 + z - 1 + 1/z # needs sage.symbolic + sage: complex_plot(f, (0, 1), (0, 1), plot_points=300, # needs sage.symbolic ....: contoured=True, contour_type='linear', contour_base=1) Graphics object consisting of 1 graphics primitive @@ -1035,8 +1041,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Note that tightly spaced contours can lead to Moiré patterns and aliasing problems. For example:: - sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic - sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, # optional - sage.symbolic + sage: f(z) = z^5 + z - 1 + 1/z # needs sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, # needs sage.symbolic ....: contoured=True, contour_type='linear', contour_base=1) Graphics object consisting of 1 graphics primitive @@ -1049,8 +1055,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, be considered more appropriate for showing changes in phase without sharp color contrasts:: - sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic - sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, cmap='twilight') # optional - sage.symbolic + sage: f(z) = z^5 + z - 1 + 1/z # needs sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), plot_points=300, cmap='twilight') # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1061,8 +1067,8 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Passing *matplotlib* as the colormap gives a special colormap that is similar to the default:: - sage: f(z) = z^5 + z - 1 + 1/z # optional - sage.symbolic - sage: complex_plot(f, (-3, 3), (-3, 3), # optional - sage.symbolic + sage: f(z) = z^5 + z - 1 + 1/z # needs sage.symbolic + sage: complex_plot(f, (-3, 3), (-3, 3), # needs sage.symbolic ....: plot_points=300, contoured=True, cmap='matplotlib') Graphics object consisting of 1 graphics primitive @@ -1073,7 +1079,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Here is the identity, useful for seeing what values map to what colors:: - sage: complex_plot(lambda z: z, (-3, 3), (-3, 3)) # optional - sage.symbolic + sage: complex_plot(lambda z: z, (-3, 3), (-3, 3)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1082,7 +1088,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, The Riemann Zeta function:: - sage: complex_plot(zeta, (-30,30), (-30,30)) # optional - sage.symbolic + sage: complex_plot(zeta, (-30,30), (-30,30)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1093,7 +1099,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, ``dark_rate`` will make regions become darker/lighter faster when there are no contours:: - sage: complex_plot(zeta, (-30, 30), (-30, 30), dark_rate=1.0) # optional - sage.symbolic + sage: complex_plot(zeta, (-30, 30), (-30, 30), dark_rate=1.0) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1103,7 +1109,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Decreasing ``dark_rate`` has the opposite effect. When there are contours, adjust ``dark_rate`` affects how visible contours are. Compare:: - sage: complex_plot(zeta, (-1, 9), (10, 20), plot_points=200, # long time # optional - sage.symbolic + sage: complex_plot(zeta, (-1, 9), (10, 20), plot_points=200, # long time, needs sage.symbolic ....: contoured=True, cmap='twilight', dark_rate=0.2) Graphics object consisting of 1 graphics primitive @@ -1113,7 +1119,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, and:: - sage: complex_plot(zeta, (-1, 9), (10, 20), plot_points=200, # long time # optional - sage.symbolic + sage: complex_plot(zeta, (-1, 9), (10, 20), plot_points=200, # long time, needs sage.symbolic ....: contoured=True, cmap='twilight', dark_rate=0.75) Graphics object consisting of 1 graphics primitive @@ -1126,12 +1132,12 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Extra options will get passed on to show(), as long as they are valid:: - sage: complex_plot(lambda z: z, (-3, 3), (-3, 3), figsize=[1,1]) # optional - sage.symbolic + sage: complex_plot(lambda z: z, (-3, 3), (-3, 3), figsize=[1,1]) # needs sage.symbolic Graphics object consisting of 1 graphics primitive :: - sage: complex_plot(lambda z: z, (-3, 3), (-3, 3)).show(figsize=[1,1]) # These are equivalent # optional - sage.symbolic + sage: complex_plot(lambda z: z, (-3, 3), (-3, 3)).show(figsize=[1,1]) # These are equivalent # needs sage.symbolic REFERENCES: @@ -1143,14 +1149,15 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, Test to make sure that using fast_callable functions works:: - sage: f(x) = x^2 # optional - sage.symbolic - sage: g = fast_callable(f, domain=CC, vars='x') # optional - sage.symbolic - sage: h = fast_callable(f, domain=CDF, vars='x') # optional - sage.symbolic - sage: P = complex_plot(f, (-10, 10), (-10, 10)) # optional - sage.symbolic - sage: Q = complex_plot(g, (-10, 10), (-10, 10)) # optional - sage.symbolic - sage: R = complex_plot(h, (-10, 10), (-10, 10)) # optional - sage.symbolic - sage: S = complex_plot(exp(x)-sin(x), (-10, 10), (-10, 10)) # optional - sage.symbolic - sage: P; Q; R; S # optional - sage.symbolic + sage: # needs sage.symbolic + sage: f(x) = x^2 + sage: g = fast_callable(f, domain=CC, vars='x') + sage: h = fast_callable(f, domain=CDF, vars='x') + sage: P = complex_plot(f, (-10, 10), (-10, 10)) + sage: Q = complex_plot(g, (-10, 10), (-10, 10)) + sage: R = complex_plot(h, (-10, 10), (-10, 10)) + sage: S = complex_plot(exp(x)-sin(x), (-10, 10), (-10, 10)) + sage: P; Q; R; S Graphics object consisting of 1 graphics primitive Graphics object consisting of 1 graphics primitive Graphics object consisting of 1 graphics primitive @@ -1162,7 +1169,7 @@ def complex_plot(f, x_range, y_range, contoured=False, tiled=False, cmap=None, :: - sage: complex_plot(sqrt, (-5, 5), (-5, 5)) # optional - sage.symbolic + sage: complex_plot(sqrt, (-5, 5), (-5, 5)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive """ import matplotlib as mpl diff --git a/src/sage/plot/graphics.py b/src/sage/plot/graphics.py index 1518c7ec7a0..1cd1e88f8a7 100644 --- a/src/sage/plot/graphics.py +++ b/src/sage/plot/graphics.py @@ -138,15 +138,15 @@ class Graphics(WithEqualityById, SageObject): sage: h = 10; c = 0.4; p = 0.5 sage: G = Graphics() - sage: for x in srange(1, h+1): # optional - sage.symbolic + sage: for x in srange(1, h+1): # needs sage.symbolic ....: l = [[0,x*sqrt(3)],[-x/2,-x*sqrt(3)/2],[x/2,-x*sqrt(3)/2],[0,x*sqrt(3)]] ....: G += line(l, color=hue(c + p*(x/h))) - sage: G.show(figsize=[5,5]) # optional - sage.symbolic + sage: G.show(figsize=[5,5]) # needs sage.symbolic We can change the scale of the axes in the graphics before displaying.:: - sage: G = plot(exp, 1, 10) # long time # optional - sage.symbolic - sage: G.show(scale='semilogy') # long time # optional - sage.symbolic + sage: G = plot(exp, 1, 10) # long time # needs sage.symbolic + sage: G.show(scale='semilogy') # long time # needs sage.symbolic TESTS: @@ -212,32 +212,32 @@ def set_aspect_ratio(self, ratio): EXAMPLES: We create a plot of the upper half of a circle, but it doesn't look round because the aspect ratio is off:: - sage: P = plot(sqrt(1-x^2),(x,-1,1)); P # optional - sage.symbolic + sage: P = plot(sqrt(1-x^2),(x,-1,1)); P # needs sage.symbolic Graphics object consisting of 1 graphics primitive So we set the aspect ratio and now it is round:: - sage: P.set_aspect_ratio(1) # optional - sage.symbolic - sage: P.aspect_ratio() # optional - sage.symbolic + sage: P.set_aspect_ratio(1) # needs sage.symbolic + sage: P.aspect_ratio() # needs sage.symbolic 1.0 - sage: P # optional - sage.symbolic + sage: P # needs sage.symbolic Graphics object consisting of 1 graphics primitive Note that the aspect ratio is inherited upon addition (which takes the max of aspect ratios of objects whose aspect ratio has been set):: - sage: P + plot(sqrt(4-x^2),(x,-2,2)) # optional - sage.symbolic + sage: P + plot(sqrt(4-x^2),(x,-2,2)) # needs sage.symbolic Graphics object consisting of 2 graphics primitives In the following example, both plots produce a circle that looks twice as tall as wide:: sage: Q = circle((0,0), 0.5); Q.set_aspect_ratio(2) - sage: (P + Q).aspect_ratio(); P + Q # optional - sage.symbolic + sage: (P + Q).aspect_ratio(); P + Q # needs sage.symbolic 2.0 Graphics object consisting of 2 graphics primitives - sage: (Q + P).aspect_ratio(); Q + P # optional - sage.symbolic + sage: (Q + P).aspect_ratio(); Q + P # needs sage.symbolic 2.0 Graphics object consisting of 2 graphics primitives """ @@ -293,23 +293,24 @@ def legend(self, show=None): By default no legend is displayed:: - sage: P = plot(sin) # optional - sage.symbolic - sage: P.legend() # optional - sage.symbolic + sage: P = plot(sin) # needs sage.symbolic + sage: P.legend() # needs sage.symbolic False But if we put a label then the legend is shown:: - sage: P = plot(sin, legend_label='sin') # optional - sage.symbolic - sage: P.legend() # optional - sage.symbolic + sage: P = plot(sin, legend_label='sin') # needs sage.symbolic + sage: P.legend() # needs sage.symbolic True We can turn it on or off:: - sage: P.legend(False) # optional - sage.symbolic - sage: P.legend() # optional - sage.symbolic + sage: # needs sage.symbolic + sage: P.legend(False) + sage: P.legend() False - sage: P.legend(True) # optional - sage.symbolic - sage: P # show with the legend # optional - sage.symbolic + sage: P.legend(True) + sage: P # show with the legend Graphics object consisting of 1 graphics primitive """ if show is None: @@ -405,30 +406,30 @@ def set_legend_options(self, **kwds): By default, no options are set:: - sage: p = plot(tan, legend_label='tan') # optional - sage.symbolic - sage: p.set_legend_options() # optional - sage.symbolic + sage: p = plot(tan, legend_label='tan') # needs sage.symbolic + sage: p.set_legend_options() # needs sage.symbolic {} We build a legend without a shadow:: - sage: p.set_legend_options(shadow=False) # optional - sage.symbolic - sage: p.set_legend_options()['shadow'] # optional - sage.symbolic + sage: p.set_legend_options(shadow=False) # needs sage.symbolic + sage: p.set_legend_options()['shadow'] # needs sage.symbolic False To set the legend position to the center of the plot, all these methods are roughly equivalent:: - sage: p.set_legend_options(loc='center'); p # optional - sage.symbolic + sage: p.set_legend_options(loc='center'); p # needs sage.symbolic Graphics object consisting of 1 graphics primitive :: - sage: p.set_legend_options(loc=10); p # optional - sage.symbolic + sage: p.set_legend_options(loc=10); p # needs sage.symbolic Graphics object consisting of 1 graphics primitive :: - sage: p.set_legend_options(loc=(0.5,0.5)); p # aligns the bottom of the box to the center # optional - sage.symbolic + sage: p.set_legend_options(loc=(0.5,0.5)); p # aligns the bottom of the box to the center # needs sage.symbolic Graphics object consisting of 1 graphics primitive """ if len(kwds) == 0: @@ -623,16 +624,17 @@ def axes_labels_size(self, s=None): EXAMPLES:: - sage: p = plot(sin(x^2), (x, -3, 3), axes_labels=['$x$','$y$']) # optional - sage.symbolic - sage: p.axes_labels_size() # default value # optional - sage.symbolic + sage: # needs sage.symbolic + sage: p = plot(sin(x^2), (x, -3, 3), axes_labels=['$x$','$y$']) + sage: p.axes_labels_size() # default value 1.6 - sage: p.axes_labels_size(2.5) # optional - sage.symbolic - sage: p.axes_labels_size() # optional - sage.symbolic + sage: p.axes_labels_size(2.5) + sage: p.axes_labels_size() 2.5 Now the axes labels are large w.r.t. the tick marks:: - sage: p # optional - sage.symbolic + sage: p # needs sage.symbolic Graphics object consisting of 1 graphics primitive """ @@ -759,20 +761,20 @@ def axes_labels(self, l=None): :: - sage: p = plot(sin(x), (x, 0, 10)) # optional - sage.symbolic - sage: p.axes_labels(['$x$','$y$']) # optional - sage.symbolic - sage: p.axes_labels() # optional - sage.symbolic + sage: p = plot(sin(x), (x, 0, 10)) # needs sage.symbolic + sage: p.axes_labels(['$x$','$y$']) # needs sage.symbolic + sage: p.axes_labels() # needs sage.symbolic ('$x$', '$y$') Now when you plot p, you see x and y axes labels:: - sage: p # optional - sage.symbolic + sage: p # needs sage.symbolic Graphics object consisting of 1 graphics primitive Notice that some may prefer axes labels which are not typeset:: - sage: plot(sin(x), (x, 0, 10), axes_labels=['x','y']) # optional - sage.symbolic + sage: plot(sin(x), (x, 0, 10), axes_labels=['x','y']) # needs sage.symbolic Graphics object consisting of 1 graphics primitive TESTS: @@ -823,25 +825,25 @@ def axes_label_color(self, c=None): :: - sage: p = plot(sin, (-1,1)) # optional - sage.symbolic - sage: p.axes_label_color() # optional - sage.symbolic + sage: p = plot(sin, (-1,1)) # needs sage.symbolic + sage: p.axes_label_color() # needs sage.symbolic (0, 0, 0) We change the labels to be red, and confirm this:: - sage: p.axes_label_color((1,0,0)) # optional - sage.symbolic - sage: p.axes_label_color() # optional - sage.symbolic + sage: p.axes_label_color((1,0,0)) # needs sage.symbolic + sage: p.axes_label_color() # needs sage.symbolic (1.0, 0.0, 0.0) We set labels, since otherwise we won't see anything. :: - sage: p.axes_labels(['$x$ axis', '$y$ axis']) # optional - sage.symbolic + sage: p.axes_labels(['$x$ axis', '$y$ axis']) # needs sage.symbolic In the plot below, notice that the labels are red:: - sage: p # optional - sage.symbolic + sage: p # needs sage.symbolic Graphics object consisting of 1 graphics primitive """ if c is None: @@ -871,18 +873,19 @@ def axes_width(self, w=None): :: - sage: p = plot(cos, (-3,3)) # optional - sage.symbolic - sage: p.axes_width() # optional - sage.symbolic + sage: # needs sage.symbolic + sage: p = plot(cos, (-3,3)) + sage: p.axes_width() 0.8 - sage: p.axes_width(10) # optional - sage.symbolic - sage: p.axes_width() # optional - sage.symbolic + sage: p.axes_width(10) + sage: p.axes_width() 10.0 Finally we plot the result, which is a graph with very fat axes. :: - sage: p + sage: p # needs sage.symbolic Graphics object consisting of 1 graphics primitive """ if w is None: @@ -908,13 +911,14 @@ def tick_label_color(self, c=None): EXAMPLES:: - sage: p = plot(cos, (-3,3)) # optional - sage.symbolic - sage: p.tick_label_color() # optional - sage.symbolic + sage: # needs sage.symbolic + sage: p = plot(cos, (-3,3)) + sage: p.tick_label_color() (0, 0, 0) - sage: p.tick_label_color((1,0,0)) # optional - sage.symbolic - sage: p.tick_label_color() # optional - sage.symbolic + sage: p.tick_label_color((1,0,0)) + sage: p.tick_label_color() (1.0, 0.0, 0.0) - sage: p # optional - sage.symbolic + sage: p Graphics object consisting of 1 graphics primitive """ if c is None: @@ -938,27 +942,27 @@ def _repr_(self): We create a plot and call :meth:`show` on it, which causes it to be displayed as a plot:: - sage: P = plot(cos, (-1,1)) # optional - sage.symbolic - sage: P.show() # optional - sage.symbolic + sage: P = plot(cos, (-1,1)) # needs sage.symbolic + sage: P.show() # needs sage.symbolic Just doing this also displays the plot:: - sage: P # optional - sage.symbolic + sage: P # needs sage.symbolic Graphics object consisting of 1 graphics primitive Using the Python `repr` or `str` commands do not display the plot:: - sage: repr(P) # optional - sage.symbolic + sage: repr(P) # needs sage.symbolic 'Graphics object consisting of 1 graphics primitive' - sage: str(P) # optional - sage.symbolic + sage: str(P) # needs sage.symbolic 'Graphics object consisting of 1 graphics primitive' - sage: print(P) # optional - sage.symbolic + sage: print(P) # needs sage.symbolic Graphics object consisting of 1 graphics primitive TESTS:: - sage: P._repr_() # optional - sage.symbolic + sage: P._repr_() # needs sage.symbolic 'Graphics object consisting of 1 graphics primitive' """ return str(self) @@ -1140,50 +1144,53 @@ def __add__(self, other): EXAMPLES:: - sage: g1 = plot(abs(sqrt(x^3-1)), (x,1,5), frame=True) # optional - sage.symbolic - sage: g2 = plot(-abs(sqrt(x^3-1)), (x,1,5), color='red') # optional - sage.symbolic - sage: g1 + g2 # displays the plot # optional - sage.symbolic + sage: g1 = plot(abs(sqrt(x^3-1)), (x,1,5), frame=True) # needs sage.symbolic + sage: g2 = plot(-abs(sqrt(x^3-1)), (x,1,5), color='red') # needs sage.symbolic + sage: g1 + g2 # displays the plot # needs sage.symbolic Graphics object consisting of 2 graphics primitives TESTS: Extra keywords to show are propagated:: - sage: (g1 + g2)._extra_kwds=={'aspect_ratio': 'automatic', 'frame': True} # optional - sage.symbolic + sage: # needs sage.symbolic + sage: (g1 + g2)._extra_kwds=={'aspect_ratio': 'automatic', 'frame': True} True - sage: g1.set_aspect_ratio(2) # optional - sage.symbolic - sage: (g1+g2).aspect_ratio() # optional - sage.symbolic + sage: g1.set_aspect_ratio(2) + sage: (g1+g2).aspect_ratio() 2.0 - sage: g2.set_aspect_ratio(3) # optional - sage.symbolic - sage: (g1+g2).aspect_ratio() # optional - sage.symbolic + sage: g2.set_aspect_ratio(3) + sage: (g1+g2).aspect_ratio() 3.0 As are legend options, :trac:`12936`:: - sage: p1 = plot(x, x, 0, 1) # optional - sage.symbolic - sage: p2 = p1 # optional - sage.symbolic - sage: p1.set_legend_options(back_color='black') # optional - sage.symbolic - sage: p2.set_legend_options(shadow=False) # optional - sage.symbolic - sage: p3 = p1 + p2 # optional - sage.symbolic - sage: p3._legend_opts # optional - sage.symbolic + sage: # needs sage.symbolic + sage: p1 = plot(x, x, 0, 1) + sage: p2 = p1 + sage: p1.set_legend_options(back_color='black') + sage: p2.set_legend_options(shadow=False) + sage: p3 = p1 + p2 + sage: p3._legend_opts {'back_color': 'black', 'shadow': False} If the same legend option is specified more than once, the latter takes precedence:: - sage: p1 = plot(x, x, 0, 1) # optional - sage.symbolic - sage: p2 = p1 # optional - sage.symbolic - sage: p1.set_legend_options(shadow=True) # optional - sage.symbolic - sage: p2.set_legend_options(shadow=False) # optional - sage.symbolic - sage: p3 = p1 + p2 # optional - sage.symbolic - sage: p3._legend_opts # optional - sage.symbolic + sage: # needs sage.symbolic + sage: p1 = plot(x, x, 0, 1) + sage: p2 = p1 + sage: p1.set_legend_options(shadow=True) + sage: p2.set_legend_options(shadow=False) + sage: p3 = p1 + p2 + sage: p3._legend_opts {'shadow': False} Flipped axes take precedence over non-flipped axes:: - sage: p1 = plot(x, x, 0, 1, flip_x=True, flip_y=True) # optional - sage.symbolic - sage: p2 = plot(x^2, x, 0, 1) # optional - sage.symbolic - sage: [p._extra_kwds[k] for p in [p1 + p2, p2 + p1] # optional - sage.symbolic + sage: p1 = plot(x, x, 0, 1, flip_x=True, flip_y=True) # needs sage.symbolic + sage: p2 = plot(x^2, x, 0, 1) # needs sage.symbolic + sage: [p._extra_kwds[k] for p in [p1 + p2, p2 + p1] # needs sage.symbolic ....: for k in ['flip_x', 'flip_y']] [True, True, True, True] """ @@ -1274,7 +1281,7 @@ def plot3d(self, z=0, **kwds): EXAMPLES:: - sage: sum(plot(z*sin(x), 0, 10).plot3d(z) # long time # optional - sage.symbolic + sage: sum(plot(z*sin(x), 0, 10).plot3d(z) # long time # needs sage.symbolic ....: for z in range(6)) Graphics3d Object """ @@ -1726,112 +1733,112 @@ def show(self, **kwds): You can turn off the drawing of the axes:: - sage: show(plot(sin,-4,4), axes=False) # optional - sage.symbolic + sage: show(plot(sin,-4,4), axes=False) # needs sage.symbolic You can also label the axes. Putting something in dollar signs formats it as a mathematical expression:: - sage: show(plot(sin,-4,4), axes_labels=('$x$','$y$')) # optional - sage.symbolic + sage: show(plot(sin,-4,4), axes_labels=('$x$','$y$')) # needs sage.symbolic You can add a title to a plot:: - sage: show(plot(sin,-4,4), title=r'A plot of $\sin(x)$') # optional - sage.symbolic + sage: show(plot(sin,-4,4), title=r'A plot of $\sin(x)$') # needs sage.symbolic You can also provide the position for the title to the plot. In the plot below the title is placed on the bottom left of the figure.:: - sage: plot(sin, -4, 4, title='Plot sin(x)', title_pos=(0.05,-0.05)) # optional - sage.symbolic + sage: plot(sin, -4, 4, title='Plot sin(x)', title_pos=(0.05,-0.05)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive If you want all the text to be rendered by using an external LaTeX installation then set the ``typeset`` to ``"latex"``. This requires that LaTeX, dvipng and Ghostscript be installed:: - sage: plot(x, typeset='latex') # optional - latex sage.symbolic + sage: plot(x, typeset='latex') # optional - latex, needs sage.symbolic Graphics object consisting of 1 graphics primitive If you want all the text in your plot to use Type 1 fonts, then set the ``typeset`` option to ``"type1"``. This requires that LaTeX, dvipng and Ghostscript be installed:: - sage: plot(x, typeset='type1') # optional - latex sage.symbolic + sage: plot(x, typeset='type1') # optional - latex, needs sage.symbolic Graphics object consisting of 1 graphics primitive You can turn on the drawing of a frame around the plots:: - sage: show(plot(sin,-4,4), frame=True) # optional - sage.symbolic + sage: show(plot(sin,-4,4), frame=True) # needs sage.symbolic You can make the background transparent:: - sage: plot(sin(x), (x, -4, 4), transparent=True) # optional - sage.symbolic + sage: plot(sin(x), (x, -4, 4), transparent=True) # needs sage.symbolic Graphics object consisting of 1 graphics primitive Prior to :trac:`19485`, legends by default had a shadowless gray background. This behavior can be recovered by passing in certain ``legend_options``:: - sage: p = plot(sin(x), legend_label=r'$\sin(x)$') # optional - sage.symbolic - sage: p.show(legend_options={'back_color': (0.9,0.9,0.9), # optional - sage.symbolic + sage: p = plot(sin(x), legend_label=r'$\sin(x)$') # needs sage.symbolic + sage: p.show(legend_options={'back_color': (0.9,0.9,0.9), # needs sage.symbolic ....: 'shadow': False}) We can change the scale of the axes in the graphics before displaying:: - sage: G = plot(exp, 1, 10) # optional - sage.symbolic - sage: G.show(scale='semilogy') # optional - sage.symbolic + sage: G = plot(exp, 1, 10) # needs sage.symbolic + sage: G.show(scale='semilogy') # needs sage.symbolic We can change the base of the logarithm too. The following changes the vertical axis to be on log scale, and with base 2. Note that the ``base`` argument will ignore any changes to the axis which is in linear scale.:: - sage: G.show(scale='semilogy', base=2) # y axis as powers of 2 # long time, optional - sage.symbolic + sage: G.show(scale='semilogy', base=2) # y axis as powers of 2 # long time, needs sage.symbolic :: - sage: G.show(scale='semilogy', base=(3,2)) # base ignored for x-axis # optional - sage.symbolic + sage: G.show(scale='semilogy', base=(3,2)) # base ignored for x-axis # needs sage.symbolic The scale can be also given as a 2-tuple or a 3-tuple.:: - sage: G.show(scale=('loglog', 2.1)) # both x and y axes in base 2.1 # long time, optional - sage.symbolic + sage: G.show(scale=('loglog', 2.1)) # both x and y axes in base 2.1 # long time, needs sage.symbolic :: - sage: G.show(scale=('loglog', 2, 3)) # x in base 2, y in base 3 # long time, optional - sage.symbolic + sage: G.show(scale=('loglog', 2, 3)) # x in base 2, y in base 3 # long time, needs sage.symbolic The base need not be an integer, though it does have to be made a float.:: - sage: G.show(scale='semilogx', base=float(e)) # base is e # optional - sage.symbolic + sage: G.show(scale='semilogx', base=float(e)) # base is e # needs sage.symbolic Logarithmic scale can be used for various kinds of plots. Here are some examples.:: - sage: G = list_plot([10**i for i in range(10)]) # long time, optional - sage.symbolic + sage: G = list_plot([10**i for i in range(10)]) # long time, needs sage.symbolic sage: G.show(scale='semilogy') # long time :: - sage: G = parametric_plot((x, x**2), (x, 1, 10)) # optional - sage.symbolic - sage: G.show(scale='loglog') # optional - sage.symbolic + sage: G = parametric_plot((x, x**2), (x, 1, 10)) # needs sage.symbolic + sage: G.show(scale='loglog') # needs sage.symbolic :: - sage: disk((5,5), 4, (0, 3*pi/2)).show(scale='loglog',base=2) # optional - sage.symbolic + sage: disk((5,5), 4, (0, 3*pi/2)).show(scale='loglog',base=2) # needs sage.symbolic :: - sage: x, y = var('x, y') # optional - sage.symbolic - sage: G = plot_vector_field((2^x,y^2), (x,1,10), (y,1,100)) # optional - sage.symbolic - sage: G.show(scale='semilogx',base=2) # optional - sage.symbolic + sage: x, y = var('x, y') # needs sage.symbolic + sage: G = plot_vector_field((2^x,y^2), (x,1,10), (y,1,100)) # needs sage.symbolic + sage: G.show(scale='semilogx',base=2) # needs sage.symbolic Flip the horizontal or vertical axis. :: - sage: G = plot(x^3, -2, 3) # optional - sage.symbolic - sage: G.show(flip_x=True) # optional - sage.symbolic - sage: G.show(flip_y=True) # optional - sage.symbolic + sage: G = plot(x^3, -2, 3) # needs sage.symbolic + sage: G.show(flip_x=True) # needs sage.symbolic + sage: G.show(flip_y=True) # needs sage.symbolic Add grid lines at the major ticks of the axes. @@ -1846,27 +1853,28 @@ def show(self, **kwds): :: - sage: u,v = var('u v') # optional - sage.symbolic - sage: f = exp(-(u^2+v^2)) # optional - sage.symbolic - sage: p = plot_vector_field(f.gradient(), (u,-2,2), (v,-2,2)) # optional - sage.symbolic - sage: p.show(gridlines="minor") # optional - sage.symbolic + sage: # needs sage.symbolic + sage: u,v = var('u v') + sage: f = exp(-(u^2+v^2)) + sage: p = plot_vector_field(f.gradient(), (u,-2,2), (v,-2,2)) + sage: p.show(gridlines="minor") Add only horizontal or vertical grid lines. :: - sage: p = plot(sin, -10, 20) # optional - sage.symbolic - sage: p.show(gridlines=[None, "automatic"]) # optional - sage.symbolic - sage: p.show(gridlines=["minor", False]) # optional - sage.symbolic + sage: p = plot(sin, -10, 20) # needs sage.symbolic + sage: p.show(gridlines=[None, "automatic"]) # needs sage.symbolic + sage: p.show(gridlines=["minor", False]) # needs sage.symbolic Add grid lines at specific positions (using lists/tuples). :: - sage: x, y = var('x, y') # optional - sage.symbolic - sage: p = implicit_plot((y^2-x^2)*(x-1)*(2*x-3) - 4*(x^2+y^2-2*x)^2, # optional - sage.symbolic + sage: x, y = var('x, y') # needs sage.symbolic + sage: p = implicit_plot((y^2-x^2)*(x-1)*(2*x-3) - 4*(x^2+y^2-2*x)^2, # needs sage.symbolic ....: (x,-2,2), (y,-2,2), plot_points=1000) - sage: p.show(gridlines=[[1,0],[-1,0,1]]) # optional - sage.symbolic + sage: p.show(gridlines=[[1,0],[-1,0,1]]) # needs sage.symbolic Add grid lines at specific positions (using iterators). @@ -1874,18 +1882,18 @@ def show(self, **kwds): sage: def maple_leaf(t): ....: return (100/(100+(t-pi/2)^8))*(2-sin(7*t)-cos(30*t)/2) - sage: p = polar_plot(maple_leaf, -pi/4, 3*pi/2, # long time, optional - sage.symbolic + sage: p = polar_plot(maple_leaf, -pi/4, 3*pi/2, # long time, needs sage.symbolic ....: color="red",plot_points=1000) - sage: p.show(gridlines=([-3,-2.75,..,3], range(-1,5,2))) # long time, optional - sage.symbolic + sage: p.show(gridlines=([-3,-2.75,..,3], range(-1,5,2))) # long time, needs sage.symbolic Add grid lines at specific positions (using functions). :: - sage: y = x^5 + 4*x^4 - 10*x^3 - 40*x^2 + 9*x + 36 # optional - sage.symbolic - sage: p = plot(y, -4.1, 1.1) # optional - sage.symbolic - sage: xlines = lambda a, b: [z for z, m in y.roots()] # optional - sage.symbolic - sage: p.show(gridlines=[xlines, [0]], frame=True, axes=False) # optional - sage.symbolic + sage: y = x^5 + 4*x^4 - 10*x^3 - 40*x^2 + 9*x + 36 # needs sage.symbolic + sage: p = plot(y, -4.1, 1.1) # needs sage.symbolic + sage: xlines = lambda a, b: [z for z, m in y.roots()] # needs sage.symbolic + sage: p.show(gridlines=[xlines, [0]], frame=True, axes=False) # needs sage.symbolic Change the style of all the grid lines. @@ -1900,8 +1908,8 @@ def show(self, **kwds): :: - sage: p = polar_plot(2 + 2*cos(x), 0, 2*pi, color=hue(0.3)) # optional - sage.symbolic - sage: p.show(gridlines=True, # optional - sage.symbolic + sage: p = polar_plot(2 + 2*cos(x), 0, 2*pi, color=hue(0.3)) # needs sage.symbolic + sage: p.show(gridlines=True, # needs sage.symbolic ....: hgridlinesstyle=dict(color="orange", linewidth=1.0), ....: vgridlinesstyle=dict(color="blue", linestyle=":")) @@ -1909,10 +1917,10 @@ def show(self, **kwds): :: - sage: x, y = var('x, y') # optional - sage.symbolic - sage: p = implicit_plot((y^2-x^2)*(x-1)*(2*x-3) - 4*(x^2+y^2-2*x)^2, # optional - sage.symbolic + sage: x, y = var('x, y') # needs sage.symbolic + sage: p = implicit_plot((y^2-x^2)*(x-1)*(2*x-3) - 4*(x^2+y^2-2*x)^2, # needs sage.symbolic ....: (x,-2,2), (y,-2,2), plot_points=1000) - sage: p.show(gridlines=( # optional - sage.symbolic + sage: p.show(gridlines=( # needs sage.symbolic ....: [ ....: (1,{"color":"red","linestyle":":"}), ....: (0,{"color":"blue","linestyle":"--"}) @@ -1929,9 +1937,9 @@ def show(self, **kwds): :: - sage: f = sin(x^2 + y^2)*cos(x)*sin(y) # optional - sage.symbolic - sage: c = contour_plot(f, (x, -4, 4), (y, -4, 4), plot_points=100) # optional - sage.symbolic - sage: c.show(gridlines=True, # optional - sage.symbolic + sage: f = sin(x^2 + y^2)*cos(x)*sin(y) # needs sage.symbolic + sage: c = contour_plot(f, (x, -4, 4), (y, -4, 4), plot_points=100) # needs sage.symbolic + sage: c.show(gridlines=True, # needs sage.symbolic ....: gridlinesstyle={'linestyle': ':', 'linewidth': 1, 'color': 'red'}) Grid lines can be added to matrix plots. @@ -1951,10 +1959,10 @@ def show(self, **kwds): :: - sage: (plot(sin(x), (x, -pi, pi), thickness=2) # optional - sage.symbolic + sage: (plot(sin(x), (x, -pi, pi), thickness=2) # needs sage.symbolic ....: + point((pi, -1), pointsize=15)) Graphics object consisting of 2 graphics primitives - sage: (plot(sin(x), (x, -pi, pi), thickness=2, axes_pad=0) # optional - sage.symbolic + sage: (plot(sin(x), (x, -pi, pi), thickness=2, axes_pad=0) # needs sage.symbolic ....: + point((pi, -1), pointsize=15)) Graphics object consisting of 2 graphics primitives @@ -1967,10 +1975,10 @@ def show(self, **kwds): :: - sage: plot_loglog(x, (1.1*10**-2, 9990)) # optional - sage.symbolic + sage: plot_loglog(x, (1.1*10**-2, 9990)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive - sage: plot_loglog(x, (1.1*10**-2, 9990), axes_pad=0) # optional - sage.symbolic + sage: plot_loglog(x, (1.1*10**-2, 9990), axes_pad=0) # needs sage.symbolic Graphics object consisting of 1 graphics primitive Via matplotlib, Sage allows setting of custom ticks. See above @@ -1978,39 +1986,39 @@ def show(self, **kwds): Here the labels are not so useful:: - sage: plot(sin(pi*x), (x, -8, 8)) # optional - sage.symbolic + sage: plot(sin(pi*x), (x, -8, 8)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive Now put ticks at multiples of 2:: - sage: plot(sin(pi*x), (x, -8, 8), ticks=2) # optional - sage.symbolic + sage: plot(sin(pi*x), (x, -8, 8), ticks=2) # needs sage.symbolic Graphics object consisting of 1 graphics primitive Or just choose where you want the ticks:: - sage: plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7], [-1/2,0,1/2]]) # optional - sage.symbolic + sage: plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7], [-1/2,0,1/2]]) # needs sage.symbolic Graphics object consisting of 1 graphics primitive Or no ticks at all:: - sage: plot(sin(pi*x), (x, -8, 8), ticks=[[], []]) # optional - sage.symbolic + sage: plot(sin(pi*x), (x, -8, 8), ticks=[[], []]) # needs sage.symbolic Graphics object consisting of 1 graphics primitive This can be very helpful in showing certain features of plots. :: - sage: plot(1.5/(1+e^(-x)), (x, -10, 10)) # doesn't quite show value of inflection point # optional - sage.symbolic + sage: plot(1.5/(1+e^(-x)), (x, -10, 10)) # doesn't quite show value of inflection point # needs sage.symbolic Graphics object consisting of 1 graphics primitive :: - sage: plot(1.5/(1+e^(-x)), (x, -10, 10), # It's right at f(x)=0.75! # optional - sage.symbolic + sage: plot(1.5/(1+e^(-x)), (x, -10, 10), # It's right at f(x)=0.75! # needs sage.symbolic ....: ticks=[None, 1.5/4]) Graphics object consisting of 1 graphics primitive But be careful to leave enough room for at least two major ticks, so that the user can tell what the scale is:: - sage: plot(x^2, (x,1,8), ticks=6).show() # optional - sage.symbolic + sage: plot(x^2, (x,1,8), ticks=6).show() # needs sage.symbolic Traceback (most recent call last): ... ValueError: Expand the range of the independent variable to @@ -2019,7 +2027,7 @@ def show(self, **kwds): We can also do custom formatting if you need it. See above for full details:: - sage: plot(2*x + 1, (x,0,5), # not tested (broken with matplotlib 3.6) # optional - sage.symbolic + sage: plot(2*x + 1, (x,0,5), # not tested (broken with matplotlib 3.6), needs sage.symbolic ....: ticks=[[0,1,e,pi,sqrt(20)], 2], ....: tick_formatter="latex") Graphics object consisting of 1 graphics primitive @@ -2029,20 +2037,20 @@ def show(self, **kwds): :: - sage: plot(sin(x), (x,0,2*pi), ticks=pi/3, tick_formatter=pi) # optional - sage.symbolic + sage: plot(sin(x), (x,0,2*pi), ticks=pi/3, tick_formatter=pi) # needs sage.symbolic Graphics object consisting of 1 graphics primitive But keep in mind that you will get exactly the formatting you asked for if you specify both formatters. The first syntax is recommended for best style in that case. :: - sage: plot(arcsin(x), (x,-1,1), ticks=[None, pi/6], # Nice-looking! # optional - sage.symbolic + sage: plot(arcsin(x), (x,-1,1), ticks=[None, pi/6], # Nice-looking! # needs sage.symbolic ....: tick_formatter=["latex", pi]) Graphics object consisting of 1 graphics primitive :: - sage: plot(arcsin(x), (x,-1,1), ticks=[None, pi/6], # Not so nice-looking # optional - sage.symbolic + sage: plot(arcsin(x), (x,-1,1), ticks=[None, pi/6], # Not so nice-looking # needs sage.symbolic ....: tick_formatter=[None, pi]) Graphics object consisting of 1 graphics primitive @@ -2050,21 +2058,21 @@ def show(self, **kwds): ``tick_formatter`` with the list of labels, and simultaneously providing the keyword ``ticks`` with the positions of the labels. :: - sage: plot(x, (x,0,3), ticks=[[1,2.5], [0.5,1,2]], # optional - sage.symbolic + sage: plot(x, (x,0,3), ticks=[[1,2.5], [0.5,1,2]], # needs sage.symbolic ....: tick_formatter=[["$x_1$","$x_2$"], ["$y_1$","$y_2$","$y_3$"]]) Graphics object consisting of 1 graphics primitive The following sets the custom tick labels only along the horizontal axis. :: - sage: plot(x**2, (x,0,2), ticks=[[1,2], None], # optional - sage.symbolic + sage: plot(x**2, (x,0,2), ticks=[[1,2], None], # needs sage.symbolic ....: tick_formatter=[["$x_1$","$x_2$"], None]) Graphics object consisting of 1 graphics primitive If the number of tick labels do not match the number of positions of tick labels, then it results in an error.:: - sage: plot(x**2, (x,0,2), ticks=[[2], None], # optional - sage.symbolic + sage: plot(x**2, (x,0,2), ticks=[[2], None], # needs sage.symbolic ....: tick_formatter=[["$x_1$","$x_2$"], None]).show() Traceback (most recent call last): ... @@ -2103,7 +2111,7 @@ def show(self, **kwds): When using ``title_pos``, it must be ensured that a list or a tuple of length two is used. Otherwise, a warning is raised:: - sage: plot(x, -4, 4, title='Plot x', title_pos=0.05) # optional - sage.symbolic + sage: plot(x, -4, 4, title='Plot x', title_pos=0.05) # needs sage.symbolic doctest:...: ...RichReprWarning: Exception in _rich_repr_ while displaying object: 'title_pos' must be a list or tuple of two real numbers. Graphics object consisting of 1 graphics primitive @@ -2132,25 +2140,26 @@ def show(self, **kwds): The following tests ensure we give a good error message for negative figsizes:: - sage: P = plot(x^2,(x,0,1)) # optional - sage.symbolic - sage: P.show(figsize=[-1,1]) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: P = plot(x^2,(x,0,1)) + sage: P.show(figsize=[-1,1]) Traceback (most recent call last): ... ValueError: figsize should be positive numbers, not -1.0 and 1.0 - sage: P.show(figsize=-1) # optional - sage.symbolic + sage: P.show(figsize=-1) Traceback (most recent call last): ... ValueError: figsize should be positive, not -1.0 - sage: P.show(figsize=x^2) # optional - sage.symbolic + sage: P.show(figsize=x^2) Traceback (most recent call last): ... TypeError: figsize should be a positive number, not x^2 - sage: P.show(figsize=[2,3,4]) # optional - sage.symbolic + sage: P.show(figsize=[2,3,4]) Traceback (most recent call last): ... ValueError: figsize should be a positive number or a list of two positive numbers, not [2, 3, 4] - sage: P.show(figsize=[sqrt(2),sqrt(3)]) # optional - sage.symbolic + sage: P.show(figsize=[sqrt(2),sqrt(3)]) """ from sage.repl.rich_output import get_display_manager dm = get_display_manager() @@ -2360,11 +2369,12 @@ def _matplotlib_tick_formatter(self, subplot, base=(10, 10), EXAMPLES:: + sage: # needs sage.symbolic sage: from matplotlib.figure import Figure - sage: p = plot(x); d = p.get_minmax_data() # optional - sage.symbolic - sage: subplot = Figure().add_subplot(111) # optional - sage.symbolic - sage: p._objects[0]._render_on_subplot(subplot) # optional - sage.symbolic - sage: p._matplotlib_tick_formatter(subplot, **d) # optional - sage.symbolic + sage: p = plot(x); d = p.get_minmax_data() + sage: subplot = Figure().add_subplot(111) + sage: p._objects[0]._render_on_subplot(subplot) + sage: p._matplotlib_tick_formatter(subplot, **d) (, , , @@ -2673,41 +2683,43 @@ def matplotlib(self, filename=None, :: - sage: p = plot(sin(x), (x, -2*pi, 2*pi)) # optional - sage.symbolic - sage: figure = p.matplotlib() # optional - sage.symbolic - sage: axes = figure.axes[0] # optional - sage.symbolic + sage: p = plot(sin(x), (x, -2*pi, 2*pi)) # needs sage.symbolic + sage: figure = p.matplotlib() # needs sage.symbolic + sage: axes = figure.axes[0] # needs sage.symbolic TESTS: We verify that :trac:`10291` is fixed:: - sage: p = plot(sin(x), (x, -2*pi, 2*pi)) # optional - sage.symbolic - sage: figure = p.matplotlib() # optional - sage.symbolic - sage: axes_range = p.get_axes_range() # optional - sage.symbolic - sage: figure = p.matplotlib() # optional - sage.symbolic - sage: axes_range2 = p.get_axes_range() # optional - sage.symbolic - sage: axes_range == axes_range2 # optional - sage.symbolic + sage: # needs sage.symbolic + sage: p = plot(sin(x), (x, -2*pi, 2*pi)) + sage: figure = p.matplotlib() + sage: axes_range = p.get_axes_range() + sage: figure = p.matplotlib() + sage: axes_range2 = p.get_axes_range() + sage: axes_range == axes_range2 True We verify that legend options are properly handled (:trac:`12960`). First, we test with no options, and next with an incomplete set of options.:: - sage: p = plot(x, legend_label='aha') # optional - sage.symbolic - sage: p.legend(True) # optional - sage.symbolic - sage: pm = p.matplotlib() # optional - sage.symbolic - sage: pm = p.matplotlib(legend_options={'font_size': 'small'}) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: p = plot(x, legend_label='aha') + sage: p.legend(True) + sage: pm = p.matplotlib() + sage: pm = p.matplotlib(legend_options={'font_size': 'small'}) The title should not overlap with the axes labels nor the frame in the following plot (see :trac:`10512`):: - sage: plot(sin(x^2), (x, -3, 3), title='Plot of sin(x^2)', # optional - sage.symbolic + sage: plot(sin(x^2), (x, -3, 3), title='Plot of sin(x^2)', # needs sage.symbolic ....: axes_labels=['x','y'], frame=True) Graphics object consisting of 1 graphics primitive ``typeset`` must not be set to an arbitrary string:: - sage: plot(x, typeset='garbage') # optional - sage.symbolic + sage: plot(x, typeset='garbage') # needs sage.symbolic doctest:...: ...RichReprWarning: Exception in _rich_repr_ while displaying object: typeset must be set to one of 'default', 'latex', or 'type1'; got 'garbage'. @@ -2717,17 +2729,19 @@ def matplotlib(self, filename=None, By default, Sage 5.10 changes float objects to the `RealLiteral` type. The patch changes them to float before creating `matplotlib` objects.:: - sage: f = lambda x, y: abs(cos((x + I * y) ** 4)) - 1 # long time # optional - sage.symbolic - sage: g = implicit_plot(f, (-4, 4), (-3, 3), linewidth=0.6) # long time # optional - sage.symbolic - sage: gm = g.matplotlib() # long time # without the patch, this goes BOOM -- er, TypeError # optional - sage.symbolic + sage: # long time, needs sage.symbolic + sage: f = lambda x, y: abs(cos((x + I * y) ** 4)) - 1 # long time, needs sage.symbolic + sage: g = implicit_plot(f, (-4, 4), (-3, 3), linewidth=0.6) # long time, needs sage.symbolic + sage: gm = g.matplotlib() # long time, needs sage.symbolic If the axes are flipped, the limits of the axes get swapped:: - sage: p = plot(2*x, 1, 2) # optional - sage.symbolic - sage: sub, = p.matplotlib(flip_y=True, flip_x=True).axes # optional - sage.symbolic - sage: xmin, xmax = sub.get_xlim() # optional - sage.symbolic - sage: ymin, ymax = sub.get_ylim() # optional - sage.symbolic - sage: xmin > xmax, ymin > ymax # optional - sage.symbolic + sage: # needs sage.symbolic + sage: p = plot(2*x, 1, 2) + sage: sub, = p.matplotlib(flip_y=True, flip_x=True).axes + sage: xmin, xmax = sub.get_xlim() + sage: ymin, ymax = sub.get_ylim() + sage: xmin > xmax, ymin > ymax (True, True) """ if not isinstance(ticks, (list, tuple)): @@ -3281,11 +3295,11 @@ def save(self, filename, **kwds): You can also pass extra options to the plot command instead of this method, e.g. :: - sage: plot(x^2 - 5, (x, 0, 5), ymin=0).save(tmp_filename(ext='.png')) # optional - sage.symbolic + sage: plot(x^2 - 5, (x, 0, 5), ymin=0).save(tmp_filename(ext='.png')) # needs sage.symbolic will save the same plot as the one shown by this command:: - sage: plot(x^2 - 5, (x, 0, 5), ymin=0) # optional - sage.symbolic + sage: plot(x^2 - 5, (x, 0, 5), ymin=0) # needs sage.symbolic Graphics object consisting of 1 graphics primitive (This test verifies that :trac:`8632` is fixed.) @@ -3294,26 +3308,27 @@ def save(self, filename, **kwds): Legend labels should save correctly:: - sage: P = plot(x,(x,0,1),legend_label='$xyz$') # optional - sage.symbolic - sage: P.set_legend_options(back_color=(1,0,0)) # optional - sage.symbolic - sage: P.set_legend_options(loc=7) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: P = plot(x,(x,0,1),legend_label='$xyz$') + sage: P.set_legend_options(back_color=(1,0,0)) + sage: P.set_legend_options(loc=7) sage: import tempfile - sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # optional - sage.symbolic + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: ....: P.save(f.name) This plot should save with the frame shown, showing :trac:`7524` is fixed (same issue as :trac:`7981` and :trac:`8632`):: - sage: var('x,y') # optional - sage.symbolic + sage: var('x,y') # needs sage.symbolic (x, y) - sage: a = plot_vector_field((x,-y),(x,-1,1),(y,-1,1)) # optional - sage.symbolic + sage: a = plot_vector_field((x,-y),(x,-1,1),(y,-1,1)) # needs sage.symbolic sage: import tempfile - sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # optional - sage.symbolic + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # needs sage.symbolic ....: a.save(f.name) The following plot should show the axes; fixes :trac:`14782` :: - sage: plot(x^2, (x, 1, 2), ticks=[[], []]) + sage: plot(x^2, (x, 1, 2), ticks=[[], []]) # needs sage.symbolic Graphics object consisting of 1 graphics primitive """ @@ -3428,7 +3443,7 @@ def description(self): EXAMPLES:: - sage: print(polytopes.hypercube(2).plot().description()) # optional - sage.geometry.polyhedron + sage: print(polytopes.hypercube(2).plot().description()) # needs sage.geometry.polyhedron Polygon defined by 4 points: [(-1.0, -1.0), (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0)] Line defined by 2 points: [(-1.0, 1.0), (-1.0, -1.0)] Line defined by 2 points: [(1.0, -1.0), (-1.0, -1.0)] @@ -3473,11 +3488,12 @@ def inset(self, graphics, pos=None, fontsize=None): EXAMPLES:: - sage: f(x) = x^2*sin(1/x) # optional - sage.symbolic - sage: g1 = plot(f(x), (x, -2, 2), axes_labels=['$x$', '$y$']) # optional - sage.symbolic - sage: g2 = plot(f(x), (x, -0.3, 0.3), axes_labels=['$x$', '$y$'], # optional - sage.symbolic + sage: # needs sage.symbolic + sage: f(x) = x^2*sin(1/x) + sage: g1 = plot(f(x), (x, -2, 2), axes_labels=['$x$', '$y$']) + sage: g2 = plot(f(x), (x, -0.3, 0.3), axes_labels=['$x$', '$y$'], ....: frame=True) - sage: g1.inset(g2) # optional - sage.symbolic + sage: g1.inset(g2) Multigraphics with 2 elements .. PLOT:: @@ -3490,7 +3506,7 @@ def inset(self, graphics, pos=None, fontsize=None): Using non-default values for the position/size and the font size:: - sage: g1.inset(g2, pos=(0.15, 0.7, 0.25, 0.25), fontsize=8) # optional - sage.symbolic + sage: g1.inset(g2, pos=(0.15, 0.7, 0.25, 0.25), fontsize=8) # needs sage.symbolic Multigraphics with 2 elements .. PLOT:: @@ -3503,10 +3519,10 @@ def inset(self, graphics, pos=None, fontsize=None): We can add another inset by invoking ``inset`` on the last output:: - sage: g1g2 = _ # optional - sage.symbolic - sage: g3 = plot(f(x), (x, -0.05, 0.05), axes_labels=['$x$', '$y$'], # optional - sage.symbolic + sage: g1g2 = _ # needs sage.symbolic + sage: g3 = plot(f(x), (x, -0.05, 0.05), axes_labels=['$x$', '$y$'], # needs sage.symbolic ....: frame=True) - sage: g1g2.inset(g3, pos=(0.65, 0.12, 0.25, 0.25)) # optional - sage.symbolic + sage: g1g2.inset(g3, pos=(0.65, 0.12, 0.25, 0.25)) # needs sage.symbolic Multigraphics with 3 elements .. PLOT:: diff --git a/src/sage/plot/line.py b/src/sage/plot/line.py index bff28b3d34d..58d5fd579e0 100644 --- a/src/sage/plot/line.py +++ b/src/sage/plot/line.py @@ -131,9 +131,9 @@ def plot3d(self, z=0, **kwds): EXAMPLES:: - sage: E = EllipticCurve('37a').plot(thickness=5).plot3d() # optional - sage.schemes - sage: F = EllipticCurve('37a').plot(thickness=5).plot3d(z=2) # optional - sage.schemes - sage: E + F # long time (5s on sage.math, 2012) # optional - sage.schemes + sage: E = EllipticCurve('37a').plot(thickness=5).plot3d() # needs sage.schemes + sage: F = EllipticCurve('37a').plot(thickness=5).plot3d(z=2) # needs sage.schemes + sage: E + F # long time (5s on sage.math, 2012), needs sage.schemes Graphics3d Object .. PLOT:: @@ -391,14 +391,14 @@ def line2d(points, **options): sage: line([]) #returns an empty plot Graphics object consisting of 0 graphics primitives - sage: import numpy; line(numpy.array([])) # optional - numpy + sage: import numpy; line(numpy.array([])) # needs numpy Graphics object consisting of 0 graphics primitives sage: line([(1,1)]) Graphics object consisting of 1 graphics primitive A line with numpy arrays:: - sage: line(numpy.array([[1,2], [3,4]])) # optional - numpy + sage: line(numpy.array([[1,2], [3,4]])) # needs numpy Graphics object consisting of 1 graphics primitive A line with a legend:: @@ -574,10 +574,11 @@ def line2d(points, **options): A purple plot of the Hasse-Weil `L`-function `L(E, 1 + it)`, `-1 < t < 10`:: - sage: E = EllipticCurve('37a') # optional - sage.schemes - sage: vals = E.lseries().values_along_line(1-I, 1+10*I, 100) # critical line # optional - sage.schemes - sage: L = [(z[1].real(), z[1].imag()) for z in vals] # optional - sage.schemes - sage: line(L, rgbcolor=(3/4,1/2,5/8)) # optional - sage.schemes + sage: # needs sage.schemes + sage: E = EllipticCurve('37a') + sage: vals = E.lseries().values_along_line(1-I, 1+10*I, 100) # critical line + sage: L = [(z[1].real(), z[1].imag()) for z in vals] + sage: line(L, rgbcolor=(3/4,1/2,5/8)) Graphics object consisting of 1 graphics primitive .. PLOT :: diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index e42400c49f0..a35fda0da27 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -187,7 +187,7 @@ You can even have custom tick labels along with custom positioning. :: - sage: plot(x^2, (x,0,3), ticks=[[1,2.5],pi/2], tick_formatter=[["$x_1$","$x_2$"],pi]) # long time + sage: plot(x^2, (x,0,3), ticks=[[1,2.5],pi/2], tick_formatter=[["$x_1$","$x_2$"],pi]) # long time Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -340,7 +340,7 @@ Many concentric circles shrinking toward the origin:: - sage: show(sum(circle((i,0), i, hue=sin(i/10)) for i in [10,9.9,..,0])) # long time + sage: show(sum(circle((i,0), i, hue=sin(i/10)) for i in [10,9.9,..,0])) # long time .. PLOT:: @@ -420,7 +420,7 @@ def y(x): return x*sin(x**2) sage: g1 = plot(sin(x), 0, 2*pi) sage: g2 = plot(cos(x), 0, 2*pi, linestyle="--") - sage: (g1+g2).show(ticks=pi/6, tick_formatter=pi) # long time # show their sum, nicely formatted + sage: (g1+g2).show(ticks=pi/6, tick_formatter=pi) # long time # show their sum, nicely formatted .. PLOT:: @@ -433,7 +433,8 @@ def y(x): return x*sin(x**2) sage: f(x) = (x-3)*(x-5)*(x-7)+40 sage: P = line([(2,0),(2,f(2))], color='black') sage: P += line([(8,0),(8,f(8))], color='black') - sage: P += polygon([(2,0),(2,f(2))] + [(x, f(x)) for x in [2,2.1,..,8]] + [(8,0),(2,0)], rgbcolor=(0.8,0.8,0.8),aspect_ratio='automatic') + sage: P += polygon([(2,0),(2,f(2))] + [(x, f(x)) for x in [2,2.1,..,8]] + [(8,0),(2,0)], + ....: rgbcolor=(0.8,0.8,0.8), aspect_ratio='automatic') sage: P += text("$\\int_{a}^b f(x) dx$", (5, 20), fontsize=16, color='black') sage: P += plot(f, (1, 8.5), thickness=3) sage: P # show the result @@ -516,7 +517,7 @@ def f(x): return (x-3)*(x-5)*(x-7)+40 Verify that a clean sage startup does *not* import matplotlib:: - sage: os.system("sage -c \"if 'matplotlib' in sys.modules: sys.exit(1)\"") # long time + sage: os.system("sage -c \"if 'matplotlib' in sys.modules: sys.exit(1)\"") # long time 0 Verify that :trac:`10980` is fixed:: @@ -682,18 +683,20 @@ def SelectiveFormatter(formatter, skip_values): :: + sage: # needs numpy sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.pyplot as plt - sage: import numpy # optional - numpy + sage: import numpy sage: fig = plt.figure() sage: ax = fig.add_subplot(111) - sage: t = numpy.arange(0.0, 2.0, 0.01) # optional - numpy - sage: s = numpy.sin(2*numpy.pi*t) # optional - numpy - sage: p = ax.plot(t, s) # optional - numpy - sage: formatter=SelectiveFormatter(ax.xaxis.get_major_formatter(), skip_values=[0,1]) # optional - numpy - sage: ax.xaxis.set_major_formatter(formatter) # optional - numpy + sage: t = numpy.arange(0.0, 2.0, 0.01) + sage: s = numpy.sin(2*numpy.pi*t) + sage: p = ax.plot(t, s) + sage: formatter = SelectiveFormatter(ax.xaxis.get_major_formatter(), + ....: skip_values=[0,1]) + sage: ax.xaxis.set_major_formatter(formatter) sage: import tempfile - sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # optional - numpy + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: ....: fig.savefig(f.name) """ @@ -716,18 +719,20 @@ def __init__(self, formatter, skip_values): EXAMPLES:: + sage: # needs numpy sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.pyplot as plt - sage: import numpy # optional - numpy + sage: import numpy sage: fig = plt.figure() sage: ax = fig.add_subplot(111) - sage: t = numpy.arange(0.0, 2.0, 0.01) # optional - numpy - sage: s = numpy.sin(2*numpy.pi*t) # optional - numpy - sage: line = ax.plot(t, s) # optional - numpy - sage: formatter = SelectiveFormatter(ax.xaxis.get_major_formatter(), skip_values=[0,1]) # optional - numpy - sage: ax.xaxis.set_major_formatter(formatter) # optional - numpy + sage: t = numpy.arange(0.0, 2.0, 0.01) + sage: s = numpy.sin(2*numpy.pi*t) + sage: line = ax.plot(t, s) + sage: formatter = SelectiveFormatter(ax.xaxis.get_major_formatter(), + ....: skip_values=[0,1]) + sage: ax.xaxis.set_major_formatter(formatter) sage: from tempfile import NamedTemporaryFile - sage: with NamedTemporaryFile(suffix=".png") as f: # optional - numpy + sage: with NamedTemporaryFile(suffix=".png") as f: ....: fig.savefig(f.name) """ self.formatter=formatter @@ -741,7 +746,8 @@ def set_locs(self, locs): sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.ticker - sage: formatter=SelectiveFormatter(matplotlib.ticker.Formatter(),skip_values=[0,200]) + sage: formatter = SelectiveFormatter(matplotlib.ticker.Formatter(), + ....: skip_values=[0,200]) sage: formatter.set_locs([i*100 for i in range(10)]) """ self.formatter.set_locs([l for l in locs if l not in self.skip_values]) @@ -754,7 +760,8 @@ def __call__(self, x, *args, **kwds): sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.ticker - sage: formatter=SelectiveFormatter(matplotlib.ticker.FixedFormatter(['a','b']),skip_values=[0,2]) + sage: formatter = SelectiveFormatter(matplotlib.ticker.FixedFormatter(['a','b']), + ....: skip_values=[0,2]) sage: [formatter(i,1) for i in range(10)] ['', 'b', '', 'b', 'b', 'b', 'b', 'b', 'b', 'b'] """ @@ -2553,7 +2560,7 @@ def parametric_plot(funcs, *args, **kwargs): :: - sage: parametric_plot( (sin(t), sin(2*t)), (t, 0, 2*pi), color=hue(0.6) ) + sage: parametric_plot((sin(t), sin(2*t)), (t, 0, 2*pi), color=hue(0.6)) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -2609,27 +2616,27 @@ def parametric_plot(funcs, *args, **kwargs): :: - sage: y=var('y') - sage: parametric_plot( (5*cos(x), x*y, cos(x*y)), (x, -4,4), (y,-4,4)) # long time` + sage: y = var('y') + sage: parametric_plot((5*cos(x), x*y, cos(x*y)), (x, -4, 4), (y, -4, 4)) # long time Graphics3d Object .. PLOT:: #AttributeError: 'sage.plot.plot3d.parametric_surface.ParametricSurf' object has no attribute 'plot' #y = var('y') - #g = parametric_plot( (5*cos(x), x*y, cos(x*y)), (x, -4,4), (y,-4,4)) # long time` + #g = parametric_plot( (5*cos(x), x*y, cos(x*y)), (x, -4,4), (y,-4,4)) # long time #sphinx_plot(g) :: - sage: t=var('t') - sage: parametric_plot( vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green') # long time + sage: t = var('t') + sage: parametric_plot(vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green') # long time Graphics object consisting of 1 graphics primitive .. PLOT:: t = var('t') - g = parametric_plot( vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green') # long time + g = parametric_plot( vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green') # long time sphinx_plot(g) :: @@ -2695,7 +2702,7 @@ def parametric_plot(funcs, *args, **kwargs): One test for :trac:`7165`:: sage: m = SR.var('m') - sage: parametric_plot([real(exp(i*m)),imaginary(exp(i*m))], (m,0,7)) + sage: parametric_plot([real(exp(i*m)), imaginary(exp(i*m))], (m, 0, 7)) Graphics object consisting of 1 graphics primitive """ num_ranges = 0 @@ -2897,8 +2904,8 @@ def list_plot(data, plotjoined=False, **kwargs): You can provide a numpy array.:: - sage: import numpy # optional - numpy - sage: list_plot(numpy.arange(10)) # optional - numpy + sage: import numpy # needs numpy + sage: list_plot(numpy.arange(10)) # needs numpy Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -2909,7 +2916,7 @@ def list_plot(data, plotjoined=False, **kwargs): :: - sage: list_plot(numpy.array([[1,2], [2,3], [3,4]])) # optional - numpy + sage: list_plot(numpy.array([[1,2], [2,3], [3,4]])) # needs numpy Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -3136,7 +3143,7 @@ def plot_loglog(funcs, *args, **kwds): EXAMPLES:: - sage: plot_loglog(exp, (1,10)) # plot in loglog scale with base 10 + sage: plot_loglog(exp, (1,10)) # plot in loglog scale with base 10 Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -3146,7 +3153,7 @@ def plot_loglog(funcs, *args, **kwds): :: - sage: plot_loglog(exp, (1,10), base=2.1) # long time # with base 2.1 on both axes + sage: plot_loglog(exp, (1,10), base=2.1) # long time # with base 2.1 on both axes Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -3184,7 +3191,7 @@ def plot_semilogx(funcs, *args, **kwds): EXAMPLES:: - sage: plot_semilogx(exp, (1,10)) # long time # plot in semilogx scale, base 10 + sage: plot_semilogx(exp, (1,10)) # long time # plot in semilogx scale, base 10 Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -3194,7 +3201,7 @@ def plot_semilogx(funcs, *args, **kwds): :: - sage: plot_semilogx(exp, (1,10), base=2) # with base 2 + sage: plot_semilogx(exp, (1,10), base=2) # with base 2 Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -3204,7 +3211,7 @@ def plot_semilogx(funcs, *args, **kwds): :: - sage: s = var('s') # Samples points logarithmically so graph is smooth + sage: s = var('s') # Samples points logarithmically so graph is smooth sage: f = 4000000/(4000000 + 4000*s*i - s*s) sage: plot_semilogx(20*log(abs(f), 10), (s, 1, 1e6)) Graphics object consisting of 1 graphics primitive @@ -3275,26 +3282,27 @@ def list_plot_loglog(data, plotjoined=False, **kwds): EXAMPLES:: sage: yl = [5**k for k in range(10)]; xl = [2**k for k in range(10)] - sage: list_plot_loglog(list(zip(xl, yl))) # long time # plot in loglog scale with base 10 + sage: list_plot_loglog(list(zip(xl, yl))) # long time # use loglog scale with base 10 Graphics object consisting of 1 graphics primitive .. PLOT:: yl = [5**k for k in range(10)] xl = [2**k for k in range(10)] - g = list_plot_loglog(list(zip(xl, yl))) # long time # plot in loglog scale with base 10 + g = list_plot_loglog(list(zip(xl, yl))) # long time # plot in loglog scale with base 10 sphinx_plot(g) :: - sage: list_plot_loglog(list(zip(xl, yl)), base=2.1) # long time # with base 2.1 on both axes + sage: list_plot_loglog(list(zip(xl, yl)), # long time # with base 2.1 on both axes + ....: base=2.1) Graphics object consisting of 1 graphics primitive .. PLOT:: yl = [5**k for k in range(10)] xl = [2**k for k in range(10)] - g = list_plot_loglog(list(zip(xl, yl)), base=2.1) # long time # with base 2.1 on both axes + g = list_plot_loglog(list(zip(xl, yl)), base=2.1) # long time # with base 2.1 on both axes sphinx_plot(g) :: @@ -3357,7 +3365,7 @@ def list_plot_semilogx(data, plotjoined=False, **kwds): :: sage: yl = [2**k for k in range(12)] - sage: list_plot_semilogx(yl) # plot empty due to (0,1) + sage: list_plot_semilogx(yl) # plot empty due to (0,1) Graphics object consisting of 1 graphics primitive We remove `(0,1)` to fix this.:: @@ -3367,12 +3375,12 @@ def list_plot_semilogx(data, plotjoined=False, **kwds): :: - sage: list_plot_semilogx([(1,2),(3,4),(3,-1),(25,3)], base=2) # with base 2 + sage: list_plot_semilogx([(1,2),(3,4),(3,-1),(25,3)], base=2) # with base 2 Graphics object consisting of 1 graphics primitive .. PLOT:: - g = list_plot_semilogx([(1,2),(3,4),(3,-1),(25,3)], base=2) # with base 2 + g = list_plot_semilogx([(1,2),(3,4),(3,-1),(25,3)], base=2) # with base 2 sphinx_plot(g) """ @@ -3394,13 +3402,13 @@ def list_plot_semilogy(data, plotjoined=False, **kwds): EXAMPLES:: sage: yl = [2**k for k in range(12)] - sage: list_plot_semilogy(yl) # plot in semilogy scale, base 10 + sage: list_plot_semilogy(yl) # plot in semilogy scale, base 10 Graphics object consisting of 1 graphics primitive .. PLOT:: yl = [2**k for k in range(12)] - g = list_plot_semilogy(yl) # plot in semilogy scale, base 10 + g = list_plot_semilogy(yl) # plot in semilogy scale, base 10 sphinx_plot(g) .. warning:: @@ -3413,7 +3421,7 @@ def list_plot_semilogy(data, plotjoined=False, **kwds): :: sage: xl = [2**k for k in range(12)]; yl = range(len(xl)) - sage: list_plot_semilogy(list(zip(xl,yl))) # plot empty due to (1,0) + sage: list_plot_semilogy(list(zip(xl, yl))) # plot empty due to (1,0) doctest:warning ... Graphics object consisting of 1 graphics primitive @@ -3425,12 +3433,12 @@ def list_plot_semilogy(data, plotjoined=False, **kwds): :: - sage: list_plot_semilogy([2, 4, 6, 8, 16, 31], base=2) # with base 2 + sage: list_plot_semilogy([2, 4, 6, 8, 16, 31], base=2) # with base 2 Graphics object consisting of 1 graphics primitive .. PLOT:: - g = list_plot_semilogy([2, 4, 6, 8, 16, 31], base=2) # with base 2 + g = list_plot_semilogy([2, 4, 6, 8, 16, 31], base=2) # with base 2 sphinx_plot(g) """ @@ -3467,7 +3475,7 @@ def reshape(v, n, m): EXAMPLES:: - sage: L = [plot(sin(k*x),(x,-pi,pi)) for k in range(10)] + sage: L = [plot(sin(k*x), (x,-pi,pi)) for k in range(10)] sage: graphics_array(L,3,4) # long time (up to 4s on sage.math, 2012) Graphics Array of size 3 x 4 @@ -3537,17 +3545,18 @@ def graphics_array(array, nrows=None, ncols=None): Make some plots of `\sin` functions:: + sage: # long time sage: f(x) = sin(x) sage: g(x) = sin(2*x) sage: h(x) = sin(4*x) - sage: p1 = plot(f, (-2*pi,2*pi), color=hue(0.5)) # long time - sage: p2 = plot(g, (-2*pi,2*pi), color=hue(0.9)) # long time - sage: p3 = parametric_plot((f,g), (0,2*pi), color=hue(0.6)) # long time - sage: p4 = parametric_plot((f,h), (0,2*pi), color=hue(1.0)) # long time + sage: p1 = plot(f, (-2*pi,2*pi), color=hue(0.5)) + sage: p2 = plot(g, (-2*pi,2*pi), color=hue(0.9)) + sage: p3 = parametric_plot((f,g), (0,2*pi), color=hue(0.6)) + sage: p4 = parametric_plot((f,h), (0,2*pi), color=hue(1.0)) Now make a graphics array out of the plots:: - sage: graphics_array(((p1,p2), (p3,p4))) # long time + sage: graphics_array(((p1,p2), (p3,p4))) # long time Graphics Array of size 2 x 2 .. PLOT:: @@ -3555,26 +3564,25 @@ def graphics_array(array, nrows=None, ncols=None): def f(x): return sin(x) def g(x): return sin(2*x) def h(x): return sin(4*x) - p1 = plot(f, (-2*pi,2*pi), color=hue(0.5)) # long time - p2 = plot(g, (-2*pi,2*pi), color=hue(0.9)) # long time - p3 = parametric_plot((f,g), (0,2*pi), color=hue(0.6)) # long time - p4 = parametric_plot((f,h), (0,2*pi), color=hue(1.0)) # long time - g = graphics_array(((p1, p2), (p3, p4))) # long time + p1 = plot(f, (-2*pi,2*pi), color=hue(0.5)) + p2 = plot(g, (-2*pi,2*pi), color=hue(0.9)) + p3 = parametric_plot((f,g), (0,2*pi), color=hue(0.6)) + p4 = parametric_plot((f,h), (0,2*pi), color=hue(1.0)) + g = graphics_array(((p1, p2), (p3, p4))) sphinx_plot(g) One can also name the array, and then use :meth:`~sage.plot.multigraphics.MultiGraphics.show` or :meth:`~sage.plot.multigraphics.MultiGraphics.save`:: - sage: ga = graphics_array(((p1,p2), (p3,p4))) # long time + sage: ga = graphics_array(((p1,p2), (p3,p4))) # long time sage: ga.show() # long time; same output as above Here we give only one row:: - sage: p1 = plot(sin,(-4,4)) - sage: p2 = plot(cos,(-4,4)) - sage: ga = graphics_array([p1, p2]) - sage: ga + sage: p1 = plot(sin, (-4,4)) + sage: p2 = plot(cos, (-4,4)) + sage: ga = graphics_array([p1, p2]); ga Graphics Array of size 1 x 2 sage: ga.show() @@ -3831,7 +3839,12 @@ def adaptive_refinement(f, p1, p2, adaptive_tolerance=0.01, sage: adaptive_refinement(sin, (0,0), (pi,0), adaptive_tolerance=0.01, adaptive_recursion=0) [] sage: adaptive_refinement(sin, (0,0), (pi,0), adaptive_tolerance=0.01) - [(0.125*pi, 0.3826834323650898), (0.1875*pi, 0.5555702330196022), (0.25*pi, 0.7071067811865475), (0.3125*pi, 0.8314696123025452), (0.375*pi, 0.9238795325112867), (0.4375*pi, 0.9807852804032304), (0.5*pi, 1.0), (0.5625*pi, 0.9807852804032304), (0.625*pi, 0.9238795325112867), (0.6875*pi, 0.8314696123025455), (0.75*pi, 0.7071067811865476), (0.8125*pi, 0.5555702330196022), (0.875*pi, 0.3826834323650899)] + [(0.125*pi, 0.3826834323650898), (0.1875*pi, 0.5555702330196022), + (0.25*pi, 0.7071067811865475), (0.3125*pi, 0.8314696123025452), + (0.375*pi, 0.9238795325112867), (0.4375*pi, 0.9807852804032304), + (0.5*pi, 1.0), (0.5625*pi, 0.9807852804032304), (0.625*pi, 0.9238795325112867), + (0.6875*pi, 0.8314696123025455), (0.75*pi, 0.7071067811865476), + (0.8125*pi, 0.5555702330196022), (0.875*pi, 0.3826834323650899)] This shows that lowering ``adaptive_tolerance`` and raising ``adaptive_recursion`` both increase the number of subdivision diff --git a/src/sage/plot/plot3d/base.pyx b/src/sage/plot/plot3d/base.pyx index 771fff25e54..85510d0c33a 100644 --- a/src/sage/plot/plot3d/base.pyx +++ b/src/sage/plot/plot3d/base.pyx @@ -1765,17 +1765,17 @@ end_scene""".format( EXAMPLES: We illustrate use of the ``aspect_ratio`` option:: - sage: x, y = var('x,y') # optional -- sage.symbolic - sage: p = plot3d(2*sin(x*y), (x, -pi, pi), (y, -pi, pi)) # optional -- sage.symbolic - sage: p.show(aspect_ratio=[1,1,1]) # optional -- sage.symbolic + sage: x, y = var('x,y') # needs sage.symbolic + sage: p = plot3d(2*sin(x*y), (x, -pi, pi), (y, -pi, pi)) # needs sage.symbolic + sage: p.show(aspect_ratio=[1,1,1]) # needs sage.symbolic This looks flattened, but filled with the plot:: - sage: p.show(frame_aspect_ratio=[1,1,1/16]) # optional -- sage.symbolic + sage: p.show(frame_aspect_ratio=[1,1,1/16]) # needs sage.symbolic This looks flattened, but the plot is square and smaller:: - sage: p.show(aspect_ratio=[1,1,1], frame_aspect_ratio=[1,1,1/8]) # optional -- sage.symbolic + sage: p.show(aspect_ratio=[1,1,1], frame_aspect_ratio=[1,1,1/8]) # needs sage.symbolic This example shows indirectly that the defaults from :func:`~sage.plot.plot.plot` are dealt with properly:: @@ -1786,17 +1786,17 @@ end_scene""".format( We use the 'canvas3d' backend from inside the notebook to get a view of the plot rendered inline using HTML canvas:: - sage: p.show(viewer='canvas3d') # optional -- sage.symbolic + sage: p.show(viewer='canvas3d') # needs sage.symbolic Sometimes shadows in Tachyon-produced images can lead to confusing plots. To remove them:: - sage: p.show(viewer="tachyon", shade="medium") # optional -- sage.symbolic + sage: p.show(viewer="tachyon", shade="medium") # needs sage.symbolic One can also pass Tachyon command line flags directly. For example, the following line produces the same result as the previous one:: - sage: p.show(viewer="tachyon", extra_opts="-mediumshade") # optional -- sage.symbolic + sage: p.show(viewer="tachyon", extra_opts="-mediumshade") # needs sage.symbolic """ from sage.repl.rich_output import get_display_manager dm = get_display_manager() @@ -1990,10 +1990,11 @@ end_scene""".format( EXAMPLES:: - sage: x,y,z = var('x,y,z') # optional -- sage.symbolic - sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) # optional -- sage.symbolic - sage: astl = a.stl_binary() # optional -- sage.symbolic - sage: print(astl[:40].decode('ascii')) # optional -- sage.symbolic + sage: # needs sage.symbolic + sage: x,y,z = var('x,y,z') + sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) + sage: astl = a.stl_binary() + sage: print(astl[:40].decode('ascii')) STL binary file / made by SageMath / ### sage: p = polygon3d([[0,0,0], [1,2,3], [3,0,0]]) @@ -2002,9 +2003,9 @@ end_scene""".format( This works when faces have more then 3 sides:: - sage: P = polytopes.dodecahedron() # optional -- sage.geometry.polyhedron - sage: Q = P.plot().all[-1] # optional -- sage.geometry.polyhedron - sage: print(Q.stl_binary()[:40].decode('ascii')) # optional -- sage.geometry.polyhedron + sage: P = polytopes.dodecahedron() # needs sage.geometry.polyhedron + sage: Q = P.plot().all[-1] # needs sage.geometry.polyhedron + sage: print(Q.stl_binary()[:40].decode('ascii')) # needs sage.geometry.polyhedron STL binary file / made by SageMath / ### """ import struct @@ -2037,10 +2038,11 @@ end_scene""".format( EXAMPLES:: - sage: x,y,z = var('x,y,z') # optional -- sage.symbolic - sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) # optional -- sage.symbolic - sage: astl = a.stl_ascii_string() # optional -- sage.symbolic - sage: astl.splitlines()[:7] # abs tol 1e-10 # optional -- sage.symbolic + sage: # needs sage.symbolic + sage: x,y,z = var('x,y,z') + sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) + sage: astl = a.stl_ascii_string() + sage: astl.splitlines()[:7] # abs tol 1e-10 ['solid surface', 'facet normal 0.9733285267845754 -0.16222142113076257 -0.16222142113076257', ' outer loop', @@ -2063,9 +2065,9 @@ end_scene""".format( Now works when faces have more then 3 sides:: - sage: P = polytopes.dodecahedron() # optional -- sage.geometry.polyhedron - sage: Q = P.plot().all[-1] # optional -- sage.geometry.polyhedron - sage: print(Q.stl_ascii_string().splitlines()[:7]) # optional -- sage.geometry.polyhedron + sage: P = polytopes.dodecahedron() # needs sage.geometry.polyhedron + sage: Q = P.plot().all[-1] # needs sage.geometry.polyhedron + sage: print(Q.stl_ascii_string().splitlines()[:7]) # needs sage.geometry.polyhedron ['solid surface', 'facet normal 0.0 0.5257311121191338 0.8506508083520399', ' outer loop', @@ -2132,10 +2134,11 @@ end_scene""".format( EXAMPLES:: - sage: x,y,z = var('x,y,z') # optional -- sage.symbolic - sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) # optional -- sage.symbolic - sage: astl = a.ply_ascii_string() # optional -- sage.symbolic - sage: astl.splitlines()[:10] # optional -- sage.symbolic + sage: # needs sage.symbolic + sage: x,y,z = var('x,y,z') + sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) + sage: astl = a.ply_ascii_string() + sage: astl.splitlines()[:10] ['ply', 'format ascii 1.0', 'comment surface', @@ -2206,10 +2209,11 @@ end_scene""".format( EXAMPLES:: - sage: x,y,z = var('x,y,z') # optional -- sage.symbolic - sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) # optional -- sage.symbolic - sage: a_amf = a.amf_ascii_string() # optional -- sage.symbolic - sage: a_amf[:160] # optional -- sage.symbolic + sage: # needs sage.symbolic + sage: x,y,z = var('x,y,z') + sage: a = implicit_plot3d(x^2+y^2+z^2-9,[x,-5,5],[y,-5,5],[z,-5,5]) + sage: a_amf = a.amf_ascii_string() + sage: a_amf[:160] '2.948717948717948-0.384615384615385-0.3935' sage: p = polygon3d([[0,0,0], [1,2,3], [3,0,0]]) diff --git a/src/sage/plot/plot3d/index_face_set.pyx b/src/sage/plot/plot3d/index_face_set.pyx index 16421d54726..7c2c9fb535b 100644 --- a/src/sage/plot/plot3d/index_face_set.pyx +++ b/src/sage/plot/plot3d/index_face_set.pyx @@ -398,21 +398,22 @@ cdef class IndexFaceSet(PrimitiveObject): EXAMPLES:: - sage: var('x,y,z') # optional - sage.symbolic + sage: # needs sage.symbolic + sage: var('x,y,z') (x, y, z) - sage: G = implicit_plot3d(x^2+y^2+z^2 - 1, # optional - sage.symbolic + sage: G = implicit_plot3d(x^2+y^2+z^2 - 1, ....: (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=6) - sage: G.triangulate() # indirect doctest # optional - sage.symbolic - sage: len(G.face_list()) # optional - sage.symbolic + sage: G.triangulate() # indirect doctest + sage: len(G.face_list()) 44 - sage: len(G.vertex_list()) # optional - sage.symbolic + sage: len(G.vertex_list()) 132 - sage: G = implicit_plot3d(x^2+y^2+z^2 - 100, # optional - sage.symbolic + sage: G = implicit_plot3d(x^2+y^2+z^2 - 100, ....: (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=6) - sage: G.triangulate() # indirect doctest # optional - sage.symbolic - sage: len(G.face_list()) # optional - sage.symbolic + sage: G.triangulate() # indirect doctest + sage: len(G.face_list()) 0 - sage: len(G.vertex_list()) # optional - sage.symbolic + sage: len(G.vertex_list()) 0 """ self.vs = check_reallocarray(self.vs, vcount, sizeof(point_c)) @@ -900,9 +901,9 @@ cdef class IndexFaceSet(PrimitiveObject): EXAMPLES:: - sage: x,y = var('x,y') # optional - sage.symbolic - sage: p = plot3d(sqrt(sin(x)*sin(y)), (x,0,2*pi), (y,0,2*pi)) # optional - sage.symbolic - sage: p.bounding_box() # optional - sage.symbolic + sage: x,y = var('x,y') # needs sage.symbolic + sage: p = plot3d(sqrt(sin(x)*sin(y)), (x,0,2*pi), (y,0,2*pi)) # needs sage.symbolic + sage: p.bounding_box() # needs sage.symbolic ((0.0, 0.0, 0.0), (6.283185307179586, 6.283185307179586, 0.9991889981715697)) """ if self.vcount == 0: @@ -1010,12 +1011,12 @@ cdef class IndexFaceSet(PrimitiveObject): EXAMPLES:: - sage: var('x,y,z') # optional - sage.symbolic + sage: var('x,y,z') # needs sage.symbolic (x, y, z) - sage: P = implicit_plot3d(z-x*y,(-2,2),(-2,2),(-2,2)) # optional - sage.symbolic + sage: P = implicit_plot3d(z-x*y,(-2,2),(-2,2),(-2,2)) # needs sage.symbolic sage: def condi(x,y,z): ....: return bool(x*x+y*y+z*z <= Integer(1)) - sage: R = P.add_condition(condi, 20); R # optional - sage.symbolic + sage: R = P.add_condition(condi, 20); R # needs sage.symbolic Graphics3d Object .. PLOT:: @@ -1032,9 +1033,9 @@ cdef class IndexFaceSet(PrimitiveObject): ....: return bool(x*x+y*y <= 1.1) sage: cm = colormaps.hsv sage: cf = lambda x,y,z: float(x+y) % 1 - sage: P = implicit_plot3d(x**2+y**2+z**2-1-x**2*z+y**2*z, # optional - sage.symbolic + sage: P = implicit_plot3d(x**2+y**2+z**2-1-x**2*z+y**2*z, # needs sage.symbolic ....: (-2,2),(-2,2),(-2,2),color=(cm,cf)) - sage: R = P.add_condition(condi,40); R # optional - sage.symbolic + sage: R = P.add_condition(condi,40); R # needs sage.symbolic Graphics3d Object .. PLOT:: @@ -1049,11 +1050,11 @@ cdef class IndexFaceSet(PrimitiveObject): An example with transparency:: - sage: P = implicit_plot3d(x**4+y**4+z**2-4, (x,-2,2), (y,-2,2), (z,-2,2), # optional - sage.symbolic + sage: P = implicit_plot3d(x**4+y**4+z**2-4, (x,-2,2), (y,-2,2), (z,-2,2), # needs sage.symbolic ....: alpha=0.3) sage: def cut(a,b,c): ....: return a*a+c*c > 2 - sage: Q = P.add_condition(cut,40); Q # optional - sage.symbolic + sage: Q = P.add_condition(cut,40); Q # needs sage.symbolic Graphics3d Object .. PLOT:: @@ -1066,11 +1067,11 @@ cdef class IndexFaceSet(PrimitiveObject): A sombrero with quadrilaterals:: - sage: P = plot3d(-sin(2*x*x+2*y*y)*exp(-x*x-y*y), (x,-2,2), (y,-2,2), # optional - sage.symbolic + sage: P = plot3d(-sin(2*x*x+2*y*y)*exp(-x*x-y*y), (x,-2,2), (y,-2,2), # needs sage.symbolic ....: color='gold') sage: def cut(x,y,z): ....: return x*x+y*y < 1 - sage: Q = P.add_condition(cut);Q # optional - sage.symbolic + sage: Q = P.add_condition(cut);Q # needs sage.symbolic Graphics3d Object .. PLOT:: @@ -1085,13 +1086,14 @@ cdef class IndexFaceSet(PrimitiveObject): One test for preservation of transparency :trac:`28783`:: - sage: x,y,z = var('x,y,z') # optional - sage.symbolic - sage: P = plot3d(cos(x*y),(x,-2,2),(y,-2,2),color='red',opacity=0.1) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: x,y,z = var('x,y,z') + sage: P = plot3d(cos(x*y),(x,-2,2),(y,-2,2),color='red',opacity=0.1) sage: def condi(x,y,z): ....: return not(x*x+y*y <= 1) - sage: Q = P.add_condition(condi, 40) # optional - sage.symbolic - sage: L = Q.json_repr(Q.default_render_params()) # optional - sage.symbolic - sage: '"opacity":0.1' in L[-1] # optional - sage.symbolic + sage: Q = P.add_condition(condi, 40) + sage: L = Q.json_repr(Q.default_render_params()) + sage: '"opacity":0.1' in L[-1] True A test that this works with polygons:: @@ -1099,7 +1101,7 @@ cdef class IndexFaceSet(PrimitiveObject): sage: p = polygon3d([[2,0,0], [0,2,0], [0,0,3]]) sage: def f(x,y,z): ....: return bool(x*x+y*y+z*z<=5) - sage: cut = p.add_condition(f,60,1.0e-12); cut.face_list() # optional - sage.symbolic + sage: cut = p.add_condition(f,60,1.0e-12); cut.face_list() # needs sage.symbolic [[(0.556128491210302, 0.0, 2.165807263184547), (2.0, 0.0, 0.0), (0.0, 2.0, 0.0), diff --git a/src/sage/plot/plot3d/shapes.pyx b/src/sage/plot/plot3d/shapes.pyx index 72a94213359..ce8083c41c6 100644 --- a/src/sage/plot/plot3d/shapes.pyx +++ b/src/sage/plot/plot3d/shapes.pyx @@ -80,7 +80,7 @@ def validate_frame_size(size): Traceback (most recent call last): ... ValueError: each box dimension must be nonnegative - sage: validate_frame_size([sqrt(-1),3,2]) # optional - sage.symbolic + sage: validate_frame_size([sqrt(-1),3,2]) # needs sage.symbolic Traceback (most recent call last): ... TypeError: each box dimension must coerce to a float @@ -138,10 +138,10 @@ class Box(IndexFaceSet): A sinusoidal stack of multicolored boxes:: - sage: B = sum(Box([2,4,1/4], # optional - sage.symbolic + sage: B = sum(Box([2,4,1/4], # needs sage.symbolic ....: color=(i/4,i/5,1)).translate((sin(i),0,5-i)) ....: for i in [0..20]) - sage: show(B, figsize=6) # optional - sage.symbolic + sage: show(B, figsize=6) # needs sage.symbolic .. PLOT:: @@ -292,7 +292,7 @@ cdef class Cone(ParametricSurface): A spiky plot of the sine function:: - sage: sum(Cone(.1, sin(n), color='yellow').translate(n, sin(n), 0) # optional - sage.symbolic + sage: sum(Cone(.1, sin(n), color='yellow').translate(n, sin(n), 0) # needs sage.symbolic ....: for n in [0..10, step=.1]) Graphics3d Object @@ -303,11 +303,11 @@ cdef class Cone(ParametricSurface): A Christmas tree:: - sage: T = sum(Cone(exp(-n/5), 4/3*exp(-n/5), # optional - sage.symbolic + sage: T = sum(Cone(exp(-n/5), 4/3*exp(-n/5), # needs sage.symbolic ....: color=(0, .5, 0)).translate(0, 0, -3*exp(-n/5)) ....: for n in [1..7]) - sage: T += Cone(1/8, 1, color='brown').translate(0, 0, -3) # optional - sage.symbolic - sage: T.show(aspect_ratio=1, frame=False) # optional - sage.symbolic + sage: T += Cone(1/8, 1, color='brown').translate(0, 0, -3) # needs sage.symbolic + sage: T.show(aspect_ratio=1, frame=False) # needs sage.symbolic .. PLOT:: @@ -413,11 +413,11 @@ cdef class Cylinder(ParametricSurface): Some gears:: sage: G = Cylinder(1, .5) + Cylinder(.25, 3).translate(0, 0, -3) - sage: G += sum(Cylinder(.2, 1).translate(cos(2*pi*n/9), sin(2*pi*n/9), 0) # optional - sage.symbolic + sage: G += sum(Cylinder(.2, 1).translate(cos(2*pi*n/9), sin(2*pi*n/9), 0) # needs sage.symbolic ....: for n in [1..9]) - sage: G += G.translate(2.3, 0, -.5) # optional - sage.symbolic - sage: G += G.translate(3.5, 2, -1) # optional - sage.symbolic - sage: G.show(aspect_ratio=1, frame=False) # optional - sage.symbolic + sage: G += G.translate(2.3, 0, -.5) # needs sage.symbolic + sage: G += G.translate(3.5, 2, -1) # needs sage.symbolic + sage: G.show(aspect_ratio=1, frame=False) # needs sage.symbolic .. PLOT:: @@ -731,7 +731,7 @@ def arrow3d(start, end, width=1, radius=None, head_radius=None, head_len=None, * Many arrows arranged in a circle (flying spears?):: - sage: sum(arrow3d((cos(t),sin(t),0), (cos(t),sin(t),1)) # optional - sage.symbolic + sage: sum(arrow3d((cos(t),sin(t),0), (cos(t),sin(t),1)) # needs sage.symbolic ....: for t in [0,0.3,..,2*pi]) Graphics3d Object diff --git a/src/sage/plot/plot3d/shapes2.py b/src/sage/plot/plot3d/shapes2.py index 55e87b2f53a..18e37bbfefe 100644 --- a/src/sage/plot/plot3d/shapes2.py +++ b/src/sage/plot/plot3d/shapes2.py @@ -161,7 +161,7 @@ def tetra(col): This function should work for anything than can be turned into a list, such as iterators and such (see :trac:`10478`):: - sage: line3d(iter([(0,0,0), (sqrt(3), 2, 4)])) # optional - sage.symbolic + sage: line3d(iter([(0,0,0), (sqrt(3), 2, 4)])) # needs sage.symbolic Graphics3d Object sage: line3d((x, x^2, x^3) for x in range(5)) Graphics3d Object @@ -251,7 +251,7 @@ def bezier3d(path, **options): sage: path = [[(0,0,0),(.5,.1,.2),(.75,3,-1),(1,1,0)], ....: [(.5,1,.2),(1,.5,0)], [(.7,.2,.5)]] - sage: b = bezier3d(path, color='green'); b # optional - sage.symbolic + sage: b = bezier3d(path, color='green'); b # needs sage.symbolic Graphics3d Object .. PLOT:: @@ -262,7 +262,7 @@ def bezier3d(path, **options): To construct a simple curve, create a list containing a single list:: sage: path = [[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]] - sage: curve = bezier3d(path, thickness=5, color='blue'); curve # optional - sage.symbolic + sage: curve = bezier3d(path, thickness=5, color='blue'); curve # needs sage.symbolic Graphics3d Object .. PLOT:: @@ -276,14 +276,14 @@ def bezier3d(path, **options): sage: p2d = [[(3,0.0),(3,0.13),(2,0.2),(2,0.3)], ....: [(2.7,0.4),(2.6,0.5),(2.5,0.5)], [(2.3,0.5),(2.2,0.4),(2.1,0.3)]] - sage: bp = bezier_path(p2d) # optional - sage.symbolic - sage: bp.plot3d() # optional - sage.symbolic + sage: bp = bezier_path(p2d) # needs sage.symbolic + sage: bp.plot3d() # needs sage.symbolic Graphics3d Object sage: p3d = [[(3,0,0),(3,0.1,0),(2.9,0.2,0),(2.8,0.3,0)], ....: [(2.7,0.4,0),(2,0.5,0),(2.5,0.5,0)], ....: [(2.3,0.5,0),(2.2,0.4,0),(2.1,0.3,0)]] - sage: bezier3d(p3d) # optional - sage.symbolic + sage: bezier3d(p3d) # needs sage.symbolic Graphics3d Object """ from . import parametric_plot3d as P3D @@ -432,8 +432,8 @@ def frame3d(lower_left, upper_right, **kwds): This is usually used for making an actual plot:: - sage: y = var('y') # optional - sage.symbolic - sage: plot3d(sin(x^2+y^2), (x,0,pi), (y,0,pi)) # optional - sage.symbolic + sage: y = var('y') # needs sage.symbolic + sage: plot3d(sin(x^2+y^2), (x,0,pi), (y,0,pi)) # needs sage.symbolic Graphics3d Object """ x0, y0, z0 = lower_left @@ -489,11 +489,12 @@ def frame_labels(lower_left, upper_right, This is usually used for making an actual plot:: - sage: y = var('y') # optional - sage.symbolic - sage: P = plot3d(sin(x^2+y^2), (x,0,pi), (y,0,pi)) # optional - sage.symbolic - sage: a,b = P._rescale_for_frame_aspect_ratio_and_zoom(1.0,[1,1,1],1) # optional - sage.symbolic - sage: F = frame_labels(a, b, *P._box_for_aspect_ratio("automatic",a,b)) # optional - sage.symbolic - sage: F.jmol_repr(F.default_render_params())[0] # optional - sage.symbolic + sage: # needs sage.symbolic + sage: y = var('y') + sage: P = plot3d(sin(x^2+y^2), (x,0,pi), (y,0,pi)) + sage: a,b = P._rescale_for_frame_aspect_ratio_and_zoom(1.0,[1,1,1],1) + sage: F = frame_labels(a, b, *P._box_for_aspect_ratio("automatic",a,b)) + sage: F.jmol_repr(F.default_render_params())[0] [['select atomno = 1', 'color atom [76,76,76]', 'label "0.0"']] TESTS:: @@ -764,9 +765,9 @@ def sphere(center=(0, 0, 0), size=1, **kwds): We draw a transparent sphere on a saddle. :: - sage: u,v = var('u v') # optional - sage.symbolic - sage: saddle = plot3d(u^2 - v^2, (u,-2,2), (v,-2,2)) # optional - sage.symbolic - sage: sphere((0,0,1), color='red', opacity=0.5, aspect_ratio=[1,1,1]) + saddle # optional - sage.symbolic + sage: u,v = var('u v') # needs sage.symbolic + sage: saddle = plot3d(u^2 - v^2, (u,-2,2), (v,-2,2)) # needs sage.symbolic + sage: sphere((0,0,1), color='red', opacity=0.5, aspect_ratio=[1,1,1]) + saddle # needs sage.symbolic Graphics3d Object .. PLOT:: @@ -1067,7 +1068,7 @@ class Line(PrimitiveObject): sage: N = 11 sage: c = 0.4 - sage: sum(Line([(i,1,0), (i,0,0), (i,cos(2*pi*i/N), sin(2*pi*i/N))], # optional - sage.symbolic + sage: sum(Line([(i,1,0), (i,0,0), (i,cos(2*pi*i/N), sin(2*pi*i/N))], # needs sage.symbolic ....: corner_cutoff=c, ....: color='red' if -cos(2*pi*i/N)<=c else 'blue') ....: for i in range(N+1)) @@ -1106,8 +1107,8 @@ def bounding_box(self): TESTS:: sage: from sage.plot.plot3d.shapes2 import Line - sage: L = Line([(i, i^2 - 1, -2*ln(i)) for i in [10,20,30]]) # optional - sage.symbolic - sage: L.bounding_box() # optional - sage.symbolic + sage: L = Line([(i, i^2 - 1, -2*ln(i)) for i in [10,20,30]]) # needs sage.symbolic + sage: L.bounding_box() # needs sage.symbolic ((10.0, 99.0, -6.802394763324311), (30.0, 899.0, -4.605170185988092)) """ @@ -1124,9 +1125,9 @@ def tachyon_repr(self, render_params): TESTS:: - sage: L = line3d([(cos(i),sin(i),i^2) for i in srange(0,10,.01)], # optional - sage.symbolic + sage: L = line3d([(cos(i),sin(i),i^2) for i in srange(0,10,.01)], # needs sage.symbolic ....: color='red') - sage: L.tachyon_repr(L.default_render_params())[0] # optional - sage.symbolic + sage: L.tachyon_repr(L.default_render_params())[0] # needs sage.symbolic 'FCylinder base 1.0 0.0 0.0 apex 0.9999500004166653 0.009999833334166664 0.0001 rad 0.005 texture...' """ T = render_params.transform @@ -1157,9 +1158,9 @@ def obj_repr(self, render_params): TESTS:: sage: from sage.plot.plot3d.shapes2 import Line - sage: L = Line([(cos(i),sin(i),i^2) for i in srange(0,10,.01)], # optional - sage.symbolic + sage: L = Line([(cos(i),sin(i),i^2) for i in srange(0,10,.01)], # needs sage.symbolic ....: color='red') - sage: L.obj_repr(L.default_render_params())[0][0][0][2][:3] # optional - sage.symbolic + sage: L.obj_repr(L.default_render_params())[0][0][0][2][:3] # needs sage.symbolic ['v 0.99995 0.00999983 0.0001', 'v 1.02376 0.010195 -0.00750607', 'v 1.00007 0.0102504 -0.0248984'] @@ -1181,9 +1182,9 @@ def jmol_repr(self, render_params): TESTS:: - sage: L = line3d([(cos(i),sin(i),i^2) for i in srange(0,10,.01)], # optional - sage.symbolic + sage: L = line3d([(cos(i),sin(i),i^2) for i in srange(0,10,.01)], # needs sage.symbolic ....: color='red') - sage: L.jmol_repr(L.default_render_params())[0][:42] # optional - sage.symbolic + sage: L.jmol_repr(L.default_render_params())[0][:42] # needs sage.symbolic 'draw line_1 diameter 1 curve {1.0 0.0 0.0}' """ T = render_params.transform @@ -1441,10 +1442,10 @@ def point3d(v, size=5, **kwds): sage: print(point(vector((2,3,4)))) Graphics3d Object - sage: c = polytopes.hypercube(3) # optional - sage.geometry.polyhedron - sage: v = c.vertices()[0]; v # optional - sage.geometry.polyhedron + sage: c = polytopes.hypercube(3) # needs sage.geometry.polyhedron + sage: v = c.vertices()[0]; v # needs sage.geometry.polyhedron A vertex at (1, -1, -1) - sage: print(point(v)) # optional - sage.geometry.polyhedron + sage: print(point(v)) # needs sage.geometry.polyhedron Graphics3d Object We check to make sure the options work:: diff --git a/src/sage/plot/plot3d/tachyon.py b/src/sage/plot/plot3d/tachyon.py index b2130f39cd9..9c5719f894e 100644 --- a/src/sage/plot/plot3d/tachyon.py +++ b/src/sage/plot/plot3d/tachyon.py @@ -125,17 +125,18 @@ sage: T.save(fname_png) sage: r2 = os.system('convert '+fname_png+' '+fname_ppm) # optional -- ImageMagick - sage: T = Tachyon(xres=800, yres=600, # optional -- ImageMagick + sage: # optional - imagemagick + sage: T = Tachyon(xres=800, yres=600, ....: camera_position=(-2.0,-.1,.3), ....: projection='fisheye', ....: frustum=(-1.0, 1.0, -1.0, 1.0)) - sage: T.texture('t1', color=(1,0,0), specular=.9) # optional -- ImageMagick - sage: T.texture('p1', color=(1,1,1), opacity=.1, # optional -- ImageMagick + sage: T.texture('t1', color=(1,0,0), specular=.9) + sage: T.texture('p1', color=(1,1,1), opacity=.1, ....: imagefile=fname_ppm, texfunc=9) - sage: T.sphere((0,0,0), .5, 't1') # optional -- ImageMagick - sage: T.plane((0,0,-1), (0,0,1), 'p1') # optional -- ImageMagick - sage: T.light((-4,-4,4), .1, (1,1,1)) # optional -- ImageMagick - sage: T.show() # optional -- ImageMagick + sage: T.sphere((0,0,0), .5, 't1') + sage: T.plane((0,0,-1), (0,0,1), 'p1') + sage: T.light((-4,-4,4), .1, (1,1,1)) + sage: T.show() AUTHOR: @@ -258,24 +259,26 @@ class Tachyon(WithEqualityById, SageObject): Points on an elliptic curve, their height indicated by their height above the axis:: + sage: # needs sage.schemes sage: t = Tachyon(camera_position=(5,2,2), look_at=(0,1,0)) sage: t.light((10,3,2), 0.2, (1,1,1)) sage: t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) sage: t.texture('t1', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,1,0)) sage: t.texture('t2', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,0,1)) - sage: E = EllipticCurve('37a') # optional - sage.schemes - sage: P = E([0,0]) # optional - sage.schemes - sage: Q = P # optional - sage.schemes + sage: E = EllipticCurve('37a') # needs sage.schemes + sage: P = E([0,0]) # needs sage.schemes + sage: Q = P # needs sage.schemes sage: n = 100 - sage: for i in range(n): # increase 20 for a better plot # optional - sage.schemes + sage: for i in range(n): # increase 20 for a better plot # needs sage.schemes ....: Q = Q + P ....: t.sphere((Q[1], Q[0], ZZ(i)/n), 0.1, 't%s'%(i%3)) - sage: t.show() # optional - sage.schemes + sage: t.show() # needs sage.schemes A beautiful picture of rational points on a rank 1 elliptic curve. :: + sage: # needs sage.schemes sage: t = Tachyon(xres=1000, yres=800, camera_position=(2,7,4), ....: look_at=(2,0,0), raydepth=4) sage: t.light((10,3,2), 1, (1,1,1)) @@ -286,16 +289,16 @@ class Tachyon(WithEqualityById, SageObject): sage: t.plane((0,0,0),(0,0,1),'grey') sage: t.cylinder((0,0,0),(1,0,0),.01,'black') sage: t.cylinder((0,0,0),(0,1,0),.01,'black') - sage: E = EllipticCurve('37a') # optional - sage.schemes - sage: P = E([0,0]) # optional - sage.schemes - sage: Q = P # optional - sage.schemes + sage: E = EllipticCurve('37a') # needs sage.schemes + sage: P = E([0,0]) # needs sage.schemes + sage: Q = P # needs sage.schemes sage: n = 100 - sage: for i in range(n): # optional - sage.schemes + sage: for i in range(n): # needs sage.schemes ....: Q = Q + P ....: c = i/n + .1 ....: t.texture('r%s'%i,color=(float(i/n),0,0)) ....: t.sphere((Q[0], -Q[1], .01), .04, 'r%s'%i) - sage: t.show() # long time, e.g., 10-20 seconds # optional - sage.schemes + sage: t.show() # long time # needs sage.schemes A beautiful spiral. @@ -305,11 +308,11 @@ class Tachyon(WithEqualityById, SageObject): sage: t.light((0,0,100), 1, (1,1,1)) sage: t.texture('r', ambient=0.1, diffuse=0.9, specular=0.5, ....: opacity=1.0, color=(1,0,0)) - sage: for i in srange(0,50,0.1): # optional - sage.schemes - ....: t.sphere((i/10,sin(i),cos(i)), 0.05, 'r') + sage: for i in srange(0,50,0.1): + ....: t.sphere((i/10.0,sin(i),cos(i)), 0.05, 'r') sage: t.texture('white', color=(1,1,1), opacity=1, specular=1, diffuse=1) sage: t.plane((0,0,-100), (0,0,-100), 'white') - sage: t.show() # optional - sage.schemes + sage: t.show() If the optional parameter ``viewdir`` is not set, the camera center should not coincide with the point which @@ -326,12 +329,11 @@ class Tachyon(WithEqualityById, SageObject): ....: projection='fisheye', frustum=(-1.0, 1.0, -1.0, 1.0)) sage: T.texture('t1', color=(0,0,1)) sage: cedges = [[[1, 1, 1], [-1, 1, 1]], [[1, 1, 1], [1, -1, 1]], - ....: [[1, 1, 1], [1, 1, -1]], [[-1, 1, 1], [-1, -1, 1]], [[-1, 1, 1], - ....: [-1, 1, -1]], [[1, -1, 1], [-1, -1, 1]], [[1, -1, 1], - ....: [1, -1, -1]], - ....: [[-1, -1, 1], [-1, -1, -1]], [[1, 1, -1], [-1, 1, -1]], - ....: [[1, 1, -1], [1, -1, -1]], [[-1, 1, -1], [-1, -1, -1]], - ....: [[1, -1, -1], [-1, -1, -1]]] + ....: [[1, 1, 1], [1, 1, -1]], [[-1, 1, 1], [-1, -1, 1]], + ....: [[-1, 1, 1], [-1, 1, -1]], [[1, -1, 1], [-1, -1, 1]], + ....: [[1, -1, 1], [1, -1, -1]], [[-1, -1, 1], [-1, -1, -1]], + ....: [[1, 1, -1], [-1, 1, -1]], [[1, 1, -1], [1, -1, -1]], + ....: [[-1, 1, -1], [-1, -1, -1]], [[1, -1, -1], [-1, -1, -1]]] sage: for ed in cedges: ....: T.fcylinder(ed[0], ed[1], .05, 't1') sage: T.light((-4,-4,4), .1, (1,1,1)) @@ -560,11 +562,11 @@ def show(self, **kwds): sage: def f(x,y): return float(sin(x*y)) sage: h.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, ....: opacity=1.0, color=(1.0,0,0)) - sage: h.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # optional -- sage.symbolic + sage: h.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # needs sage.symbolic ....: num_colors=60) # increase min_depth for better picture sage: from sage.misc.verbose import set_verbose, get_verbose sage: set_verbose(0) - sage: h.show() # optional -- sage.symbolic + sage: h.show() # needs sage.symbolic This second example, using a "medium" global verbosity setting of 1, displays some extra technical information then @@ -578,10 +580,10 @@ def show(self, **kwds): sage: def f(x,y): return float(sin(x*y)) sage: s.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, ....: opacity=1.0, color=(1.0,0,0)) - sage: s.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # optional -- sage.symbolic + sage: s.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # needs sage.symbolic ....: num_colors=60) # increase min_depth for better picture sage: set_verbose(1) - sage: s.show() # optional -- sage.symbolic + sage: s.show() # needs sage.symbolic tachyon ... Scene contains 2713 objects. ... @@ -601,11 +603,11 @@ def show(self, **kwds): sage: def f(x,y): return float(sin(x*y)) sage: d.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, ....: opacity=1.0, color=(1.0,0,0)) - sage: d.plot(f,(-4,4),(-4,4),"t0",max_depth=5,initial_depth=3, # optional -- sage.symbolic + sage: d.plot(f,(-4,4),(-4,4),"t0",max_depth=5,initial_depth=3, # needs sage.symbolic ....: num_colors=60) # increase min_depth for better picture sage: get_verbose() 0 - sage: d.show(verbose=2) # optional -- sage.symbolic + sage: d.show(verbose=2) # needs sage.symbolic tachyon ... Scene contains 2713 objects. ... @@ -1013,9 +1015,9 @@ def plot(self, f, xmin_xmax, ymin_ymax, texture, grad_f=None, sage: def f(x,y): return float(sin(x*y)) sage: t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, ....: opacity=1.0, color=(1.0,0,0)) - sage: t.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # optional -- sage.symbolic + sage: t.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # needs sage.symbolic ....: num_colors=60) # increase min_depth for better picture - sage: t.show(verbose=1) # optional -- sage.symbolic + sage: t.show(verbose=1) # needs sage.symbolic tachyon ... Scene contains 2713 objects. ... @@ -1030,9 +1032,9 @@ def plot(self, f, xmin_xmax, ymin_ymax, texture, grad_f=None, sage: def g(x,y): return (float(y*cos(x*y)), float(x*cos(x*y)), 1) sage: t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.1, ....: opacity=1.0, color=(1.0,0,0)) - sage: t.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # optional -- sage.symbolic + sage: t.plot(f, (-4,4), (-4,4), "t0", max_depth=5, initial_depth=3, # needs sage.symbolic ....: grad_f=g) # increase min_depth for better picture - sage: t.show(verbose=1) # optional -- sage.symbolic + sage: t.show(verbose=1) # needs sage.symbolic tachyon ... Scene contains 2713 objects. ... diff --git a/src/sage/plot/point.py b/src/sage/plot/point.py index 3b3d5821ba6..2bbe8cef07a 100644 --- a/src/sage/plot/point.py +++ b/src/sage/plot/point.py @@ -4,12 +4,12 @@ TESTS:: - sage: E = EllipticCurve('37a') # optional - sage.schemes - sage: P = E(0,0) # optional - sage.schemes + sage: E = EllipticCurve('37a') # needs sage.schemes + sage: P = E(0,0) # needs sage.schemes sage: def get_points(n): ....: return sum(point(list(i*P)[:2], size=3) ....: for i in range(-n,n) if i != 0 and (i*P)[0] < 3) - sage: sum(get_points(15*n).plot3d(z=n) for n in range(1,10)) # optional - sage.schemes + sage: sum(get_points(15*n).plot3d(z=n) for n in range(1,10)) # needs sage.schemes Graphics3d Object """ @@ -371,10 +371,10 @@ def point(points, **kwds): Extra options will get passed on to show(), as long as they are valid:: - sage: point([(cos(theta), sin(theta)) # optional - sage.symbolic + sage: point([(cos(theta), sin(theta)) # needs sage.symbolic ....: for theta in srange(0, 2*pi, pi/8)], frame=True) Graphics object consisting of 1 graphics primitive - sage: point([(cos(theta), sin(theta)) # These are equivalent # optional - sage.symbolic + sage: point([(cos(theta), sin(theta)) # These are equivalent # needs sage.symbolic ....: for theta in srange(0, 2*pi, pi/8)]).show(frame=True) TESTS: @@ -508,7 +508,7 @@ def point2d(points, **options): sage: P = points([(0, 0), (1, 0)], pointsize=40, ....: legend_label='origin', legend_color='red') - sage: P + plot(x^2, (x, 0, 1), legend_label='plot', legend_color='green') # optional - sage.symbolic + sage: P + plot(x^2, (x, 0, 1), legend_label='plot', legend_color='green') # needs sage.symbolic Graphics object consisting of 2 graphics primitives .. PLOT:: @@ -519,10 +519,10 @@ def point2d(points, **options): Extra options will get passed on to show(), as long as they are valid:: - sage: point([(cos(theta), sin(theta)) # optional - sage.symbolic + sage: point([(cos(theta), sin(theta)) # needs sage.symbolic ....: for theta in srange(0, 2*pi, pi/8)], frame=True) Graphics object consisting of 1 graphics primitive - sage: point([(cos(theta), sin(theta)) # These are equivalent # optional - sage.symbolic + sage: point([(cos(theta), sin(theta)) # These are equivalent # needs sage.symbolic ....: for theta in srange(0, 2*pi, pi/8)]).show(frame=True) .. PLOT:: @@ -553,9 +553,9 @@ def point2d(points, **options): We can plot a single complex number:: - sage: point(1 + I, pointsize=100) # optional - sage.symbolic + sage: point(1 + I, pointsize=100) # needs sage.symbolic Graphics object consisting of 1 graphics primitive - sage: point(sqrt(2) + I, pointsize=100) # optional - sage.symbolic + sage: point(sqrt(2) + I, pointsize=100) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -568,7 +568,7 @@ def point2d(points, **options): We can also plot a list of complex numbers:: - sage: point([I, 1 + I, 2 + 2*I], pointsize=100) # optional - sage.symbolic + sage: point([I, 1 + I, 2 + 2*I], pointsize=100) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: diff --git a/src/sage/plot/polygon.py b/src/sage/plot/polygon.py index 70f77c22778..6f2c2b3f78b 100644 --- a/src/sage/plot/polygon.py +++ b/src/sage/plot/polygon.py @@ -198,7 +198,7 @@ def plot3d(self, z=0, **kwds): A pentagon:: - sage: polygon([(cos(t), sin(t)) # optional - sage.symbolic + sage: polygon([(cos(t), sin(t)) # needs sage.symbolic ....: for t in srange(0, 2*pi, 2*pi/5)]).plot3d() Graphics3d Object @@ -365,8 +365,8 @@ def polygon2d(points, **options): For filled polygons, one can use different colors for the border and the interior as follows:: - sage: L = [[0,0]]+[[i/100, 1.1+cos(i/20)] for i in range(100)]+[[1,0]] # optional - sage.symbolic - sage: polygon2d(L, color="limegreen", edgecolor="black", axes=False) # optional - sage.symbolic + sage: L = [[0,0]]+[[i/100, 1.1+cos(i/20)] for i in range(100)]+[[1,0]] # needs sage.symbolic + sage: polygon2d(L, color="limegreen", edgecolor="black", axes=False) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -389,8 +389,8 @@ def polygon2d(points, **options): An aperiodic monotile, [Smi2023]_:: - sage: s = sqrt(3) # optional - sage.symbolic - sage: polygon2d([[0, 0], [0, s], [1, s], [3/2, 3/2*s], [3, s], [3, 0], [4, 0], # optional - sage.symbolic + sage: s = sqrt(3) # needs sage.symbolic + sage: polygon2d([[0, 0], [0, s], [1, s], [3/2, 3/2*s], [3, s], [3, 0], [4, 0], # needs sage.symbolic ....: [9/2, -1/2*s], [3, -s], [3/2, -1/2*s], [1, -s], [-1, -s], ....: [-3/2, -1/2*s]], axes=False) Graphics object consisting of 1 graphics primitive @@ -404,8 +404,8 @@ def polygon2d(points, **options): A purple hexagon:: - sage: L = [[cos(pi*i/3),sin(pi*i/3)] for i in range(6)] # optional - sage.symbolic - sage: polygon2d(L, rgbcolor=(1,0,1)) # optional - sage.symbolic + sage: L = [[cos(pi*i/3),sin(pi*i/3)] for i in range(6)] # needs sage.symbolic + sage: polygon2d(L, rgbcolor=(1,0,1)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -416,9 +416,9 @@ def polygon2d(points, **options): A green deltoid:: - sage: L = [[-1+cos(pi*i/100)*(1+cos(pi*i/100)), # optional - sage.symbolic + sage: L = [[-1+cos(pi*i/100)*(1+cos(pi*i/100)), # needs sage.symbolic ....: 2*sin(pi*i/100)*(1-cos(pi*i/100))] for i in range(200)] - sage: polygon2d(L, rgbcolor=(1/8,3/4,1/2)) # optional - sage.symbolic + sage: polygon2d(L, rgbcolor=(1/8,3/4,1/2)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -429,9 +429,9 @@ def polygon2d(points, **options): A blue hypotrochoid:: - sage: L = [[6*cos(pi*i/100)+5*cos((6/2)*pi*i/100), # optional - sage.symbolic + sage: L = [[6*cos(pi*i/100)+5*cos((6/2)*pi*i/100), # needs sage.symbolic ....: 6*sin(pi*i/100)-5*sin((6/2)*pi*i/100)] for i in range(200)] - sage: polygon2d(L, rgbcolor=(1/8,1/4,1/2)) # optional - sage.symbolic + sage: polygon2d(L, rgbcolor=(1/8,1/4,1/2)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -443,9 +443,9 @@ def polygon2d(points, **options): Another one:: sage: n = 4; h = 5; b = 2 - sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100), # optional - sage.symbolic + sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100), # needs sage.symbolic ....: n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] - sage: polygon2d(L, rgbcolor=(1/8,1/4,3/4)) # optional - sage.symbolic + sage: polygon2d(L, rgbcolor=(1/8,1/4,3/4)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -458,9 +458,9 @@ def polygon2d(points, **options): A purple epicycloid:: sage: m = 9; b = 1 - sage: L = [[m*cos(pi*i/100)+b*cos((m/b)*pi*i/100), # optional - sage.symbolic + sage: L = [[m*cos(pi*i/100)+b*cos((m/b)*pi*i/100), # needs sage.symbolic ....: m*sin(pi*i/100)-b*sin((m/b)*pi*i/100)] for i in range(200)] - sage: polygon2d(L, rgbcolor=(7/8,1/4,3/4)) # optional - sage.symbolic + sage: polygon2d(L, rgbcolor=(7/8,1/4,3/4)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -472,8 +472,8 @@ def polygon2d(points, **options): A brown astroid:: - sage: L = [[cos(pi*i/100)^3, sin(pi*i/100)^3] for i in range(200)] # optional - sage.symbolic - sage: polygon2d(L, rgbcolor=(3/4,1/4,1/4)) # optional - sage.symbolic + sage: L = [[cos(pi*i/100)^3, sin(pi*i/100)^3] for i in range(200)] # needs sage.symbolic + sage: polygon2d(L, rgbcolor=(3/4,1/4,1/4)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -484,9 +484,9 @@ def polygon2d(points, **options): And, my favorite, a greenish blob:: - sage: L = [[cos(pi*i/100)*(1+cos(pi*i/50)), # optional - sage.symbolic + sage: L = [[cos(pi*i/100)*(1+cos(pi*i/50)), # needs sage.symbolic ....: sin(pi*i/100)*(1+sin(pi*i/50))] for i in range(200)] - sage: polygon2d(L, rgbcolor=(1/8,3/4,1/2)) # optional - sage.symbolic + sage: polygon2d(L, rgbcolor=(1/8,3/4,1/2)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -497,9 +497,9 @@ def polygon2d(points, **options): This one is for my wife:: - sage: L = [[sin(pi*i/100)+sin(pi*i/50), # optional - sage.symbolic + sage: L = [[sin(pi*i/100)+sin(pi*i/50), # needs sage.symbolic ....: -(1+cos(pi*i/100)+cos(pi*i/50))] for i in range(-100,100)] - sage: polygon2d(L, rgbcolor=(1,1/4,1/2)) # optional - sage.symbolic + sage: polygon2d(L, rgbcolor=(1,1/4,1/2)) # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -510,7 +510,7 @@ def polygon2d(points, **options): One can do the same one with a colored legend label:: - sage: polygon2d(L, color='red', legend_label='For you!', legend_color='red') # optional - sage.symbolic + sage: polygon2d(L, color='red', legend_label='For you!', legend_color='red') # needs sage.symbolic Graphics object consisting of 1 graphics primitive .. PLOT:: diff --git a/src/sage/plot/text.py b/src/sage/plot/text.py index 90d8d5ee533..602cdfebddf 100644 --- a/src/sage/plot/text.py +++ b/src/sage/plot/text.py @@ -81,8 +81,8 @@ def _repr_(self): EXAMPLES:: - sage: T = text("I like cool constants", (pi,e)) # optional - sage.symbolic - sage: t = T[0];t # optional - sage.symbolic + sage: T = text("I like cool constants", (pi,e)) # needs sage.symbolic + sage: t = T[0];t # needs sage.symbolic Text 'I like cool constants' at the point (3.1415926535...,2.7182818284...) """ return "Text '%s' at the point (%s,%s)" % (self.string, self.x, self.y) From 6ff7f144a507e6c0eba37e363e970c94151b30df Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 5 Aug 2023 16:07:30 -0700 Subject: [PATCH 11/21] ./sage -fixdoctests --only-tags src/sage/ext/fast_callable.pyx --- src/sage/ext/fast_callable.pyx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/sage/ext/fast_callable.pyx b/src/sage/ext/fast_callable.pyx index 6097b3d718d..97a16b9452a 100644 --- a/src/sage/ext/fast_callable.pyx +++ b/src/sage/ext/fast_callable.pyx @@ -493,7 +493,7 @@ def _builder_and_stream(vars, domain): sage: _builder_and_stream(["x", "y"], ZZ) (, ) - sage: _builder_and_stream(["x", "y"], RR) # optional - sage.rings.real_mpfr + sage: _builder_and_stream(["x", "y"], RR) # needs sage.rings.real_mpfr (, ) @@ -503,7 +503,7 @@ def _builder_and_stream(vars, domain): interpreter:: sage: domain = RDF - sage: from sage.structure.element import Element as domain # optional - sage.modules + sage: from sage.structure.element import Element as domain # needs sage.modules sage: _builder_and_stream(["x", "y"], domain) (, ) @@ -1622,7 +1622,7 @@ class IntegerPowerFunction(): sage: cube = IntegerPowerFunction(3) sage: cube (^3) - sage: cube(AA(7)^(1/3)) # optional - sage.rings.number_field + sage: cube(AA(7)^(1/3)) # needs sage.rings.number_field 7.000000000000000? sage: cube.exponent 3 @@ -1820,18 +1820,18 @@ cpdef generate_code(Expression expr, InstructionStream stream): 25 sage: fc.op_list() [('load_arg', 0), ('load_arg', 1), ('py_call', , 2), 'return'] - sage: fc = fast_callable(expr) # optional - sage.symbolic - sage: fc(3.0r) # optional - sage.symbolic + sage: fc = fast_callable(expr) # needs sage.symbolic + sage: fc(3.0r) # needs sage.symbolic 4.0*pi + 12.0 - sage: fc = fast_callable(x+3, domain=ZZ) # optional - sage.symbolic - sage: fc(4) # optional - sage.symbolic + sage: fc = fast_callable(x+3, domain=ZZ) # needs sage.symbolic + sage: fc(4) # needs sage.symbolic 7 - sage: fc = fast_callable(x/3, domain=ZZ) # optional - sage.symbolic - sage: fc(4) # optional - sage.symbolic + sage: fc = fast_callable(x/3, domain=ZZ) # needs sage.symbolic + sage: fc(4) # needs sage.symbolic Traceback (most recent call last): ... TypeError: no conversion of this rational to integer - sage: fc(6) # optional - sage.symbolic + sage: fc(6) # needs sage.symbolic 2 sage: fc = fast_callable(etb.call(sin, x), domain=ZZ) sage: fc(0) From 322f19a4db423d3ad05fbb5f96e5090153c4eaac Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 5 Aug 2023 23:19:59 -0700 Subject: [PATCH 12/21] src/sage/misc/replace_dot_all.py: Update doctest output --- src/sage/misc/replace_dot_all.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/misc/replace_dot_all.py b/src/sage/misc/replace_dot_all.py index ebb9a83dfff..96ccbccd3bc 100644 --- a/src/sage/misc/replace_dot_all.py +++ b/src/sage/misc/replace_dot_all.py @@ -298,7 +298,7 @@ def process_line(location, line, replacements, row_index, verbose=False): sage: from sage.misc.replace_dot_all import * sage: location = os.path.join(sage.env.SAGE_SRC, 'sage/plot/arc.py') sage: replacements = find_replacements(location, package_regex='sage[.]plot[.]all', verbose=True); replacements - [[471, 24, 'from sage.plot.graphics import Graphics']] + [[476, 24, 'from sage.plot.graphics import Graphics']] sage: with open(location, "r") as file: ....: lines = file.readlines() sage: row_index, col_number, *_ = replacements[0] From e4e0926c94427c5ccc391cd70cb690d177fcf34f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 6 Aug 2023 18:51:38 -0700 Subject: [PATCH 13/21] src/sage/plot/complex_plot.pyx: Use block tags --- src/sage/plot/complex_plot.pyx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/sage/plot/complex_plot.pyx b/src/sage/plot/complex_plot.pyx index c2342341ab8..cb6a9cf8ca0 100644 --- a/src/sage/plot/complex_plot.pyx +++ b/src/sage/plot/complex_plot.pyx @@ -669,12 +669,13 @@ def add_lightness_smoothing_to_rgb(rgb, delta): We can call this on grids of values:: - sage: import numpy as np # needs numpy - sage: from sage.plot.complex_plot import add_lightness_smoothing_to_rgb # needs numpy - sage: add_lightness_smoothing_to_rgb( # abs tol 1e-4 # needs numpy + sage: # needs numpy + sage: import numpy as np + sage: from sage.plot.complex_plot import add_lightness_smoothing_to_rgb + sage: add_lightness_smoothing_to_rgb( # abs tol 1e-4 ....: np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) array([[[0.75 , 0.8125, 0.875 ]]]) - sage: add_lightness_smoothing_to_rgb( # abs tol 1e-4 # needs numpy + sage: add_lightness_smoothing_to_rgb( # abs tol 1e-4 ....: np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) array([[[0.75 , 0.8125, 0.875 ]]]) """ @@ -734,15 +735,15 @@ def add_contours_to_rgb(rgb, delta, dark_rate=0.5): EXAMPLES:: sage: # needs numpy - sage: import numpy as np # needs numpy - sage: from sage.plot.complex_plot import add_contours_to_rgb # needs numpy - sage: add_contours_to_rgb(np.array([[[0, 0.25, 0.5]]]), # abs tol 1e-4 # needs numpy + sage: import numpy as np + sage: from sage.plot.complex_plot import add_contours_to_rgb + sage: add_contours_to_rgb(np.array([[[0, 0.25, 0.5]]]), # abs tol 1e-4 ....: np.array([[0.75]])) array([[[0.25 , 0.625, 1. ]]]) - sage: add_contours_to_rgb(np.array([[[0, 0, 0]]]), # abs tol 1e-4 # needs numpy + sage: add_contours_to_rgb(np.array([[[0, 0, 0]]]), # abs tol 1e-4 ....: np.array([[1]])) array([[[0.5, 0.5, 0.5]]]) - sage: add_contours_to_rgb(np.array([[[1, 1, 1]]]), # abs tol 1e-4 # needs numpy + sage: add_contours_to_rgb(np.array([[[1, 1, 1]]]), # abs tol 1e-4 ....: np.array([[-0.5]])) array([[[0.75, 0.75, 0.75]]]) From 07542538717970cb23392b55733ffa2449938deb Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 6 Aug 2023 19:01:38 -0700 Subject: [PATCH 14/21] src/sage/plot/animate.py: Reformat --- src/sage/plot/animate.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/sage/plot/animate.py b/src/sage/plot/animate.py index 7a766674099..c5e22e7fb5b 100644 --- a/src/sage/plot/animate.py +++ b/src/sage/plot/animate.py @@ -87,8 +87,7 @@ ....: (x, -2, 2), (y, -2, 2), (z, -2, 2), ....: plot_points=60, contour=[1,3,5], ....: region=lambda x,y,z: x<=t or y>=t or z<=t) - sage: a = animate([frame(t) - ....: for t in srange(.01,1.5,.2)]) + sage: a = animate([frame(t) for t in srange(.01, 1.5, .2)]) sage: a[0] # long time Graphics3d Object sage: a.show() # long time # optional -- ImageMagick @@ -99,8 +98,7 @@ illustrated by the following example:: sage: t = SR.var("t") - sage: a = animate((sin(c*pi*t) - ....: for c in sxrange(1, 2, .2))) + sage: a = animate((sin(c*pi*t) for c in sxrange(1, 2, .2))) sage: a.show() # long time # optional -- ImageMagick @@ -149,8 +147,7 @@ def animate(frames, **kwds): EXAMPLES:: sage: t = SR.var("t") - sage: a = animate((cos(c*pi*t) - ....: for c in sxrange(1, 2, .2))) + sage: a = animate((cos(c*pi*t) for c in sxrange(1, 2, .2))) sage: a.show() # long time # optional -- ImageMagick See also :mod:`sage.plot.animate` for more examples. @@ -163,7 +160,6 @@ class Animation(WithEqualityById, SageObject): INPUT: - - ``v`` -- iterable of Sage objects. These should preferably be graphics objects, but if they aren't, then :meth:`make_image` is called on them. @@ -178,8 +174,7 @@ class Animation(WithEqualityById, SageObject): EXAMPLES:: sage: x = SR.var("x") - sage: a = animate([sin(x + float(k)) - ....: for k in srange(0, 2*pi, 0.3)], + sage: a = animate([sin(x + float(k)) for k in srange(0, 2*pi, 0.3)], ....: xmin=0, xmax=2*pi, figsize=[2,1]) sage: print(a) Animation with 21 frames @@ -533,7 +528,7 @@ def graphics_array(self, ncols=3): sage: a = animate(v, xmin=0, ymin=0, axes=False) sage: print(a) Animation with 3 frames - sage: a.show() # optional - imagemagick + sage: a.show() # optional -- ImageMagick Modify the default arrangement of array:: @@ -615,7 +610,7 @@ def gif(self, delay=20, savefile=None, iterations=0, show_path=False, sage: a.gif(savefile=td + 'my_animation.gif', # long time # optional -- ImageMagick ....: show_path=True) Animation saved to .../my_animation.gif. - sage: a.gif(savefile=td + 'my_animation_2.gif', # long time # optional -- ffmpeg + sage: a.gif(savefile=td + 'my_animation_2.gif', # long time # optional -- FFmpeg ....: show_path=True, use_ffmpeg=True) Animation saved to .../my_animation_2.gif. @@ -853,7 +848,7 @@ def show(self, delay=None, iterations=None, **kwds): You can also make use of the HTML5 video element in the Sage Notebook:: - sage: # long time, optional - ffmpeg + sage: # long time, optional -- FFmpeg sage: a.show(format="ogg") sage: a.show(format="webm") sage: a.show(format="mp4") @@ -861,7 +856,7 @@ def show(self, delay=None, iterations=None, **kwds): Other backends may support other file formats as well:: - sage: # long time, optional - ffmpeg + sage: # long time, optional -- FFmpeg sage: a.show(format="flash") sage: a.show(format="matroska") sage: a.show(format="avi") @@ -956,10 +951,10 @@ def ffmpeg(self, savefile=None, show_path=False, output_format=None, ....: for k in srange(0, 2*pi, 0.7)], ....: xmin=0, xmax=2*pi, ymin=-1, ymax=1, figsize=[2,1]) sage: td = tmp_dir() - sage: a.ffmpeg(savefile=td + 'new.mpg') # long time # optional -- ffmpeg - sage: a.ffmpeg(savefile=td + 'new.avi') # long time # optional -- ffmpeg - sage: a.ffmpeg(savefile=td + 'new.gif') # long time # optional -- ffmpeg - sage: a.ffmpeg(savefile=td + 'new.mpg', show_path=True) # long time # optional -- ffmpeg + sage: a.ffmpeg(savefile=td + 'new.mpg') # long time # optional -- FFmpeg + sage: a.ffmpeg(savefile=td + 'new.avi') # long time # optional -- FFmpeg + sage: a.ffmpeg(savefile=td + 'new.gif') # long time # optional -- FFmpeg + sage: a.ffmpeg(savefile=td + 'new.mpg', show_path=True) # long time # optional -- FFmpeg Animation saved to .../new.mpg. .. NOTE:: @@ -973,7 +968,7 @@ def ffmpeg(self, savefile=None, show_path=False, output_format=None, TESTS:: - sage: a.ffmpeg(output_format='gif',delay=30,iterations=5) # long time # optional -- ffmpeg + sage: a.ffmpeg(output_format='gif',delay=30,iterations=5) # long time # optional -- FFmpeg """ from sage.features.ffmpeg import FFmpeg FFmpeg().require() @@ -1152,7 +1147,7 @@ def save(self, filename=None, show_path=False, use_ffmpeg=False, **kwds): sage: a.save(td + 'wave.gif') # long time # optional -- ImageMagick sage: a.save(td + 'wave.gif', show_path=True) # long time # optional -- ImageMagick Animation saved to file .../wave.gif. - sage: a.save(td + 'wave.avi', show_path=True) # long time # optional -- ffmpeg + sage: a.save(td + 'wave.avi', show_path=True) # long time # optional -- FFmpeg Animation saved to file .../wave.avi. sage: a.save(td + 'wave0.sobj') sage: a.save(td + 'wave1.sobj', show_path=True) @@ -1166,7 +1161,7 @@ def save(self, filename=None, show_path=False, use_ffmpeg=False, **kwds): Ensure that we can pass delay and iteration count to the saved GIF image (see :trac:`18176`):: - sage: # long time, optional - imagemagick + sage: # long time, optional -- ImageMagick sage: a.save(td + 'wave.gif') sage: with open(td + 'wave.gif', 'rb') as f: ....: print(b'GIF8' in f.read()) From 2326a21a8b1d055f0e9acfbbb67e07cf12900206 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 6 Aug 2023 19:04:56 -0700 Subject: [PATCH 15/21] sage.plot: Use # needs in file-level tags --- src/sage/plot/colors.py | 2 +- src/sage/plot/contour_plot.py | 2 +- src/sage/plot/density_plot.py | 2 +- src/sage/plot/hyperbolic_arc.py | 2 +- src/sage/plot/hyperbolic_polygon.py | 2 +- src/sage/plot/hyperbolic_regular_polygon.py | 2 +- src/sage/plot/misc.py | 2 +- src/sage/plot/multigraphics.py | 2 +- src/sage/plot/plot.py | 2 +- src/sage/plot/plot3d/implicit_plot3d.py | 2 +- src/sage/plot/plot3d/implicit_surface.pyx | 2 +- src/sage/plot/plot3d/parametric_plot3d.py | 2 +- src/sage/plot/plot3d/parametric_surface.pyx | 2 +- src/sage/plot/plot3d/plot3d.py | 2 +- src/sage/plot/plot3d/plot_field3d.py | 2 +- src/sage/plot/plot3d/revolution_plot3d.py | 2 +- src/sage/plot/plot_field.py | 2 +- src/sage/plot/step.py | 2 +- src/sage/plot/streamline_plot.py | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/sage/plot/colors.py b/src/sage/plot/colors.py index 78b58ba6090..8c0db2b3c34 100644 --- a/src/sage/plot/colors.py +++ b/src/sage/plot/colors.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.plot +# sage.doctest: needs sage.plot r""" Colors diff --git a/src/sage/plot/contour_plot.py b/src/sage/plot/contour_plot.py index b909dc3d7b4..7a8be38979b 100644 --- a/src/sage/plot/contour_plot.py +++ b/src/sage/plot/contour_plot.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic """ Contour plots """ diff --git a/src/sage/plot/density_plot.py b/src/sage/plot/density_plot.py index bf4f26aec2f..b9f993239d0 100644 --- a/src/sage/plot/density_plot.py +++ b/src/sage/plot/density_plot.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic """ Density plots """ diff --git a/src/sage/plot/hyperbolic_arc.py b/src/sage/plot/hyperbolic_arc.py index 914cd77654c..4e7fda8350d 100644 --- a/src/sage/plot/hyperbolic_arc.py +++ b/src/sage/plot/hyperbolic_arc.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic r""" Arcs in hyperbolic geometry diff --git a/src/sage/plot/hyperbolic_polygon.py b/src/sage/plot/hyperbolic_polygon.py index 5539ddf63ab..efe39697829 100644 --- a/src/sage/plot/hyperbolic_polygon.py +++ b/src/sage/plot/hyperbolic_polygon.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic """ Polygons and triangles in hyperbolic geometry diff --git a/src/sage/plot/hyperbolic_regular_polygon.py b/src/sage/plot/hyperbolic_regular_polygon.py index 41c153882ec..a20d7d5a002 100644 --- a/src/sage/plot/hyperbolic_regular_polygon.py +++ b/src/sage/plot/hyperbolic_regular_polygon.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic """ Regular polygons in the upper half model for hyperbolic plane diff --git a/src/sage/plot/misc.py b/src/sage/plot/misc.py index f6421b53d65..72ee2c049b0 100644 --- a/src/sage/plot/misc.py +++ b/src/sage/plot/misc.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic """ Plotting utilities """ diff --git a/src/sage/plot/multigraphics.py b/src/sage/plot/multigraphics.py index bae3c3308b4..f22febca152 100644 --- a/src/sage/plot/multigraphics.py +++ b/src/sage/plot/multigraphics.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic r""" Graphics arrays and insets diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index a35fda0da27..0b5e76a5e20 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic r""" 2D plotting diff --git a/src/sage/plot/plot3d/implicit_plot3d.py b/src/sage/plot/plot3d/implicit_plot3d.py index 43eae504837..60a51a3dcbe 100644 --- a/src/sage/plot/plot3d/implicit_plot3d.py +++ b/src/sage/plot/plot3d/implicit_plot3d.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic """ Implicit plots """ diff --git a/src/sage/plot/plot3d/implicit_surface.pyx b/src/sage/plot/plot3d/implicit_surface.pyx index 8981b9e2bc7..db8a3f226f3 100644 --- a/src/sage/plot/plot3d/implicit_surface.pyx +++ b/src/sage/plot/plot3d/implicit_surface.pyx @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic r""" Graphics 3D object for representing and triangulating isosurfaces diff --git a/src/sage/plot/plot3d/parametric_plot3d.py b/src/sage/plot/plot3d/parametric_plot3d.py index fece32eda71..afb2d6fa129 100644 --- a/src/sage/plot/plot3d/parametric_plot3d.py +++ b/src/sage/plot/plot3d/parametric_plot3d.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic """ Parametric plots """ diff --git a/src/sage/plot/plot3d/parametric_surface.pyx b/src/sage/plot/plot3d/parametric_surface.pyx index e1f778215b5..11676df7dfe 100644 --- a/src/sage/plot/plot3d/parametric_surface.pyx +++ b/src/sage/plot/plot3d/parametric_surface.pyx @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic r""" Parametric surface diff --git a/src/sage/plot/plot3d/plot3d.py b/src/sage/plot/plot3d/plot3d.py index 86cb4b7bafb..41a1ad5de53 100644 --- a/src/sage/plot/plot3d/plot3d.py +++ b/src/sage/plot/plot3d/plot3d.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic r""" Plotting functions diff --git a/src/sage/plot/plot3d/plot_field3d.py b/src/sage/plot/plot3d/plot_field3d.py index fa84e05b307..d93d95cba57 100644 --- a/src/sage/plot/plot3d/plot_field3d.py +++ b/src/sage/plot/plot3d/plot_field3d.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic """ Plotting 3D fields """ diff --git a/src/sage/plot/plot3d/revolution_plot3d.py b/src/sage/plot/plot3d/revolution_plot3d.py index dbbd3c77eb6..b140c463c29 100644 --- a/src/sage/plot/plot3d/revolution_plot3d.py +++ b/src/sage/plot/plot3d/revolution_plot3d.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.plot +# sage.doctest: needs sage.plot """ Surfaces of revolution diff --git a/src/sage/plot/plot_field.py b/src/sage/plot/plot_field.py index 262541b5f81..28d509fe156 100644 --- a/src/sage/plot/plot_field.py +++ b/src/sage/plot/plot_field.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic """ Plotting fields """ diff --git a/src/sage/plot/step.py b/src/sage/plot/step.py index bfd79dffb88..4023686f9bd 100644 --- a/src/sage/plot/step.py +++ b/src/sage/plot/step.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic """ Step function plots """ diff --git a/src/sage/plot/streamline_plot.py b/src/sage/plot/streamline_plot.py index 3960adbe051..663d3aee70b 100644 --- a/src/sage/plot/streamline_plot.py +++ b/src/sage/plot/streamline_plot.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic """ Streamline plots """ From 63dcc788a67a1d87fb1637ccc3e6044e1b8e1053 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 6 Aug 2023 19:09:27 -0700 Subject: [PATCH 16/21] src/sage/plot/graphics.py: Use more block tags --- src/sage/plot/graphics.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/sage/plot/graphics.py b/src/sage/plot/graphics.py index 1cd1e88f8a7..614505f89ac 100644 --- a/src/sage/plot/graphics.py +++ b/src/sage/plot/graphics.py @@ -1890,10 +1890,11 @@ def show(self, **kwds): :: - sage: y = x^5 + 4*x^4 - 10*x^3 - 40*x^2 + 9*x + 36 # needs sage.symbolic - sage: p = plot(y, -4.1, 1.1) # needs sage.symbolic - sage: xlines = lambda a, b: [z for z, m in y.roots()] # needs sage.symbolic - sage: p.show(gridlines=[xlines, [0]], frame=True, axes=False) # needs sage.symbolic + sage: # needs sage.symbolic + sage: y = x^5 + 4*x^4 - 10*x^3 - 40*x^2 + 9*x + 36 + sage: p = plot(y, -4.1, 1.1) + sage: xlines = lambda a, b: [z for z, m in y.roots()] + sage: p.show(gridlines=[xlines, [0]], frame=True, axes=False) Change the style of all the grid lines. @@ -2730,9 +2731,9 @@ def matplotlib(self, filename=None, The patch changes them to float before creating `matplotlib` objects.:: sage: # long time, needs sage.symbolic - sage: f = lambda x, y: abs(cos((x + I * y) ** 4)) - 1 # long time, needs sage.symbolic - sage: g = implicit_plot(f, (-4, 4), (-3, 3), linewidth=0.6) # long time, needs sage.symbolic - sage: gm = g.matplotlib() # long time, needs sage.symbolic + sage: f = lambda x, y: abs(cos((x + I * y) ** 4)) - 1 + sage: g = implicit_plot(f, (-4, 4), (-3, 3), linewidth=0.6) + sage: gm = g.matplotlib() If the axes are flipped, the limits of the axes get swapped:: From abc8d168417efc413ed34ca13230a1a82c845744 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 6 Aug 2023 19:31:48 -0700 Subject: [PATCH 17/21] src/sage/plot/{line,plot}.py: Doctest cosmetics --- src/sage/plot/line.py | 2 +- src/sage/plot/plot.py | 150 ++++++++++++++++++++++++------------------ 2 files changed, 88 insertions(+), 64 deletions(-) diff --git a/src/sage/plot/line.py b/src/sage/plot/line.py index 58d5fd579e0..c945946484a 100644 --- a/src/sage/plot/line.py +++ b/src/sage/plot/line.py @@ -389,7 +389,7 @@ def line2d(points, **options): A line with no points or one point:: - sage: line([]) #returns an empty plot + sage: line([]) # returns an empty plot Graphics object consisting of 0 graphics primitives sage: import numpy; line(numpy.array([])) # needs numpy Graphics object consisting of 0 graphics primitives diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index 0b5e76a5e20..39decf13757 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -420,7 +420,8 @@ def y(x): return x*sin(x**2) sage: g1 = plot(sin(x), 0, 2*pi) sage: g2 = plot(cos(x), 0, 2*pi, linestyle="--") - sage: (g1+g2).show(ticks=pi/6, tick_formatter=pi) # long time # show their sum, nicely formatted + sage: (g1 + g2).show(ticks=pi/6, # show their sum, nicely formatted # long time +....: tick_formatter=pi) .. PLOT:: @@ -1109,7 +1110,7 @@ def plot(funcs, *args, **kwds): :: - sage: p=plot(1, (x,0,3), plot_points=4, randomize=False, adaptive_recursion=0) + sage: p = plot(1, (x,0,3), plot_points=4, randomize=False, adaptive_recursion=0) sage: list(p[0]) [(0.0, 1.0), (1.0, 1.0), (2.0, 1.0), (3.0, 1.0)] @@ -1147,9 +1148,12 @@ def plot(funcs, *args, **kwds): By default, color will change from one primitive to the next. This may be controlled by modifying ``color`` option:: - sage: g1 = plot([x*exp(-n*x^2)/.4 for n in [1..3]], (0, 2), color='blue', aspect_ratio=.8); g1 + sage: g1 = plot([x*exp(-n*x^2)/.4 for n in [1..3]], (0, 2), + ....: color='blue', aspect_ratio=.8); g1 Graphics object consisting of 3 graphics primitives - sage: g2 = plot([x*exp(-n*x^2)/.4 for n in [1..3]], (0, 2), color=['red','red','green'], linestyle=['-','--','-.'], aspect_ratio=.8); g2 + sage: g2 = plot([x*exp(-n*x^2)/.4 for n in [1..3]], (0, 2), + ....: color=['red','red','green'], linestyle=['-','--','-.'], + ....: aspect_ratio=.8); g2 Graphics object consisting of 3 graphics primitives .. PLOT:: @@ -1218,7 +1222,7 @@ def plot(funcs, *args, **kwds): a graph is on both sides of both axes, as the axes only cross if the origin is actually part of the viewing area:: - sage: plot(x^3,(x,0,2)) # this one has the origin + sage: plot(x^3, (x,0,2)) # this one has the origin Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1228,7 +1232,7 @@ def plot(funcs, *args, **kwds): :: - sage: plot(x^3,(x,1,2)) # this one does not + sage: plot(x^3, (x,1,2)) # this one does not Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1240,7 +1244,7 @@ def plot(funcs, *args, **kwds): the labels have quite different orders of magnitude or are very large, scientific notation (the `e` notation for powers of ten) is used:: - sage: plot(x^2,(x,480,500)) # this one has no scientific notation + sage: plot(x^2, (x,480,500)) # this one has no scientific notation Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1250,7 +1254,7 @@ def plot(funcs, *args, **kwds): :: - sage: plot(x^2,(x,300,500)) # this one has scientific notation on y-axis + sage: plot(x^2, (x,300,500)) # this one has scientific notation on y-axis Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1330,7 +1334,7 @@ def plot(funcs, *args, **kwds): If `X` is a list of Sage objects and ``legend_label`` is 'automatic', then Sage will create labels for each function according to their internal representation:: - sage: plot([sin(x), tan(x), 1-x^2], legend_label='automatic') + sage: plot([sin(x), tan(x), 1 - x^2], legend_label='automatic') Graphics object consisting of 3 graphics primitives .. PLOT:: @@ -1373,7 +1377,7 @@ def plot(funcs, *args, **kwds): :: - sage: plot_semilogy(exp, (1, 10)) # same thing + sage: plot_semilogy(exp, (1, 10)) # same thing Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1393,7 +1397,7 @@ def plot(funcs, *args, **kwds): :: - sage: plot(exp, (1, 10), scale='loglog', base=2) # long time # base of log is 2 + sage: plot(exp, (1, 10), scale='loglog', base=2) # base of log is 2 # long time Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1404,15 +1408,16 @@ def plot(funcs, *args, **kwds): We can also change the scale of the axes in the graphics just before displaying:: - sage: G = plot(exp, 1, 10) # long time - sage: G.show(scale=('semilogy', 2)) # long time + sage: G = plot(exp, 1, 10) # long time + sage: G.show(scale=('semilogy', 2)) # long time The algorithm used to insert extra points is actually pretty simple. On the picture drawn by the lines below:: sage: p = plot(x^2, (-0.5, 1.4)) + line([(0,0), (1,1)], color='green') sage: p += line([(0.5, 0.5), (0.5, 0.5^2)], color='purple') - sage: p += point(((0, 0), (0.5, 0.5), (0.5, 0.5^2), (1, 1)), color='red', pointsize=20) + sage: p += point(((0, 0), (0.5, 0.5), (0.5, 0.5^2), (1, 1)), + ....: color='red', pointsize=20) sage: p += text('A', (-0.05, 0.1), color='red') sage: p += text('B', (1.01, 1.1), color='red') sage: p += text('C', (0.48, 0.57), color='red') @@ -1452,8 +1457,8 @@ def plot(funcs, *args, **kwds): :: - sage: def h1(x): return abs(sqrt(x^3 - 1)) - sage: def h2(x): return -abs(sqrt(x^3 - 1)) + sage: def h1(x): return abs(sqrt(x^3 - 1)) + sage: def h2(x): return -abs(sqrt(x^3 - 1)) sage: P = plot([h1, h2], 1,4) sage: P # show the result Graphics object consisting of 2 graphics primitives @@ -1475,14 +1480,16 @@ def h2(x): return -abs(sqrt(x**3 - 1)) As a workaround, we can perform the trick:: - sage: p1 = line([(a,b) for a,b in zip(p[0].xdata,p[0].ydata) if (b>=-1 and b<=1)]) - sage: q1 = line([(a,b) for a,b in zip(q[0].xdata,q[0].ydata) if (b>=0 and b<=4)]) - sage: (p1+q1).show() + sage: p1 = line([(a,b) for a, b in zip(p[0].xdata, p[0].ydata) + ....: if b>=-1 and b<=1]) + sage: q1 = line([(a,b) for a, b in zip(q[0].xdata, q[0].ydata) + ....: if b>=0 and b<=4]) + sage: (p1 + q1).show() We can also directly plot the elliptic curve:: - sage: E = EllipticCurve([0,-1]) - sage: plot(E, (1, 4), color=hue(0.6)) + sage: E = EllipticCurve([0,-1]) # needs sage.schemes + sage: plot(E, (1, 4), color=hue(0.6)) # needs sage.schemes Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1608,8 +1615,10 @@ def h2(x): return -abs(sqrt(x**3 - 1)) sage: p1 = plot(sin(x), -pi, pi, fill='axis') sage: p2 = plot(sin(x), -pi, pi, fill='min', fillalpha=1) sage: p3 = plot(sin(x), -pi, pi, fill='max') - sage: p4 = plot(sin(x), -pi, pi, fill=(1-x)/3, fillcolor='blue', fillalpha=.2) - sage: graphics_array([[p1, p2], [p3, p4]]).show(frame=True, axes=False) # long time + sage: p4 = plot(sin(x), -pi, pi, fill=(1-x)/3, + ....: fillcolor='blue', fillalpha=.2) + sage: graphics_array([[p1, p2], # long time + ....: [p3, p4]]).show(frame=True, axes=False) .. PLOT:: @@ -1623,11 +1632,15 @@ def h2(x): return -abs(sqrt(x**3 - 1)) The basic options for filling a list of plots:: sage: (f1, f2) = x*exp(-1*x^2)/.35, x*exp(-2*x^2)/.35 - sage: p1 = plot([f1, f2], -pi, pi, fill={1: [0]}, fillcolor='blue', fillalpha=.25, color='blue') + sage: p1 = plot([f1, f2], -pi, pi, fill={1: [0]}, + ....: fillcolor='blue', fillalpha=.25, color='blue') sage: p2 = plot([f1, f2], -pi, pi, fill={0: x/3, 1:[0]}, color=['blue']) - sage: p3 = plot([f1, f2], -pi, pi, fill=[0, [0]], fillcolor=['orange','red'], fillalpha=1, color={1: 'blue'}) - sage: p4 = plot([f1, f2], (x,-pi, pi), fill=[x/3, 0], fillcolor=['grey'], color=['red', 'blue']) - sage: graphics_array([[p1, p2], [p3, p4]]).show(frame=True, axes=False) # long time + sage: p3 = plot([f1, f2], -pi, pi, fill=[0, [0]], + ....: fillcolor=['orange','red'], fillalpha=1, color={1: 'blue'}) + sage: p4 = plot([f1, f2], (x,-pi, pi), fill=[x/3, 0], + ....: fillcolor=['grey'], color=['red', 'blue']) + sage: graphics_array([[p1, p2], # long time + ....: [p3, p4]]).show(frame=True, axes=False) .. PLOT:: @@ -1641,7 +1654,8 @@ def h2(x): return -abs(sqrt(x**3 - 1)) A example about the growth of prime numbers:: - sage: plot(1.13*log(x), 1, 100, fill=lambda x: nth_prime(x)/floor(x), fillcolor='red') + sage: plot(1.13*log(x), 1, 100, + ....: fill=lambda x: nth_prime(x)/floor(x), fillcolor='red') Graphics object consisting of 2 graphics primitives .. PLOT:: @@ -1651,7 +1665,7 @@ def h2(x): return -abs(sqrt(x**3 - 1)) Fill the area between a function and its asymptote:: sage: f = (2*x^3+2*x-1)/((x-2)*(x+1)) - sage: plot([f, 2*x+2], -7,7, fill={0: [1]}, fillcolor='#ccc').show(ymin=-20, ymax=20) + sage: plot([f, 2*x+2], -7, 7, fill={0: [1]}, fillcolor='#ccc').show(ymin=-20, ymax=20) .. PLOT:: @@ -1678,16 +1692,18 @@ def b(n): return lambda x: bessel_J(n, x) like ``i:j`` will fill between the ith function and the line y=j:: sage: def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) - sage: plot([b(c) for c in [1..5]], 0, 20, fill={i:[i-1] for i in [1..4]}, color={i:'blue' for i in [1..5]}, aspect_ratio=3, ymax=3) + sage: plot([b(c) for c in [1..5]], 0, 20, fill={i: [i-1] for i in [1..4]}, + ....: color={i: 'blue' for i in [1..5]}, aspect_ratio=3, ymax=3) Graphics object consisting of 9 graphics primitives - sage: plot([b(c) for c in [1..5]], 0, 20, fill={i:i-1 for i in [1..4]}, color='blue', aspect_ratio=3) # long time + sage: plot([b(c) for c in [1..5]], 0, 20, fill={i: i-1 for i in [1..4]}, # long time + ....: color='blue', aspect_ratio=3) Graphics object consisting of 9 graphics primitives .. PLOT:: def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) g1 = plot([b(n) for n in range(1,6)], 0, 20, fill={i:[i-1] for i in range(1,5)}, color={i:'blue' for i in range(1,6)}, aspect_ratio=3) - g2 = plot([b(n) for n in range(1,6)], 0, 20, fill={i:i-1 for i in range(1,5)}, color='blue', aspect_ratio=3) # long time + g2 = plot([b(n) for n in range(1,6)], 0, 20, fill={i:i-1 for i in range(1,5)}, color='blue', aspect_ratio=3) g1.ymax(3) g = graphics_array([[g1], [g2]]) sphinx_plot(g) @@ -1695,39 +1711,42 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) Extra options will get passed on to :meth:`~sage.plot.graphics.Graphics.show`, as long as they are valid:: - sage: plot(sin(x^2), (x, -3, 3), title=r'Plot of $\sin(x^2)$', axes_labels=['$x$','$y$']) # These labels will be nicely typeset + sage: plot(sin(x^2), (x, -3, 3), # These labels will be nicely typeset + ....: title=r'Plot of $\sin(x^2)$', axes_labels=['$x$','$y$']) Graphics object consisting of 1 graphics primitive .. PLOT:: - g = plot(sin(x**2), (x, -3, 3), title=r'Plot of $\sin(x^2)$', axes_labels=['$x$','$y$']) # These labels will be nicely typeset + g = plot(sin(x**2), (x, -3, 3), title=r'Plot of $\sin(x^2)$', axes_labels=['$x$','$y$']) sphinx_plot(g) :: - sage: plot(sin(x^2), (x, -3, 3), title='Plot of sin(x^2)', axes_labels=['x','y']) # These will not + sage: plot(sin(x^2), (x, -3, 3), # These will not + ....: title='Plot of sin(x^2)', axes_labels=['x','y']) Graphics object consisting of 1 graphics primitive .. PLOT:: - g = plot(sin(x**2), (x, -3, 3), title='Plot of sin(x^2)', axes_labels=['x','y']) # These will not + g = plot(sin(x**2), (x, -3, 3), title='Plot of sin(x^2)', axes_labels=['x','y']) sphinx_plot(g) :: - sage: plot(sin(x^2), (x, -3, 3), axes_labels=['x','y'], axes_labels_size=2.5) # Large axes labels (w.r.t. the tick marks) + sage: plot(sin(x^2), (x, -3, 3), # Large axes labels (w.r.t. the tick marks) + ....: axes_labels=['x','y'], axes_labels_size=2.5) Graphics object consisting of 1 graphics primitive .. PLOT:: - g = plot(sin(x**2), (x, -3, 3), axes_labels=['x','y'], axes_labels_size=2.5) # Large axes labels (w.r.t. the tick marks) + g = plot(sin(x**2), (x, -3, 3), axes_labels=['x','y'], axes_labels_size=2.5) sphinx_plot(g) :: sage: plot(sin(x^2), (x, -3, 3), figsize=[8,2]) Graphics object consisting of 1 graphics primitive - sage: plot(sin(x^2), (x, -3, 3)).show(figsize=[8,2]) # These are equivalent + sage: plot(sin(x^2), (x, -3, 3)).show(figsize=[8,2]) # These are equivalent .. PLOT:: @@ -1739,7 +1758,7 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) :: - sage: plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7],[-1/2,0,1/2]]) + sage: plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7], [-1/2,0,1/2]]) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1749,7 +1768,10 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) :: - sage: plot(2*x + 1, (x, 0, 5), ticks=[[0, 1, e, pi, sqrt(20)], [1, 3, 2*e + 1, 2*pi + 1, 2*sqrt(20) + 1]], tick_formatter="latex") + sage: plot(2*x + 1, (x, 0, 5), + ....: ticks=[[0, 1, e, pi, sqrt(20)], + ....: [1, 3, 2*e + 1, 2*pi + 1, 2*sqrt(20) + 1]], + ....: tick_formatter="latex") Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1761,7 +1783,7 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) :: - sage: plot(sin(x),(x,0,2*pi),ticks=pi/3,tick_formatter=pi) + sage: plot(sin(x), (x,0,2*pi), ticks=pi/3, tick_formatter=pi) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1771,7 +1793,8 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) You can even have custom tick labels along with custom positioning. :: - sage: plot(x**2, (x,0,3), ticks=[[1,2.5],[0.5,1,2]], tick_formatter=[["$x_1$","$x_2$"],["$y_1$","$y_2$","$y_3$"]]) + sage: plot(x**2, (x,0,3), ticks=[[1,2.5], [0.5,1,2]], + ....: tick_formatter=[["$x_1$","$x_2$"],["$y_1$","$y_2$","$y_3$"]]) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1783,7 +1806,7 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) option as shown below. This also requires that LaTeX, dvipng and Ghostscript be installed:: - sage: plot(x, typeset='type1') # optional - latex + sage: plot(x, typeset='type1') # optional - latex Graphics object consisting of 1 graphics primitive A example with excluded values:: @@ -1816,8 +1839,8 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) Excluded points can also be given by an equation:: - sage: g(x) = x^2-2*x-2 - sage: plot(1/g(x), (x, -3, 4), exclude=g(x)==0, ymin=-5, ymax=5) # long time + sage: g(x) = x^2 - 2*x - 2 + sage: plot(1/g(x), (x, -3, 4), exclude=g(x)==0, ymin=-5, ymax=5) # long time Graphics object consisting of 3 graphics primitives .. PLOT:: @@ -1829,7 +1852,8 @@ def g(x): return x**2-2*x-2 ``exclude`` and ``detect_poles`` can be used together:: sage: f(x) = (floor(x)+0.5) / (1-(x-0.5)^2) - sage: plot(f, (x, -3.5, 3.5), detect_poles='show', exclude=[-3..3], ymin=-5, ymax=5) + sage: plot(f, (x, -3.5, 3.5), detect_poles='show', exclude=[-3..3], + ....: ymin=-5, ymax=5) Graphics object consisting of 12 graphics primitives .. PLOT:: @@ -1849,7 +1873,7 @@ def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2) .. PLOT:: set_verbose(-1) - g = plot(arcsec, (x, -2, 2)) # [-1, 1] is excluded automatically + g = plot(arcsec, (x, -2, 2)) sphinx_plot(g) :: @@ -1860,7 +1884,7 @@ def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2) .. PLOT:: set_verbose(-1) - g = plot(arcsec, (x, -2, 2), exclude=[1.5]) # x=1.5 is also excluded + g = plot(arcsec, (x, -2, 2), exclude=[1.5]) sphinx_plot(g) :: @@ -1873,7 +1897,7 @@ def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2) .. PLOT:: set_verbose(-1) - g = plot(sqrt(x**2-1), -2, 2) # [-1, 1] is excluded automatically + g = plot(sqrt(x**2-1), -2, 2) sphinx_plot(g) :: @@ -1885,7 +1909,7 @@ def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2) .. PLOT:: set_verbose(-1) - g = plot(arccsc, -2, 2) # [-1, 1] is excluded automatically + g = plot(arccsc, -2, 2) sphinx_plot(g) TESTS: @@ -3153,12 +3177,12 @@ def plot_loglog(funcs, *args, **kwds): :: - sage: plot_loglog(exp, (1,10), base=2.1) # long time # with base 2.1 on both axes + sage: plot_loglog(exp, (1,10), base=2.1) # with base 2.1 on both axes # long time Graphics object consisting of 1 graphics primitive .. PLOT:: - g = plot_loglog(exp, (1,10), base=2.1) # long time # with base 2.1 on both axes + g = plot_loglog(exp, (1,10), base=2.1) sphinx_plot(g) :: @@ -3191,12 +3215,12 @@ def plot_semilogx(funcs, *args, **kwds): EXAMPLES:: - sage: plot_semilogx(exp, (1,10)) # long time # plot in semilogx scale, base 10 + sage: plot_semilogx(exp, (1,10)) # plot in semilogx scale, base 10 # long time Graphics object consisting of 1 graphics primitive .. PLOT:: - g = plot_semilogx(exp, (1,10)) # long time # plot in semilogx scale, base 10 + g = plot_semilogx(exp, (1,10)) sphinx_plot(g) :: @@ -3206,7 +3230,7 @@ def plot_semilogx(funcs, *args, **kwds): .. PLOT:: - g = plot_semilogx(exp, (1,10), base=2) # with base 2 + g = plot_semilogx(exp, (1,10), base=2) sphinx_plot(g) :: @@ -3282,19 +3306,19 @@ def list_plot_loglog(data, plotjoined=False, **kwds): EXAMPLES:: sage: yl = [5**k for k in range(10)]; xl = [2**k for k in range(10)] - sage: list_plot_loglog(list(zip(xl, yl))) # long time # use loglog scale with base 10 + sage: list_plot_loglog(list(zip(xl, yl))) # use loglog scale with base 10 # long time Graphics object consisting of 1 graphics primitive .. PLOT:: yl = [5**k for k in range(10)] xl = [2**k for k in range(10)] - g = list_plot_loglog(list(zip(xl, yl))) # long time # plot in loglog scale with base 10 + g = list_plot_loglog(list(zip(xl, yl))) sphinx_plot(g) :: - sage: list_plot_loglog(list(zip(xl, yl)), # long time # with base 2.1 on both axes + sage: list_plot_loglog(list(zip(xl, yl)), # with base 2.1 on both axes # long time ....: base=2.1) Graphics object consisting of 1 graphics primitive @@ -3302,12 +3326,12 @@ def list_plot_loglog(data, plotjoined=False, **kwds): yl = [5**k for k in range(10)] xl = [2**k for k in range(10)] - g = list_plot_loglog(list(zip(xl, yl)), base=2.1) # long time # with base 2.1 on both axes + g = list_plot_loglog(list(zip(xl, yl)), base=2.1) sphinx_plot(g) :: - sage: list_plot_loglog(list(zip(xl, yl)), base=(2,5)) # long time + sage: list_plot_loglog(list(zip(xl, yl)), base=(2,5)) # long time Graphics object consisting of 1 graphics primitive .. warning:: @@ -3380,7 +3404,7 @@ def list_plot_semilogx(data, plotjoined=False, **kwds): .. PLOT:: - g = list_plot_semilogx([(1,2),(3,4),(3,-1),(25,3)], base=2) # with base 2 + g = list_plot_semilogx([(1,2),(3,4),(3,-1),(25,3)], base=2) sphinx_plot(g) """ @@ -3438,7 +3462,7 @@ def list_plot_semilogy(data, plotjoined=False, **kwds): .. PLOT:: - g = list_plot_semilogy([2, 4, 6, 8, 16, 31], base=2) # with base 2 + g = list_plot_semilogy([2, 4, 6, 8, 16, 31], base=2) sphinx_plot(g) """ From 73a5b5142d560c60cc4b5799eb374ae96767067b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 6 Aug 2023 19:37:43 -0700 Subject: [PATCH 18/21] src/sage/plot/plot3d/shapes.pyx: Use block tag --- src/sage/plot/plot3d/shapes.pyx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sage/plot/plot3d/shapes.pyx b/src/sage/plot/plot3d/shapes.pyx index ce8083c41c6..9c820deda2b 100644 --- a/src/sage/plot/plot3d/shapes.pyx +++ b/src/sage/plot/plot3d/shapes.pyx @@ -412,12 +412,13 @@ cdef class Cylinder(ParametricSurface): Some gears:: + sage: # needs sage.symbolic sage: G = Cylinder(1, .5) + Cylinder(.25, 3).translate(0, 0, -3) - sage: G += sum(Cylinder(.2, 1).translate(cos(2*pi*n/9), sin(2*pi*n/9), 0) # needs sage.symbolic + sage: G += sum(Cylinder(.2, 1).translate(cos(2*pi*n/9), sin(2*pi*n/9), 0) ....: for n in [1..9]) - sage: G += G.translate(2.3, 0, -.5) # needs sage.symbolic - sage: G += G.translate(3.5, 2, -1) # needs sage.symbolic - sage: G.show(aspect_ratio=1, frame=False) # needs sage.symbolic + sage: G += G.translate(2.3, 0, -.5) + sage: G += G.translate(3.5, 2, -1) + sage: G.show(aspect_ratio=1, frame=False) .. PLOT:: From b5c1e8a996c4b6cd09189ae318f3c07e211691ba Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 6 Aug 2023 19:39:37 -0700 Subject: [PATCH 19/21] src/sage/plot/animate.py: Reformat --- src/sage/plot/animate.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sage/plot/animate.py b/src/sage/plot/animate.py index c5e22e7fb5b..49f2ecd87d5 100644 --- a/src/sage/plot/animate.py +++ b/src/sage/plot/animate.py @@ -453,8 +453,7 @@ def make_image(self, frame, filename, **kwds): ....: floor(G.ymin()), ceil(G.ymax())) ....: G.save_image(filename, **kwds) - sage: B = MyAnimation([graphs.CompleteGraph(n) - ....: for n in range(7,11)], figsize=5) + sage: B = MyAnimation([graphs.CompleteGraph(n) for n in range(7,11)], figsize=5) sage: d = B.png() sage: v = os.listdir(d); v.sort(); v ['00000000.png', '00000001.png', '00000002.png', '00000003.png'] From e5b62efa85414e90981828dbd4e7059eb3ee3ffe Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 7 Aug 2023 09:36:35 -0700 Subject: [PATCH 20/21] src/sage/plot/plot.py: Fix up docstring markup --- src/sage/plot/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index 39decf13757..69e78f16ab4 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -421,7 +421,7 @@ def y(x): return x*sin(x**2) sage: g1 = plot(sin(x), 0, 2*pi) sage: g2 = plot(cos(x), 0, 2*pi, linestyle="--") sage: (g1 + g2).show(ticks=pi/6, # show their sum, nicely formatted # long time -....: tick_formatter=pi) + ....: tick_formatter=pi) .. PLOT:: From e18852ade629f14e6ec69676223417dd87a46c3e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 7 Aug 2023 11:58:44 -0700 Subject: [PATCH 21/21] src/sage/plot/plot3d/list_plot3d.py: Fix doc markup --- src/sage/plot/plot3d/list_plot3d.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sage/plot/plot3d/list_plot3d.py b/src/sage/plot/plot3d/list_plot3d.py index 6a589b8b381..b8e4ddffce6 100644 --- a/src/sage/plot/plot3d/list_plot3d.py +++ b/src/sage/plot/plot3d/list_plot3d.py @@ -530,8 +530,7 @@ def list_plot3d_tuples(v, interpolation_type, **kwds): .. PLOT:: - sphinx_plot(list_plot3d([[1, 1, 1], [1, 2, 1], [0, 1, 3], [1, 0, 4]], - ....: point_list=True)) + sphinx_plot(list_plot3d([[1, 1, 1], [1, 2, 1], [0, 1, 3], [1, 0, 4]], point_list=True)) ::