Martin Mokrejs wrote: > Hi, > I am trying to improve my code where I cannot find out why matplotlib-1.1.0 > does not > support colors specified as RG tuples. Here is an example. > > > > import numpy as np > import matplotlib.pyplot as plt > > _nums = [160.0, 160.0, 160.0, 95.0, 160.0, 160.0]
Grr. This was the trick: _nums = [[160.0], [160.0], [160.0], [95.0], [160.0], [160.0]] What a wasteful list creation. :( > _colors = [(0.5019607843137255, 0.0, 0.5019607843137255), > (0.5019607843137255, 0.0, 0.5019607843137255), (0.5019607843137255, 0.0, > 0.5019607843137255), (0.5019607843137255, 0.0, 0.5019607843137255), > (0.5019607843137255, 0.0, 0.5019607843137255), (0.5019607843137255, 0.0, > 0.5019607843137255)] > _legends = ['foo', 'foo', 'foo', 'blah', 'foo', 'foo'] > > plt.hist(_nums, histtype='bar', align='mid', color=_colors, log=False, > label=_legends) > > plt.show() > > > The above code gives me: > > File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 2332, > in hist > ret = ax.hist(x, bins, range, normed, weights, cumulative, bottom, > histtype, align, orientation, rwidth, log, color, label, **kwargs) > File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line 7598, in > hist > raise ValueError("color kwarg must have one color per dataset") > ValueError: color kwarg must have one color per dataset > > > Mainly, I am suggesting the error message to be improved and to write out how > many > items were in data, color and legend iterables passed to the function. That > would help Would it tells me my problem is not with color but with data points life would be much easier. ;) > in some cases albeit not with this example. That needs some other fix. ;) > > I would like that one can also pass in a list of HTML-like colors, e.g. > 'F0F8FF' or 0xF0F8FF > would be valid. Sorry, meant also '#F0F8FF', but now I have verified that they do work already: _colors = ['b', 'b', 'b', 'r', 'b', 'b'] _colors = ['#C0C0C0', '#C0C0C0', '#C0C0C0', '#800000', '#C0C0C0', '#C0C0C0'] _colors = [(0.5019607843137255, 0.0, 0.5019607843137255), (0.5019607843137255, 0.0, 0.5019607843137255), (0.5019607843137255, 0.0, 0.5019607843137255), (0.5019607843137255, 0.0, 0.5019607843137255), (0.5019607843137255, 0.0, 0.5019607843137255), (0.5019607843137255, 0.0, 0.5019607843137255)] So this was all about *data* points to be wrapped in iterables. :(( Martin ------------------------------------------------------------------------------ For Developers, A Lot Can Happen In A Second. Boundary is the first to Know...and Tell You. Monitor Your Applications in Ultra-Fine Resolution. Try it FREE! http://p.sf.net/sfu/Boundary-d2dvs2 _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users