Issues with adding color to plots.

14 views
Skip to first unread message

Eric Kangas

unread,
Jun 30, 2012, 6:41:59 PM6/30/12
to sage-s...@googlegroups.com
Hi,

I am having issues with adding color to plots.

Code:

a = [i/pi for i in range(79)]

p1 = plot([circle((-sin(i),cos(i)),1, edgecolor = colors[i]) for i in a])

p2 = plot([circle((sin(i),-cos(i)),1, edgecolor = colors[i]) for i in a])

p3 = p1 + p2

show(p3, aspect_ratio = 1, axes = False)


error:

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)

/home/nooniensoong97/<ipython console> in <module>()

/home/nooniensoong97/programs/sage-4.7.2-linux-32bit-ubuntu_10.04_lts-i686-Linux/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.__index__ (sage/symbolic/expression.cpp:17306)()

/home/nooniensoong97/programs/sage-4.7.2-linux-32bit-ubuntu_10.04_lts-i686-Linux/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression._integer_ (sage/symbolic/expression.cpp:4400)()

TypeError: unable to convert x (=1/pi) to an integer


Eric Kangas

unread,
Jun 30, 2012, 6:43:40 PM6/30/12
to sage-s...@googlegroups.com


a = [i/pi for i in range(79)]

colors = rainbow(len(a))

kcrisman

unread,
Jun 30, 2012, 11:05:55 PM6/30/12
to sage-s...@googlegroups.com
What you wanted was very beautiful, I like it very much.

a = [j/pi for j in range(79)]
colors = rainbow(len(a))
p1 = plot([circle((-sin(a[i]),cos(a[i])),1, edgecolor = colors[i]) for i in range(len(a))])
p2 = plot([circle((sin(a[i]),-cos(a[i])),1, edgecolor = colors[i]) for i in range(len(a))])
p3 = p1 + p2
show(p3, aspect_ratio = 1, axes = False)

Note how this version doesn't give a possible problem with two different "i"s, and doesn't attempt to use the elements of the list as indices for the list.  There are some really good Python tutorials out there which will help get used to these subtleties - I like http://www.greenteapress.com/thinkpython/ though others will have their favorites.

Good luck!

- kcrisman

Eric Kangas

unread,
Jul 1, 2012, 10:54:46 AM7/1/12
to sage-s...@googlegroups.com
Thanks,

I see I had it correct just needed to do some tweaking on a few of the lines.
Reply all
Reply to author
Forward
0 new messages