SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Grigoris M. <gr....@gm...> - 2011年11月30日 15:34:54
Attachments: 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?
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
From: Tony Yu <ts...@gm...> - 2011年11月30日 16:09:20
On Wed, Nov 30, 2011 at 10:34 AM, Grigoris Maravelias <
gr....@gm...> 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<http://matplotlib.sourceforge.net/users/customizing.html>(Note
that `rc` and `rcParams` is in both matplotlib.pyplot and the main
matplotlib package).
Best,
-Tony
From: Grigoris M. <gr....@gm...> - 2011年11月30日 23:31:48
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....@gm... <mailto:gr....@gm...>> 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 
> <http://matplotlib.sourceforge.net/users/customizing.html> (Note that 
> `rc` and `rcParams` is in both matplotlib.pyplot and the main 
> matplotlib package).
>
> Best,
> -Tony
From: Tony Yu <ts...@gm...> - 2011年12月01日 02:51:07
On Wed, Nov 30, 2011 at 6:31 PM, Grigoris Maravelias <
gr....@gm...> 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
From: Benjamin R. <ben...@ou...> - 2011年12月01日 03:43:20
On Wednesday, November 30, 2011, Tony Yu <ts...@gm...> wrote:
>
>
> On Wed, Nov 30, 2011 at 6:31 PM, Grigoris Maravelias <
gr....@gm...> 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
>
>
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
From: Paul H. <pmh...@gm...> - 2011年12月12日 21:46:37
On Wed, Nov 30, 2011 at 7:43 PM, Benjamin Root <ben...@ou...> 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
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
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /