在matplotlib中删除部分情节 [英] remove part of a plot in matplotlib

查看:38
本文介绍了在matplotlib中删除部分情节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种方法来隐藏 matplotlib 图中的部分线条.假设我有一条 x 值从 0 到 100 的线,我想隐藏 x = 20 到 x = 30 线的一部分.有什么有效的方法可以做到这一点?谢谢!

I'm trying to find a way to hide part of a line in a matplotlib plot. Say I have a line with x values from 0 to 100 and I want to hide a portion of the line form x = 20 to x = 30. Is there any efficient way to do this? Thanks!

推荐答案

您可以屏蔽部分数组,然后matplotlib不会绘制它:

You could mask part of the array, then matplotlib doesn't plot it:

import numpy as np
import matplotlib.pylab as pl

x = np.arange(100)
y = np.cos(x/10.)

pl.figure()
pl.subplot(121)
pl.plot(x, y)

# Mask part of array
y2 = np.ma.masked_where(((x>20)&(x<30)), y) 

pl.subplot(122)
pl.plot(x, y2)

这篇关于在matplotlib中删除部分情节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