2019-01-19
阅读量:
917
在matplotlib中绘制这样的自定义图例?
我有一种情况,我在matplotlib图上绘制内容,散点图形状映射到一种标签。
例如:
's': "X"
'o': "Y"
但是,我用网络x绘制。现在,我想添加一个显示此映射的图例,我可以使用plt方法修改绘图。
所以我需要plt.legend以下方式:
plt.legend(('s','o'),("X","Y"))
但是从文档中不清楚如何完成这项任务。有没有办法在matplotlib中绘制这样的自定义图例?
我尝试用别人的方法:在Axis对象上绘制内容时,可以传递label关键字参数:
fig, ax = plt.subplots(figsize=(8, 8))
n_points = 10
x1 = np.random.rand(n_points)
y1 = np.random.rand(n_points)
x2 = np.random.rand(n_points)
y2 = np.random.rand(n_points)
ax.scatter(x1, y1, marker='x', label='X')
ax.scatter(x2, y2, marker='o', label='y')
ax.legend()






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论