2016-06-30 7 views
0

Ich habe einen Python-Wörterbuch Ich bin mit einem Histogramm zu erhalten:Pylab - Change historgram Farben basierend auf RGB Achse

colors = {(97, 103, 105): 638059, (129, 140, 143): 562526, (55, 58, 62): 431610, (189, 193, 193): 460605} 

import pylab as pl 
import numpy as np 
dict_index = np.arange(len(colors)) 
pl.bar(dict_index, colors.values(), align='center', width=0.5) 
pl.xticks(dict_index, colors.keys()) 
ymax = max(colors.values()) + 1 
pl.ylim(0, ymax) 
pl.show() 

Die Tasten stellen RGB-Farbcodes und meine Werte sind Anzahl der Pixel.

Ich versuche ein Histogramm (oder eine Treemap, aber das wäre extra), wo jeder Balken die RGB-Farbe übernimmt, die es darstellt.

Wie würde ich das tun?

Danke,

Antwort

1

die Farbe Option in pl.bar Versuchen. Farben müssen auf 0-1 normalisiert werden.

colors = {(97, 103, 105): 638059, (129, 140, 143): 562526, (55, 58, 62): 431610, (189, 193, 193): 460605} 
normalizedcolors = [[i/256 for i in j] for j in colors.keys()] 

import pylab as pl 
import numpy as np 
dict_index = np.arange(len(colors)) 
pl.bar(dict_index, colors.values(), align='center', width=0.5, color = normalizedcolors) 
pl.xticks(dict_index, colors.keys()) 
ymax = max(colors.values()) + 1 
pl.ylim(0, ymax) 
pl.show() 
Verwandte Themen