网络编程
位置:首页>> 网络编程>> 网络编程>> matplotlib给子图添加图例的方法

matplotlib给子图添加图例的方法

作者:木子木泗  发布时间:2023-05-02 03:21:28 

标签:matplotlib,子图,图例

代码如下:


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给子图添加图例的方法

来源:https://blog.csdn.net/u010758410/article/details/71810393

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com