如何解决如何将 seaborn.lineplot 中的所有线条更改为黑色?
如何将 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')
解决方法
以官方参考中的折线图为例,我将折线颜色设置为黑色。然而,当它只有一种颜色时,就很难识别数据。使用单一颜色进行可视化可能会更好。
将 seaborn 导入为 sns
flights = sns.load_dataset("flights")
sns.set_style("whitegrid",{
"ytick.major.size": 0.1,"ytick.minor.size": 0.05,'grid.linestyle': 'solid',})
g = sns.lineplot(data=flights,x="year",y="passengers",hue='month')
lines = g.get_lines()
[l.set_color('black') for l in lines]
g.legend()
sns.lineplot(data=flights,hue='month',palette=('Greys'))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。