首页 > 解决方案 > 如何有条件地更改散点图点形状?

问题描述

我的代码是这样的;

m = np.where(data['Education']== 'Undergraduate','*','o')
colors = np.where(data["Education"]== "Undergraduate",'r','b')
data.plot.scatter(x="Weight",y="Height",c=colors, marker=m)
plt.show()

它适用于颜色,但不适用于标记。请帮忙!!

标签: pythonmatplotlib

解决方案


以下几行内容..是我的建议。

plt.scatter(x=data.Weight[data['Education'] == 'Graduate'],y=data.Height[data['Education'] == 'Graduate'],c='r', marker='*')
plt.scatter(x=data.Weight[data['Education'] == 'Undergraduate'],y=data.Height[data['Education'] == 'Undergraduate'],c='b', marker='o')
plt.show()

推荐阅读