matplotlib给子图添加图例 matplotlib给子图添加图例的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

matplotlib给子图添加图例 matplotlib给子图添加图例的方法

木子木泗   2021-03-31 我要评论

代码如下:

import matplotlib.pyplot as plt

x = [1,2,3,4,5,6,7,8]
y = [5,2,4,2,1,4,5,2]
axe1 = plt.subplot(211)
s1 = axe1.scatter(x,y, color='r', s=25, marker="o")
plt.legend([s1],['A'])
#或者
#s1 = axe1.scatter(x,y, color='r', s=25, marker="o", label='A')
#plt.legend()

axe2 = plt.subplot(212)
s2 = axe2.scatter(x,y, color='g', s=25, marker="o")
plt.legend([s2],['B'])
#或者
#s2 = axe1.scatter(x,y, color='r', s=25, marker="o", label='B')
#plt.legend()
plt.show()

效果图如下:

以上这篇matplotlib给子图添加图例的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们