Matplotlib:用不同的标记和标签

时间:2015-11-04 13:44:17

标签: python pandas matplotlib

我的pandas数据框名为red_all,如下所示:

      a*         b*  
s1    32.649998 9.950000
s2    45.359997 18.160000
s3    50.539997 23.759998
s4    54.269997 33.019997
s5    44.219997 29.029999
s6    32.349998 20.830000
s7    17.320000 12.360000

我想绘制b *(y轴)与a *(x轴),每个点具有不同的标记和不同的标记。 到目前为止,我已经尝试过这个:

s = ['o','v','<','>','p','s','8']
dis_red = ['6.3%r/94.7%w','25%r/75%w','50%r/50%w','red','98.5%r/1.5%b','94.1r/5.9%b','80%r/20%b']

plt.figure(1)
plt.plot(red_all['a*'], red_all['b*'], 'r', marker=s, label=dis_red)
plt.grid()
plt.axis([-60, 60, -60, 85])
plt.xlabel('Chromaticity a*',fontsize=16, fontweight = 'bold')
plt.ylabel('Chromaticity b*', fontsize=16, fontweight = 'bold')
plt.legend(loc='best')

当我尝试运行它时,我得到:

ValueError: Unrecognized marker style ['o', 'v', '<', '>', 'p', 's', '8']

我该如何解决这个问题? 谢谢

2 个答案:

答案 0 :(得分:1)

这是做我想要的另一种方式:

figure1_red = zip(red_all['a*'].values,red_all['b*'].values,s,dis_red)
plt.figure(1)
for i in range(0,len(red_all['a*'])):
    plt.plot(figure1_red[i][0],figure1_red[i][1],'r',marker=figure1_red[i][2],label=figure1_red[i][3])
plt.grid()
plt.xlabel('Chromaticity a*',fontsize=16, fontweight = 'bold')
plt.ylabel('Chromaticity b*', fontsize=16, fontweight = 'bold')
plt.legend(loc='best')

enter image description here

答案 1 :(得分:0)

也许您正在寻找散点图:

vx = [0, 1, 2, 3, 4, 5, 6]
vy = [0, 1, 2, 3, 4, 5, 6]

s = ['o','v','<','>','p','s','8']
l = ['label%s' % i for i in range(7)]

for x, y, marker, label in zip(vx, vy, s, l):
    plt.scatter(x, y, c='r', marker=marker)
    plt.annotate(label, (x, y))

enter image description here