如何调整海洋线路平板的色调,而不将其连接到下次显示该类别时?

发布于 2025-01-19 19:09:12 字数 381 浏览 5 评论 0原文

我希望为我的 seaborn 线图添加色调,但是以下情况不断发生,如图所示。

我的代码如下:

plt.figure(figsize=(15,5))
sns.lineplot(x = 'DATETIME', y = 'TOTALDEMAND', data = df_day.loc[df_day['STATE'] == 'NSW'],hue="Season")

有没有办法让色调不连接到下一季?

输入图片此处描述

I wish to add a hue to my seaborn lineplot, however the following keeps happening, as shown in the image.

My code is as follows:

plt.figure(figsize=(15,5))
sns.lineplot(x = 'DATETIME', y = 'TOTALDEMAND', data = df_day.loc[df_day['STATE'] == 'NSW'],hue="Season")

Is there a way to have the hue not connect to the next season?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝礼 2025-01-26 19:09:12

一个想法可能是使用固定颜色绘制线图,并使用散点图进行着色:

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd

df = pd.DataFrame({'DATETIME': pd.date_range('20160101', periods=1000, freq='D'),
                   'TOTALDEMAND': np.random.randint(-10, 11, 1000).cumsum() + 30000})
df['SEASON'] = pd.Categorical.from_codes((df.DATETIME.dt.month - 1) // 3, ['winter', 'spring', 'summer', 'autumn'])

plt.figure(figsize=(15, 6))
ax = sns.lineplot(data=df, x='DATETIME', y='TOTALDEMAND', color='black')
sns.scatterplot(data=df, x='DATETIME', y='TOTALDEMAND', s=20, alpha=0.2, hue='SEASON', ax=ax)
sns.despine()
plt.show()

sns.lineplot 具有色调着色

An idea could be to draw the lineplot with a fixed color, and use a scatterplot for colorizing:

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd

df = pd.DataFrame({'DATETIME': pd.date_range('20160101', periods=1000, freq='D'),
                   'TOTALDEMAND': np.random.randint(-10, 11, 1000).cumsum() + 30000})
df['SEASON'] = pd.Categorical.from_codes((df.DATETIME.dt.month - 1) // 3, ['winter', 'spring', 'summer', 'autumn'])

plt.figure(figsize=(15, 6))
ax = sns.lineplot(data=df, x='DATETIME', y='TOTALDEMAND', color='black')
sns.scatterplot(data=df, x='DATETIME', y='TOTALDEMAND', s=20, alpha=0.2, hue='SEASON', ax=ax)
sns.despine()
plt.show()

sns.lineplot with hue coloring

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文