【发布时间】:2021-12-28 02:51:39
【问题描述】:
我正在使用 seaborn 的间歇泉数据集制作散点图。我正在根据“种类”列为点着色,但由于某种原因,图例仅显示“长”,而忽略了“短”。我不知道我错过了什么。我还想知道是否有一种更简单的方法来对不使用 for 循环的数据进行颜色编码。谢谢!
x = geyser_df['waiting']
y = geyser_df['duration']
col = []
for i in range(len(geyser_df)):
if (geyser_df['kind'][i] == 'short'):
col.append('MediumVioletRed')
elif(geyser_df['kind'][i] == 'long'):
col.append('Navy')
plt.scatter(x, y, c=col)
plt.legend(('long','short'))
plt.xlabel('Waiting')
plt.ylabel("Duration")
plt.suptitle("Waiting vs Duration")
plt.show()
【问题讨论】:
标签: python pandas matplotlib data-visualization scatter-plot