pie colors

Hello list!

I have a question regarding the colors of the pie diagram of matplotlib. When no colors are assigned then the pie function automatically selects some colors, like the example image I have attached. But in this case the black color covers the text. How can we avoid this?Is there an easy (perhaps?) way to exclude a color?

Of course there is not problem if I specifically select the colors but I do not know how many parts exist beforehand (and I would like to assign it automatically).

Thanks!

Regards

Grigoris

image.png

Hello list!

I have a question regarding the colors of the pie diagram of matplotlib. When no colors are assigned then the pie function automatically selects some colors, like the example image I have attached. But in this case the black color covers the text. How can we avoid this?Is there an easy (perhaps?) way to exclude a color?

I don’t really use pie charts, but I think it just uses the default color cycle. This can be altered by changing the rcParams:

import matplotlib.pyplot as plt
plt.rcParams[‘axes.color_cycle’].remove(‘k’)

The color_cycle parameter is just a python list, so I use list.remove to remove black (which is the letter ‘k’ since ‘b’ is blue). There are other ways of setting rcParams, as detailed in the help files (Note that rc and rcParams is in both matplotlib.pyplot and the main matplotlib package).

Best,
-Tony

···

On Wed, Nov 30, 2011 at 10:34 AM, Grigoris Maravelias <gr.maravelias@…287…> wrote:

Well I did tried this but it didn’t work out. It actually removes
the black color from the color_cycle but the pie still prints it.
Moreover I noticed that this color_cycle has 7 colors that repeats
after the first 7 so it won’t do what I want. I will need to find
another way to set the colors or just avoid the pie.

Thanks though for the help!

Regards

Grigoris
···

On 11/30/2011 06:09 PM, Tony Yu wrote:

    On Wed, Nov 30, 2011 at 10:34 AM, > Grigoris Maravelias <gr.maravelias@...287...> >         wrote:

Hello list!

      I have a question regarding the colors of the pie diagram of

matplotlib. When no colors are assigned then the pie function
automatically selects some colors, like the example image I
have attached. But in this case the black color covers the
text. How can we avoid this?Is there an easy (perhaps?) way to
exclude a color?

      I don't really use pie charts, but I think it just uses the

default color cycle. This can be altered by changing the
rcParams:

      >>> import matplotlib.pyplot as plt

      >>> plt.rcParams['axes.color_cycle'].remove('k')



      The color_cycle parameter is just a python list, so I use

list.remove to remove black (which is the letter ‘k’ since ‘b’
is blue). There are other ways of setting rcParams, as
detailed in the help
files
(Note that rc and rcParams is in both
matplotlib.pyplot and the main matplotlib package).

      Best,

      -Tony
Well I did tried this but it didn't work out. It actually removes

the black color from the color_cycle but the pie still prints it.
Moreover I noticed that this color_cycle has 7 colors that repeats
after the first 7 so it won’t do what I want. I will need to find
another way to set the colors or just avoid the pie.

I guess I should atleast read the docstring for plt.pie before giving you advice on how to use it. It looks like the default colors are hard coded into the function (instead of using the color_cycle parameter).

The quickest way to create different colors is to pick them out from a colormap. For example, the following gives decent results:

colors = plt.cm.Set1(np.linspace(0,1,9))
plt.pie(np.ones(9), colors=colors)

Of course, trying to get more (visually-differentiable) colors out of the color map will be difficult.

Hope that helps,
-Tony

···

On Wed, Nov 30, 2011 at 6:31 PM, Grigoris Maravelias <gr.maravelias@…287…> wrote:

Just making a note to myself. I have bits and pieces of a property cycling mechanism (originally to cycle line styles). I am finding that cycling is very inconsistent throughout mpl, and I should probably add pie() to that list as well.

As an additional note, would it be a desirable feature to be able to cycle hash styles in the case of producing b&w plots?

Ben Root

···

On Wednesday, November 30, 2011, Tony Yu <tsyu80@…287…> wrote:

On Wed, Nov 30, 2011 at 6:31 PM, Grigoris Maravelias <gr.maravelias@…287…> wrote:

Well I did tried this but it didn’t work out. It actually removes the black color from the color_cycle but the pie still prints it. Moreover I noticed that this color_cycle has 7 colors that repeats after the first 7 so it won’t do what I want. I will need to find another way to set the colors or just avoid the pie.

I guess I should atleast read the docstring for plt.pie before giving you advice on how to use it. It looks like the default colors are hard coded into the function (instead of using the color_cycle parameter).

The quickest way to create different colors is to pick them out from a colormap. For example, the following gives decent results:

colors = plt.cm.Set1(np.linspace(0,1,9))
plt.pie(np.ones(9), colors=colors)

Of course, trying to get more (visually-differentiable) colors out of the color map will be difficult.

Hope that helps,
-Tony

Ben,

I think this would be quite useful. How are you thinking of
implementing it? Cycling through
lines = ['-', '--', '-.', etc] or through dashes = [(20,10), (5,5),
(30,7), etc]?

-paul

···

On Wed, Nov 30, 2011 at 7:43 PM, Benjamin Root <ben.root@...1304...> wrote:

As an additional note, would it be a desirable feature to be able to cycle
hash styles in the case of producing b&w plots?

Ben Root