我想知道如何在下的python代码中手动更改类别的颜色,而不是使用cmap
我想要的颜色是以下十六进制颜色代码:
蓝色:#1f77b4
橙色:#ff7f0e
绿色:#2ca02c
红色:#d62728
d = """category1,05-01-2020
category1,02-02-2020
category3,06-03-2020
category2,12-04-2020
category4,07-05-2020
"""
df = pd.read_csv(StringIO(d), sep=',', parse_dates=[1], header=None, names=['category','date'])
fig, ax = plt.subplots()
ax.scatter(df['date'],df['category'], marker='s', c=df['category'].astype('category').cat.codes, cmap='tab10')
谢谢你的帮助
感谢您提供示例数据
Seaborn有
hue
和palette
关键字参数,这使得这个过程非常简单结果:
如果您想继续使用vanilla Matplotlib,可以执行以下操作:
相关问题 更多 >
编程相关推荐