python matlibplot 样式_python – 更改matplotlib线样式中图

编辑:我已经这样开放了,所以我没有注意到里卡多的回答.因为matplotlib会将事物转换为numpy数组,无论如何,都有更有效的方法来实现.

举个例子:

只是绘制两条不同的线条,一条是一条虚线,另一条是一条坚固的线条.

例如.

import numpy as np

import matplotlib.pyplot as plt

x = np.linspace(0,10,100)

y1 = 2 * x

y2 = 3 * x

xthresh = 4.5

diff = np.abs(y1 - y2)

below = diff < xthresh

above = diff >= xthresh

# Plot lines below threshold as dotted...

plt.plot(x[below],y1[below],'b--')

plt.plot(x[below],y2[below],'g--')

# Plot lines above threshold as solid...

plt.plot(x[above],y1[above],'b-')

plt.plot(x[above],y2[above],'g-')

plt.show()

对于循环的情况,使用掩码数组:

import numpy as np

import matplotlib.pyplot as plt

x = np.linspace(0,100)

y1 = 2 * np.cos(x)

y2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值