Use of Color Cycles for Hist

When plotting multiple data with one Axes.hist call, the method's
interface allows you to specify a list of labels to the 'label' kwarg
to distinguish between the datasets. To get different colors,
however, you cannot give a list of colors to 'color'; instead, you
have to leave out the 'color' kwarg and change the color cycle.

Is there any reason why the color kwarg can't work like label? I
spent an hour or two trying to debug a script before I realized that
'color' wasn't being interpreted as I expected. I realize that there
is some ambiguity since a color argument can be an rgb or rgba
sequence. My proposal would be that 'color' would be interpreted as a
list of distinct colors only when multiple datasets are given as input
and len(color) equals the number of datasets.

I find it hard to imagine a case where you would want to set all
datasets to be the same color, so I don't think the ambiguity would be
a major issue. I would be happy to write and submit an implementation
if others think this is a reasonable idea.

Cheers,
Jeff

···

Jeff Klukas, Research Assistant, Physics
University of Wisconsin -- Madison
jeff.klukas@...830... | jeffyklukas@...831... | jeffklukas@...832...
http://www.hep.wisc.edu/~jklukas/

Jeff Klukas wrote:

When plotting multiple data with one Axes.hist call, the method's
interface allows you to specify a list of labels to the 'label' kwarg
to distinguish between the datasets. To get different colors,
however, you cannot give a list of colors to 'color'; instead, you
have to leave out the 'color' kwarg and change the color cycle.

Is there any reason why the color kwarg can't work like label? I
spent an hour or two trying to debug a script before I realized that
'color' wasn't being interpreted as I expected. I realize that there
is some ambiguity since a color argument can be an rgb or rgba
sequence. My proposal would be that 'color' would be interpreted as a
list of distinct colors only when multiple datasets are given as input
and len(color) equals the number of datasets.

I find it hard to imagine a case where you would want to set all
datasets to be the same color, so I don't think the ambiguity would be
a major issue. I would be happy to write and submit an implementation
if others think this is a reasonable idea.

Sounds good to me. I agree that it makes no sense to have to set the color cycle for hist (although using the color cycle as a default is reasonable), and I think it is just an artifact of the way hist has evolved.

Eric

···

Cheers,
Jeff

>> Jeff Klukas, Research Assistant, Physics
>> University of Wisconsin -- Madison
>> jeff.klukas@...830... | jeffyklukas@...831... | jeffklukas@...832...
>> http://www.hep.wisc.edu/~jklukas/

Alright, I have attached a top-level diff that contains the changes to
axes.py that allow sending multiple colors to the 'color' argument in
Axes.hist.

Below is a short examples that passes lists to 'colors' and 'labels'.

Cheers,
Jeff

histcolors.diff (3.25 KB)

···

Jeff Klukas, Research Assistant, Physics
University of Wisconsin -- Madison
jeff.klukas@...830... | jeffyklukas@...831... | jeffklukas@...832...
http://www.hep.wisc.edu/~jklukas/

----------------------------------
import pylab as P

mu, sigma = 200, 25
x0 = mu + sigma*P.randn(10000)
x1 = mu + sigma*P.randn(7000)
x2 = mu + sigma*P.randn(3000)

P.figure()

colors = ['crimson', 'burlywood', 'chartreuse']
labels = ['Crimson', 'Burlywood', 'Chartreuse']
n, bins, patches = P.hist([x0,x1,x2], 10, histtype='bar',
                          color=colors, label=labels)

P.legend()
P.show()
---------------------------------

On Wed, Mar 31, 2010 at 1:27 PM, Eric Firing <efiring@...229...> wrote:

Jeff Klukas wrote:

When plotting multiple data with one Axes.hist call, the method's
interface allows you to specify a list of labels to the 'label' kwarg
to distinguish between the datasets. To get different colors,
however, you cannot give a list of colors to 'color'; instead, you
have to leave out the 'color' kwarg and change the color cycle.

Is there any reason why the color kwarg can't work like label? I
spent an hour or two trying to debug a script before I realized that
'color' wasn't being interpreted as I expected. I realize that there
is some ambiguity since a color argument can be an rgb or rgba
sequence. My proposal would be that 'color' would be interpreted as a
list of distinct colors only when multiple datasets are given as input
and len(color) equals the number of datasets.

I find it hard to imagine a case where you would want to set all
datasets to be the same color, so I don't think the ambiguity would be
a major issue. I would be happy to write and submit an implementation
if others think this is a reasonable idea.

Sounds good to me. I agree that it makes no sense to have to set the color
cycle for hist (although using the color cycle as a default is reasonable),
and I think it is just an artifact of the way hist has evolved.

Eric

Cheers,
Jeff

>> Jeff Klukas, Research Assistant, Physics
>> University of Wisconsin -- Madison
>> jeff.klukas@...830... | jeffyklukas@...831... | jeffklukas@...832...
>> http://www.hep.wisc.edu/~jklukas/

Jeff Klukas wrote:

Alright, I have attached a top-level diff that contains the changes to
axes.py that allow sending multiple colors to the 'color' argument in
Axes.hist.

Below is a short examples that passes lists to 'colors' and 'labels'.

Jeff,

