【发布时间】:2020-07-02 15:25:31
【问题描述】:
我无法控制哪个数据类别在 seaborn 的多线图中获取什么标记。为了证明我在这里尝试做的是一个人为的例子 -
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="ticks")
sns.set_context("paper", rc={"font.size":8,"axes.titlesize":20,"axes.labelsize":15})
fig, ax = plt.subplots()
df = pd.DataFrame({'A': [1,2,3,4,1,2,3,4,1,2,3,4], 'B': ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b', 'c', 'c', 'c', 'c'], 'C': [1,1,3,4,1,1,3,3,1,1,2,3]})
sns.lineplot(x='A', y='C', hue='B', hue_order=['c', 'b', 'a'], markers=[{'c': 'X', 'b': 's', 'a': 'o'}], palette={'a': 'Orange', 'b': 'Green', 'c': 'Red'}, dashes=False, data=df, markers=True, ax=ax)
plt.title('A Plot')
ax.set(xlabel='Time', ylabel='#')
ax.legend(title='Legend', loc='upper left', labels=['A', 'B', 'C'])
ax.set(xticks=df['A'].values)
plt.gca().set_position([0, 0, 1, 1])
plt.show()
当我执行style='B' 时,我收到以下错误 -
ValueError: These `style` levels are missing markers: {'b', 'c'}
我尝试了style_order=['a', 'b', 'c'],但我得到了与上面相同的情节。
我如何真正获得具有正确情节线的标记?
【问题讨论】:
标签: python python-3.x matplotlib plot seaborn