-
-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #32993: add pictures to line.py documentation
The examples lacked their plot counterpart URL: https://trac.sagemath.org/32993 Reported by: jhonrubia6 Ticket author(s): Javier Honrubia González Reviewer(s): Kwankyu Lee
- Loading branch information
Showing
1 changed file
with
126 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
Line Plots | ||
""" | ||
|
||
#***************************************************************************** | ||
# ***************************************************************************** | ||
# Copyright (C) 2006 Alex Clemesha <[email protected]>, | ||
# William Stein <[email protected]>, | ||
# 2008 Mike Hansen <[email protected]>, | ||
|
@@ -17,11 +17,12 @@ | |
# The full text of the GPL is available at: | ||
# | ||
# http://www.gnu.org/licenses/ | ||
#***************************************************************************** | ||
# ***************************************************************************** | ||
from sage.plot.primitive import GraphicPrimitive_xydata | ||
from sage.misc.decorators import options, rename_keyword | ||
from sage.plot.colors import to_mpl_color | ||
|
||
|
||
class Line(GraphicPrimitive_xydata): | ||
""" | ||
Primitive class that initializes the line graphics type. | ||
|
@@ -73,19 +74,19 @@ def _allowed_options(self): | |
('thickness', 'How thick the line is.'), | ||
('zorder', 'The layer level in which to draw')] | ||
""" | ||
return {'alpha':'How transparent the line is.', | ||
'legend_color':'The color of the legend text.', | ||
'legend_label':'The label for this item in the legend.', | ||
'thickness':'How thick the line is.', | ||
'rgbcolor':'The color as an RGB tuple.', | ||
'hue':'The color given as a hue.', | ||
'linestyle':"The style of the line, which is one of '--' (dashed), '-.' (dash dot), '-' (solid), 'steps', ':' (dotted).", | ||
'marker':"the marker symbol (see documentation for line2d for details)", | ||
'markersize':'the size of the marker in points', | ||
'markeredgecolor':'the color of the marker edge', | ||
'markeredgewidth':'the size of the marker edge in points', | ||
'markerfacecolor':'the color of the marker face', | ||
'zorder':'The layer level in which to draw' | ||
return {'alpha': 'How transparent the line is.', | ||
'legend_color': 'The color of the legend text.', | ||
'legend_label': 'The label for this item in the legend.', | ||
'thickness': 'How thick the line is.', | ||
'rgbcolor': 'The color as an RGB tuple.', | ||
'hue': 'The color given as a hue.', | ||
'linestyle': "The style of the line, which is one of '--' (dashed), '-.' (dash dot), '-' (solid), 'steps', ':' (dotted).", | ||
'marker': "the marker symbol (see documentation for line2d for details)", | ||
'markersize': 'the size of the marker in points', | ||
'markeredgecolor': 'the color of the marker edge', | ||
'markeredgewidth': 'the size of the marker edge in points', | ||
'markerfacecolor': 'the color of the marker face', | ||
'zorder': 'The layer level in which to draw' | ||
} | ||
|
||
def _plot3d_options(self, options=None): | ||
|
@@ -118,7 +119,7 @@ def _plot3d_options(self, options=None): | |
del options['zorder'] | ||
if 'linestyle' in options: | ||
if options['linestyle'] not in ('-', 'solid'): | ||
raise NotImplementedError("Invalid 3d line style: '%s'"% | ||
raise NotImplementedError("Invalid 3d line style: '%s'" % | ||
(options['linestyle'])) | ||
del options['linestyle'] | ||
options_3d.update(GraphicPrimitive_xydata._plot3d_options(self, options)) | ||
|
@@ -134,6 +135,13 @@ def plot3d(self, z=0, **kwds): | |
sage: F = EllipticCurve('37a').plot(thickness=5).plot3d(z=2) | ||
sage: E + F # long time (5s on sage.math, 2012) | ||
Graphics3d Object | ||
.. PLOT:: | ||
E = EllipticCurve('37a').plot(thickness=5).plot3d() | ||
F = EllipticCurve('37a').plot(thickness=5).plot3d(z=2) | ||
sphinx_plot(E+F) | ||
""" | ||
from sage.plot.plot3d.shapes2 import line3d | ||
options = self._plot3d_options() | ||
|
@@ -150,7 +158,7 @@ def _repr_(self): | |
sage: Line([-1,2,3,3], [17,4,0,2], {})._repr_() | ||
'Line defined by 4 points' | ||
""" | ||
return "Line defined by %s points"%len(self) | ||
return "Line defined by %s points" % len(self) | ||
|
||
def __getitem__(self, i): | ||
""" | ||
|
@@ -265,6 +273,7 @@ def _render_on_subplot(self, subplot): | |
return_type='short')) | ||
subplot.add_line(p) | ||
|
||
|
||
def line(points, **kwds): | ||
""" | ||
Returns either a 2-dimensional or 3-dimensional line depending | ||
|
@@ -283,10 +292,20 @@ def line(points, **kwds): | |
sage: line([(0,0), (1,1)]) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
E = line([(0,0), (1,1)]) | ||
sphinx_plot(E) | ||
:: | ||
sage: line([(0,0,1), (1,1,1)]) | ||
Graphics3d Object | ||
.. PLOT:: | ||
E = line([(0,0,1), (1,1,1)]) | ||
sphinx_plot(E) | ||
""" | ||
try: | ||
return line2d(points, **kwds) | ||
|
@@ -296,8 +315,8 @@ def line(points, **kwds): | |
|
||
|
||
@rename_keyword(color='rgbcolor') | ||
@options(alpha=1, rgbcolor=(0,0,1), thickness=1, legend_label=None, | ||
legend_color=None, aspect_ratio ='automatic') | ||
@options(alpha=1, rgbcolor=(0, 0, 1), thickness=1, legend_label=None, | ||
legend_color=None, aspect_ratio='automatic') | ||
def line2d(points, **options): | ||
r""" | ||
Create the line through the given list of points. | ||
|
@@ -387,13 +406,23 @@ def line2d(points, **options): | |
sage: line([(0,0),(1,1)], legend_label='line') | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
sphinx_plot(line([(0,0),(1,1)], legend_label='line')) | ||
Lines with different colors in the legend text:: | ||
sage: p1 = line([(0,0),(1,1)], legend_label='line') | ||
sage: p2 = line([(1,1),(2,4)], legend_label='squared', legend_color='red') | ||
sage: p1 + p2 | ||
Graphics object consisting of 2 graphics primitives | ||
.. PLOT:: | ||
p1 = line([(0,0),(1,1)], legend_label='line') | ||
p2 = line([(1,1),(2,4)], legend_label='squared', legend_color='red') | ||
sphinx_plot(p1 + p2) | ||
Extra options will get passed on to show(), as long as they are valid:: | ||
sage: line([(0,1), (3,4)], figsize=[10, 2]) | ||
|
@@ -405,6 +434,10 @@ def line2d(points, **options): | |
sage: line([(1,2),(2,4),(3,4),(4,8),(4.5,32)],scale='loglog',base=2) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
sphinx_plot(line([(1,2),(2,4),(3,4),(4,8),(4.5,32)],scale='loglog',base=2)) | ||
Many more examples below! | ||
A blue conchoid of Nicomedes:: | ||
|
@@ -413,38 +446,73 @@ def line2d(points, **options): | |
sage: line(L, rgbcolor=(1/4,1/8,3/4)) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
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)] | ||
sphinx_plot(line(L, rgbcolor=(1/4,1/8,3/4))) | ||
A line with 2 complex points:: | ||
sage: i = CC.0 | ||
sage: i = CC(0,1) | ||
sage: line([1+i, 2+3*i]) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
i = CC(0,1) | ||
o = line([1+i, 2+3*i]) | ||
sphinx_plot(o) | ||
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: line(L, rgbcolor=(1/4,1/4,3/4)) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
n = 4 | ||
h = 3 | ||
b = 2 | ||
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)] | ||
o = line(L, rgbcolor=(1/4,1/4,3/4)) | ||
sphinx_plot(o) | ||
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: line(L, rgbcolor=(1/4,1/4,3/4)) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
L = [[sin(pi*i/100)+sin(pi*i/50),-(1+cos(pi*i/100)+cos(pi*i/50))] for i in range(-100,101)] | ||
sphinx_plot(line(L, rgbcolor=(1,1/4,1/2))) | ||
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: line(L, rgbcolor=(1,1/4,1/2)) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
L = [[sin(pi*i/100)+sin(pi*i/50),-(1+cos(pi*i/100)+cos(pi*i/50))] for i in range(-100,101)] | ||
sphinx_plot(line(L, rgbcolor=(1,1/4,1/2))) | ||
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: line(L, rgbcolor=(1/4,1,1/8)) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
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)] | ||
sphinx_plot(line(L, rgbcolor=(1/4,1,1/8))) | ||
A green lemniscate of Bernoulli:: | ||
sage: cosines = [cos(-pi/2+pi*i/100) for i in range(201)] | ||
|
@@ -453,19 +521,35 @@ def line2d(points, **options): | |
sage: line(L, rgbcolor=(1/4,3/4,1/8)) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
cosines = [cos(-pi/2+pi*i/100) for i in range(201)] | ||
v = [(1/c, tan(-pi/2+pi*i/100)) for i,c in enumerate(cosines) if c != 0] | ||
L = [(a/(a**2+b**2), b/(a**2+b**2)) for a,b in v] | ||
sphinx_plot(line(L, rgbcolor=(1/4,3/4,1/8))) | ||
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: line(L, rgbcolor=(3/4, 1/4, 1/8)) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
L = [(i/100.0, real_part(jacobi('sn', i/100.0, 2.0))) for i in range(-300, 300, 30)] | ||
sphinx_plot(line(L, rgbcolor=(3/4, 1/4, 1/8))) | ||
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)) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
L = [(i/10.0, bessel_J(2,i/10.0)) for i in range(100)] | ||
sphinx_plot(line(L, rgbcolor=(3/4,1/4,5/8))) | ||
A purple plot of the Riemann zeta function `\zeta(1/2 + it)`, `0 < t < 30`:: | ||
|
@@ -475,6 +559,13 @@ def line2d(points, **options): | |
sage: line(L, rgbcolor=(3/4,1/2,5/8)) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT:: | ||
i = CDF.gen() | ||
v = [zeta(0.5 + n/10 * i) for n in range(300)] | ||
L = [(z.real(), z.imag()) for z in v] | ||
sphinx_plot(line(L, rgbcolor=(3/4,1/2,5/8))) | ||
A purple plot of the Hasse-Weil `L`-function `L(E, 1 + it)`, `-1 < t < 10`:: | ||
sage: E = EllipticCurve('37a') | ||
|
@@ -483,6 +574,13 @@ def line2d(points, **options): | |
sage: line(L, rgbcolor=(3/4,1/2,5/8)) | ||
Graphics object consisting of 1 graphics primitive | ||
.. PLOT :: | ||
E = EllipticCurve('37a') | ||
vals = E.lseries().values_along_line(1-I, 1+10*I, 100) # critical line | ||
L = [(z[1].real(), z[1].imag()) for z in vals] | ||
sphinx_plot(line(L, rgbcolor=(3/4,1/2,5/8))) | ||
A red, blue, and green "cool cat":: | ||
sage: G = plot(-cos(x), -2, 2, thickness=5, rgbcolor=(0.5,1,0.5)) | ||
|
@@ -491,6 +589,13 @@ def line2d(points, **options): | |
sage: G + P + Q # show the plot | ||
Graphics object consisting of 3 graphics primitives | ||
.. PLOT:: | ||
G = plot(-cos(x), -2, 2, thickness=5, rgbcolor=(0.5,1,0.5)) | ||
P = polygon([[1,2], [5,6], [5,0]], rgbcolor=(1,0,0)) | ||
Q = polygon([(-x,y) for x,y in P[0]], rgbcolor=(0,0,1)) | ||
sphinx_plot(G + P + Q) | ||
TESTS: | ||
Check that :trac:`13690` is fixed. The legend label should have circles | ||
|
@@ -501,7 +606,7 @@ def line2d(points, **options): | |
""" | ||
from sage.plot.all import Graphics | ||
from sage.plot.plot import xydata_from_point_list | ||
points = list(points) # make sure points is a python list | ||
points = list(points) # make sure points is a python list | ||
if not points: | ||
return Graphics() | ||
xdata, ydata = xydata_from_point_list(points) | ||
|