Thanks. I find that both hist and the patch need some additional reworking, which I will try to get done this weekend.

Eric

···

Cheers,
Jeff

>> Jeff Klukas, Research Assistant, Physics
>> University of Wisconsin -- Madison
>> jeff.klukas@...830... | jeffyklukas@...831... | jeffklukas@...832...
>> http://www.hep.wisc.edu/~jklukas/

----------------------------------
import pylab as P

mu, sigma = 200, 25
x0 = mu + sigma*P.randn(10000)
x1 = mu + sigma*P.randn(7000)
x2 = mu + sigma*P.randn(3000)

P.figure()

colors = ['crimson', 'burlywood', 'chartreuse']
labels = ['Crimson', 'Burlywood', 'Chartreuse']
n, bins, patches = P.hist([x0,x1,x2], 10, histtype='bar',
                          color=colors, label=labels)

P.legend()
P.show()
---------------------------------

On Wed, Mar 31, 2010 at 1:27 PM, Eric Firing <efiring@...229...> wrote:

Jeff Klukas wrote:

When plotting multiple data with one Axes.hist call, the method's
interface allows you to specify a list of labels to the 'label' kwarg
to distinguish between the datasets. To get different colors,
however, you cannot give a list of colors to 'color'; instead, you
have to leave out the 'color' kwarg and change the color cycle.

Is there any reason why the color kwarg can't work like label? I
spent an hour or two trying to debug a script before I realized that
'color' wasn't being interpreted as I expected. I realize that there
is some ambiguity since a color argument can be an rgb or rgba
sequence. My proposal would be that 'color' would be interpreted as a
list of distinct colors only when multiple datasets are given as input
and len(color) equals the number of datasets.

I find it hard to imagine a case where you would want to set all
datasets to be the same color, so I don't think the ambiguity would be
a major issue. I would be happy to write and submit an implementation
if others think this is a reasonable idea.

Sounds good to me. I agree that it makes no sense to have to set the color
cycle for hist (although using the color cycle as a default is reasonable),
and I think it is just an artifact of the way hist has evolved.

Eric

Cheers,
Jeff

>> Jeff Klukas, Research Assistant, Physics
>> University of Wisconsin -- Madison
>> jeff.klukas@...830... | jeffyklukas@...831... | jeffklukas@...832...
>> http://www.hep.wisc.edu/~jklukas/

Eric Firing wrote:

Jeff Klukas wrote:

Alright, I have attached a top-level diff that contains the changes to
axes.py that allow sending multiple colors to the 'color' argument in
Axes.hist.

Below is a short examples that passes lists to 'colors' and 'labels'.

Jeff,

Thanks. I find that both hist and the patch need some additional reworking, which I will try to get done this weekend.

Done in commits ending with 8220. Illustrated in examples/pylab_examples/histogram_demo_extended.py.

Thanks for your work on this.

(There is probably quite a bit more cleanup and refactoring that could be done. Much of the plotting capability of hist could be factored out for other uses, for example.)

Eric

···

Eric

Cheers,
Jeff

>> Jeff Klukas, Research Assistant, Physics
>> University of Wisconsin -- Madison
>> jeff.klukas@...830... | jeffyklukas@...831... | jeffklukas@...832...
>> http://www.hep.wisc.edu/~jklukas/

----------------------------------
import pylab as P

mu, sigma = 200, 25
x0 = mu + sigma*P.randn(10000)
x1 = mu + sigma*P.randn(7000)
x2 = mu + sigma*P.randn(3000)

P.figure()

colors = ['crimson', 'burlywood', 'chartreuse']
labels = ['Crimson', 'Burlywood', 'Chartreuse']
n, bins, patches = P.hist([x0,x1,x2], 10, histtype='bar',
                          color=colors, label=labels)

P.legend()
P.show()
---------------------------------

On Wed, Mar 31, 2010 at 1:27 PM, Eric Firing <efiring@...229...> wrote:

Jeff Klukas wrote:

When plotting multiple data with one Axes.hist call, the method's
interface allows you to specify a list of labels to the 'label' kwarg
to distinguish between the datasets. To get different colors,
however, you cannot give a list of colors to 'color'; instead, you
have to leave out the 'color' kwarg and change the color cycle.

Is there any reason why the color kwarg can't work like label? I
spent an hour or two trying to debug a script before I realized that
'color' wasn't being interpreted as I expected. I realize that there
is some ambiguity since a color argument can be an rgb or rgba
sequence. My proposal would be that 'color' would be interpreted as a
list of distinct colors only when multiple datasets are given as input
and len(color) equals the number of datasets.

I find it hard to imagine a case where you would want to set all
datasets to be the same color, so I don't think the ambiguity would be
a major issue. I would be happy to write and submit an implementation
if others think this is a reasonable idea.

Sounds good to me. I agree that it makes no sense to have to set the color
cycle for hist (although using the color cycle as a default is reasonable),
and I think it is just an artifact of the way hist has evolved.

Eric

Cheers,
Jeff

>> Jeff Klukas, Research Assistant, Physics
>> University of Wisconsin -- Madison
>> jeff.klukas@...830... | jeffyklukas@...831... | jeffklukas@...832...
>> http://www.hep.wisc.edu/~jklukas/