## Passing a list to plot in Sage(math)

January 31, 2010 by doxdrum

Looking on published worksheets, I found a simple code for 4th order Runge-Kutta applied to 1st order ODE here.

I took the same code and increce the number of interactions (from 2 to 100) and the array soln now was a list of (100 x 2) data. Of course a plot is much more useful than a really long list, so the easiest way of plotting the data is adding a new line to the code,

list_plot(soln)

This command plots the data in the 1st column vs. data of the 2nd column. Additionally, If you want to save the plot (instead of showing it) use the filename option,

list_plot(soln, filename='/path/to/directory/name-of-plot.jpg')

remember that the extension could be also PDF, PNG, EPS, among others.

Thanks to **omologos** in the sage-dev channel of IRC

Another rather interesting way of plotting arrays was pointed out to me by **mvngu** in the following code,

sage: L1 = [randint(1, 10) for i in xrange(2)]
sage: L2 = [randint(1, 10) for i in xrange(2)]
sage: L3 = [randint(1, 10) for i in xrange(2)]
sage: L4 = [randint(1, 10) for i in xrange(2)]
sage: L5 = [randint(1, 10) for i in xrange(2)]
sage: M = matrix([L1, L2, L3, L4, L5]); M
[ 1 2]
[ 1 3]
[10 6]
[ 3 8]
[ 6 1]
sage: line2d(zip(M.column(0), M.column(1)), thickness=1)

The last line does the work done

For another example see the notebook by **rsael** at sagenb.

### Like this:

Like Loading...

*Related*

Posted in Linux, Mathematics, Physics, Science | Tagged Array, Calculation, CLI, Command, Free, Functions, Graphics, How to, HowTo, IRC, Karmic, Koala, Linux, List, Maple, Mathematica, Mathematics, Matlab, Passing, Plot, Plotting, Programming, Pyhton, Sage, Sage-dev, Sagemath, Symbolic, Tips and Tricks, Ubuntu | 2 Comments

on February 1, 2010 at 1:54 am |Passing a list to plot in Sage(math) »Coolweather[…] ========================= We are not claiming to be the original source of this post, some links might be automatically be removed, so see the original story at: howto « WordPress.com Tag Feed […]

on February 1, 2010 at 8:54 am |doxdrumHello. I’m glad you like the posts I’m doing, but it isn’t nice (nor polite) to copy them. I rather suggest to link’em or make you’re own shorter version. At least you could comment the source first!

Thx.