【发布时间】:2021-09-08 11:34:38
【问题描述】:
如何在 seaborn 中将所有线条更改为黑色?我输入了“color = 'black'但它并没有改变默认值。我还希望whitegrid在图表中保留但它消失了。
data['date'] = pd.to_datetime(data['date']).dt.date
sns.lineplot(data=data, x='date', y='count', hue='new_sentiment', style = 'new_sentiment',
color ='black')
sns.set_style("whitegrid", {
"ytick.major.size": 0.1,
"ytick.minor.size": 0.05,
'grid.linestyle': 'solid',
})
plt.legend(bbox_to_anchor=(1.04,1), loc="upper left")
plt.setp(plt.gca().xaxis.get_majorticklabels(),rotation=90)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%d-%b-%Y'))
plt.xlim([datetime.date(2020, 1, 13), datetime.date(2021, 6, 15)])
plt.gca().xaxis.set_major_locator(mdates.DayLocator(interval=24))
plt.savefig('04_clean_resentiment_count_2020_2021.tiff', dpi=300, format='tiff', bbox_inches='tight')
【问题讨论】:
-
您已将
hue属性分配给new_sentiment自动为线条着色。删除它,所有线条都应该是黑色的。