# my 'new_ba', 'route', and 'sentiment' are defined
plt.figure(figsize = (10,5))
plt.title('Sentiment of Route')
colors = {'Positive': 'green', 'Neutral': 'blue', 'Negative': 'red'}
sns.histplot(data=new_ba, x='route', hue='sentiment', palette=colors.values())
plt.xticks(rotation=45, ha='right')
plt.savefig('problem.png')
plt.show()
我没有收到错误,但图例的颜色与
histplot
不同。
使用一些虚拟数据并简单地添加
multiple='stack'
,我就能够生成下面的图像。
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
new_ba = pd.read_csv('data.csv')
plt.figure(figsize = (10,5))
plt.title('Sentiment of Route')
colors = {'Positive': 'green', 'Neutral': 'blue', 'Negative': 'red'}
sns.histplot(data=new_ba, x='route', hue='sentiment', palette=colors.values(), multiple='stack')
plt.xticks(rotation=45, ha='right')
plt.savefig('problem.png')
plt.show()