Seaborn线图,不同布尔值的不同标记
Seaborn lineplot, different markers for different boolean values
我有一个包含 3 列的数据框。 Champion(分类,包含字符串值)、总伤害(数字)、获胜(包含布尔值,True 或 False)。我想画一条线,我希望它的标记在“win == True”时为“o”,在“win == False”时为“x”。我尝试了附在此处的代码,但 work.It 没有给出 ValueError: Filled and line art markers cannot be mixed.
我尝试使用色调或样式来完成它,但它更改了线条样式而不是标记。我尝试为我的胜利专栏提供风格,并尝试制作标记以遵循它,但这也没有用。谁能帮忙?
谢谢
Only with style
ScreenShot
fig = plt.figure(figsize=(12,8))
h = sns.lineplot(data=skyhill_all,x='champion',y='totalDamageDealt',style='win',markers=['o','x'])
h.yaxis.set_minor_locator(AutoMinorLocator())
h.tick_params(which='both',width=2)
h.tick_params(which='major',length=8)
h.tick_params(which='minor',length=4)
h.set_ylabel('Total Damage Done')
h.set_xlabel('Played Champions')
h.set_yticks(np.arange(5000,75000,5000))
print(h)
最简单的方法是在matplotlib中画一个折线图,然后在散点图中设置标记和颜色。剩下的就是设置 seaborn style。以后可以选择自己的风格。
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
skyhill_all = pd.DataFrame({'champion':list('ABCDEF'),
'totalDamageDealt':np.random.randint(100,10000,6),
'win': [True,False,False,True,True,False]})
plt.style.use('seaborn-white')
fig, ax = plt.subplots()
m = ['o' if x == 1 else 'x' for x in skyhill_all['win']]
c = ['orange' if x == 1 else 'blue' for x in skyhill_all['win']]
ax.plot(skyhill_all['champion'], skyhill_all['totalDamageDealt'])
for i in range(len(skyhill_all)):
ax.scatter(skyhill_all['champion'][i], skyhill_all['totalDamageDealt'][i], marker=m[i], color=c[i])
plt.show()
我有一个包含 3 列的数据框。 Champion(分类,包含字符串值)、总伤害(数字)、获胜(包含布尔值,True 或 False)。我想画一条线,我希望它的标记在“win == True”时为“o”,在“win == False”时为“x”。我尝试了附在此处的代码,但 work.It 没有给出 ValueError: Filled and line art markers cannot be mixed.
我尝试使用色调或样式来完成它,但它更改了线条样式而不是标记。我尝试为我的胜利专栏提供风格,并尝试制作标记以遵循它,但这也没有用。谁能帮忙?
谢谢
Only with style
ScreenShot
fig = plt.figure(figsize=(12,8))
h = sns.lineplot(data=skyhill_all,x='champion',y='totalDamageDealt',style='win',markers=['o','x'])
h.yaxis.set_minor_locator(AutoMinorLocator())
h.tick_params(which='both',width=2)
h.tick_params(which='major',length=8)
h.tick_params(which='minor',length=4)
h.set_ylabel('Total Damage Done')
h.set_xlabel('Played Champions')
h.set_yticks(np.arange(5000,75000,5000))
print(h)
最简单的方法是在matplotlib中画一个折线图,然后在散点图中设置标记和颜色。剩下的就是设置 seaborn style。以后可以选择自己的风格。
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
skyhill_all = pd.DataFrame({'champion':list('ABCDEF'),
'totalDamageDealt':np.random.randint(100,10000,6),
'win': [True,False,False,True,True,False]})
plt.style.use('seaborn-white')
fig, ax = plt.subplots()
m = ['o' if x == 1 else 'x' for x in skyhill_all['win']]
c = ['orange' if x == 1 else 'blue' for x in skyhill_all['win']]
ax.plot(skyhill_all['champion'], skyhill_all['totalDamageDealt'])
for i in range(len(skyhill_all)):
ax.scatter(skyhill_all['champion'][i], skyhill_all['totalDamageDealt'][i], marker=m[i], color=c[i])
plt.show()