Plotting and automatic multiple colors

387 views
Skip to first unread message

Amit Saha

unread,
Sep 28, 2013, 10:14:36 PM9/28/13
to sy...@googlegroups.com
Hi,

I am trying to find a way to do something which is usually the default
behavior in matplotlib. That is, when I show() multiple plots in a
single figure, they are shown in different colors automatically. For
example:

>>> import matplotlib.pyplot as plt
>>> plt.plot([1,2,3])
[<matplotlib.lines.Line2D object at 0x7f48e6c7a710>]
>>> plt.plot([4,5,6])
[<matplotlib.lines.Line2D object at 0x7f48e714e9d0>]
>>> plt.show()

This will show me the two lines in different colors.

On the other hand, in SymPy:

>>> plt = plot(sin(x), cos(x), show=False)
>>> plt.show()

will show both the plots in the same color. I believe it has to do
with creating a single plot object, whereas in the above, two plot
objects were created.

I started to poke around a bit, and thought the append() method in
pyplotting/plot.py may help me, but I got a Traceback, which looks
like a genuine bug to me:

Traceback (most recent call last):
File "<pyshell#120>", line 1, in <module>
plt.append(plt2)
File "/usr/lib/python3.3/site-packages/sympy/plotting/plot.py", line
210, in append
self._series.append(BaseSeries(*args))
NameError: global name 'Series' is not defined

This is what I attempted:

>>> plt = plot(sin(x), show=False)
>>> plt2 = plot(cos(x), show=False)
>>> plt.append(plt2)


Would this be the way to go about this and is this a bug? Is there a
way to achieve what I want easily without much sweat?

Thanks for any input.

Best,
Amit.

--
http://echorand.me

Amit Saha

unread,
Sep 28, 2013, 10:19:52 PM9/28/13
to sy...@googlegroups.com
Hmm, sorry this is actually 'Series'. The above is a result of poking
around without having an idea :)


--
http://echorand.me

Amit Saha

unread,
Oct 1, 2013, 12:57:29 PM10/1/13
to sy...@googlegroups.com
On Sun, Sep 29, 2013 at 12:14 PM, Amit Saha <amits...@gmail.com> wrote:
> Hi,
>
> I am trying to find a way to do something which is usually the default
> behavior in matplotlib. That is, when I show() multiple plots in a
> single figure, they are shown in different colors automatically. For
> example:
>
>>>> import matplotlib.pyplot as plt
>>>> plt.plot([1,2,3])
> [<matplotlib.lines.Line2D object at 0x7f48e6c7a710>]
>>>> plt.plot([4,5,6])
> [<matplotlib.lines.Line2D object at 0x7f48e714e9d0>]
>>>> plt.show()
>
> This will show me the two lines in different colors.
>
> On the other hand, in SymPy:
>
>>>> plt = plot(sin(x), cos(x), show=False)
>>>> plt.show()
>
> will show both the plots in the same color. I believe it has to do
> with creating a single plot object, whereas in the above, two plot
> objects were created.
>
> I started to poke around a bit, and thought the append() method in
> pyplotting/plot.py may help me, but I got a Traceback, which looks
> like a genuine bug to me:


I filed an issue for this [1]. I tried poking around a bit, but it
doesn't look like adding the second plot to the same figure is going
to help. So, here is my call for help once again:

>>>> plt = plot(sin(x), cos(x), show=False)
>>>> plt.show()

By default, SymPy will show both these plots in the same color. Is it
possible with the current public interface to have random different
colors assigned like it is done in matplotlib?

If there is not a public API for this to be done right now, I think it
would be good to make it possible. I can file a feature request.

Thanks for any pointers.


[1] https://code.google.com/p/sympy/issues/detail?id=4041
Reply all
Reply to author
Forward
0 new messages