Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168726
Image: ubuntu2004
1+1
2
float(pi)
3.1415926535897931
list_plot?

File: /usr/local/sage2/local/lib/python2.6/site-packages/sage/plot/plot.py

Type: <type ‘function’>

Definition: list_plot(data, plotjoined=False, **kwargs)

Docstring:

list_plot takes either a single list of data, a list of tuples, or a dictionary and plots the corresponding points.

If given a single list of data, list_plot forms a list of tuples (i,di) where i goes from 0 to { len}(data)-1 and di is the i^{th} data value, and puts points at those tuple values.

list_plot also takes a list of tuples (dxi, dyi) where dxi is the i^{th} data representing the x-value, and dyi is the i^{th} y-value. If plotjoined=True , then a line spanning all the data is drawn instead.

If given a dictionary, list_plot interprets the keys as x-values and the values as y-values.

EXAMPLES:

sage: list_plot([i^2 for i in range(5)])

Here are a bunch of random red points:

sage: r = [(random(),random()) for _ in range(20)]
sage: list_plot(r,color='red')

This gives all the random points joined in a purple line:

sage: list_plot(r, plotjoined=True, color='purple')

If you have separate lists of x values and y values which you want to plot against each other, use the zip command to make a single list whose entries are pairs of (x,y) values, and feed the result into list_plot:

sage: x_coords = [cos(t)^3 for t in srange(0, 2*pi, 0.02)]
sage: y_coords = [sin(t)^3 for t in srange(0, 2*pi, 0.02)]
sage: list_plot(zip(x_coords, y_coords))

If instead you try to pass the two lists as separate arguments, you will get an error message:

sage: list_plot(x_coords, y_coords)
...
TypeError: The second argument 'plotjoined' should be boolean (True or False).  If you meant to plot two lists 'x' and 'y' against each other, use 'list_plot(zip(x,y))'.

Dictionaries with numeric keys and values can be plotted:

sage: list_plot({22: 3365, 27: 3295, 37: 3135, 42: 3020, 47: 2880, 52: 2735, 57: 2550})

TESTS:

We check to see that the x/y min/max data are set correctly.

sage: d = list_plot([(100,100), (120, 120)]).get_minmax_data()
sage: d['xmin']
100.0
sage: d['ymin']
100.0
p1=list_plot([1,2,3],rgbcolor='red',pointsize=25)
p2=list_plot([1,2,3],rgbcolor='grey',plotjoined=true)
(p1+p2).show()
x_coords = [cos(t)^3 for t in srange(0, 2*pi, 0.02)] y_coords = [sin(t)^3 for t in srange(0, 2*pi, 0.02)] list_plot(zip(x_coords, y_coords),rgbcolor='red',plotjoined=true)
2 + 2
4
factor(832009715346)
2 * 3 * 1223 * 1231 * 92107
A = matrix(4,4, range(16)); A
[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11] [12 13 14 15]
factor(A.charpoly())
x^2 * (x^2 - 30*x - 80)
m = matrix(ZZ,2, range(4)); m
[0 1] [2 3]
m[0,0] = m[0,0] - 3
m
[-3 1] [ 2 3]
E = EllipticCurve([1,2,3,4,5]); E
Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over Rational Field
E.anlist(10)
[0, 1, 1, 0, -1, -3, 0, -1, -3, -3, -3]
E.rank()
1
k = 1/(sqrt(3)*I + 3/4 + sqrt(73)*5/9); k
1/(I*sqrt(3) + 5/9*sqrt(73) + 3/4)
N(k)
0.165495678130644 - 0.0521492082074256*I
N(k,20)
0.16550 - 0.052149*I
latex(k)
\frac{1}{i \, \sqrt{3} + \frac{5}{9} \, \sqrt{73} + \frac{3}{4}}
var('x')
x
f=x^2+3
f
x^2 + 3
f.integrate(x)
1/3*x^3 + 3*x
f.diff(x)
2*x
solve(f,x)
[x == -I*sqrt(3), x == I*sqrt(3)]