python - How to pick unique colors of histogram bars in matplotlib? -
i trying plot several histogram on same plot figured out colors assigned different series, bother me little. there way of forcing color bars unique ?
that works small data set, when use lot of data, see problem coming back
here example, blue color assigned twice 2 different data samples
all examples , solutions attribute colors histograms in matplotlib (at least found) suggesting normalize x axis between 0 , 1 this example , not want have because important have real values in case.
is there solution ?
thanks
edit
one solution came convert cmap palette numpy array , use pyplot hist color calling palette
n = len(list_of_samples) sample_colors = cm.get_cmap('rdylbu', n) palette = sample_colors(np.arange(n))
but works hist plot function got error message
valueerror: to_rgba: invalid rgba arg "[[ 0.64705884 0. 0.14901961 1. ] [ 0.89187675 0.2907563 0.20000001 1. ] [ 0.98711484 0.64593837 0.36358543 1. ] [ 0.99719888 0.91316527 0.61736696 1. ] [ 0.91316529 0.96638656 0.90868344 1. ] [ 0.63977591 0.82633053 0.90028011 1. ] [ 0.34957983 0.55294117 0.75462185 1. ] [ 0.19215687 0.21176471 0.58431375 1. ]]" length-1 arrays can converted python scalars
a solution histograms follows:
import pylab pl n, bins, patches = pl.hist(pl.rand(1000), 20) jet = pl.get_cmap('jet', len(patches)) in range(len(patches)): patches[i].set_facecolor(jet(i))
result:
i hope that's looking for.
Comments
Post a Comment