Два разных значения для цвета одной и той же полосы - PullRequest
1 голос
/ 26 марта 2019

Следующий код предназначен для получения цвета для каждого класса в наборе данных:

data = data.sort_values(by="Sentiment")
sentiment=data['Sentiment'].unique()
palette = sns.husl_palette(len(sentiment), l=0.7)
SAge_Graph = sns.countplot(x='Age', hue='Sentiment', 
data=data,palette=palette ,order=sorted(unique_age_groups))
legendInf = {}

for sentiment, color in zip(sentiment, palette):
legendInf[matplotlib.colors.rgb2hex(color)] = sentiment
print(legendInf)

, который дал мне следующий вывод:

{'#f8889a': 'Negative', '#57bf36': 'Neutral', '#59b0f6': 'Positive'}

В следующем коде я перебираюкаждый столбец, чтобы получить свою координату и цвет:

bars = [rect for rect in SAge_Graph.get_children() if isinstance(rect, matplotlib.patches.Rectangle)]

barInfo={}
barInfo['coordinates']=[]
barInfo['colors']=[]
for bar in bars :
w,h=bar.get_width(),bar.get_height()
x0,y0=bar.xy
x1, y1 = x0 + w, y0
x2, y2 = x0, y0 + h
x3, y3 = x0 + w, y0 + h

barInfo['coordinates'].append(((x0, y0), (x1, y1), (x2, y2), (x3, y3)))

barInfo['colors'].append(matplotlib.colors.rgb2hex(bar.get_facecolor()))

, которые дают мне следующий вывод:

    coordinates   colors
0  ((-0.4, 0), (-0.13333333333333336, 0), (-0.4, ...  #ea96a3

1  ((2.8666666666666667, 0), (3.1333333333333333,...  #60ae47

2  ((3.1333333333333333, 0), (3.4, 0), (3.1333333...  #6daee2

И цвет не одинаков в обоих, выведите любое представление о том, почему это различие?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...