首页 > 编程语言 > 详细

python中ma.masked_where的用法和legend的用法

时间:2020-06-05 20:35:52      阅读:148      评论:0      收藏:0      [点我收藏+]
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 2*np.pi, 0.02)
y = np.sin(x)
y1 = np.sin(2*x)
y2 = np.sin(3*x)
ym1 = np.ma.masked_where(y1 > 0.5, y1)
ym2 = np.ma.masked_where(y2 < -0.5, y2)

lines = plt.plot(x, y, x, ym1, x, ym2, o)
plt.setp(lines[0], linewidth=4)
plt.setp(lines[1], linewidth=2)
plt.setp(lines[2], markersize=10)

plt.legend((No mask, Masked if > 0.5, Masked if < -0.5),
           loc=upper right)
plt.title(Masked line demo)
plt.show()
ym1 = np.ma.masked_where(y1 > 0.5, y1)这句的意思是:ym1是所有y1值小于0.5的y1的集合
ym2 = np.ma.masked_where(y2 < -0.5, y2)这句的意思是:ym2是所有y2值大于﹣0.5的y2的集合

lines = plt.plot(x, y, x, ym1, x, ym2, ‘o‘)和plt.legend((‘No mask‘, ‘Masked if > 0.5‘, ‘Masked if < -0.5‘),loc=‘upper right‘)配合使用可以给图标注释

python中ma.masked_where的用法和legend的用法

原文:https://www.cnblogs.com/qingnvsue/p/13051363.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!