在python中使用matplotlib的脂肪带。

问题描述 投票:1回答:2

我想用python中的matplotlib绘制一条厚度不同的线。

为了更清楚地说明,我有以下变量。

import matplotlib.pyplot as P 
import numpy as N

x_value = N.arange(0,10,1)
y_value = N.random.rand(10)
bandwidth = N.random.rand(10)*10
P.plot(x_value,y_value,bandwidth)

我想绘制一条x_value和y_value的线,其厚度随x_value的位置而变化,并由带宽向量给出。

我看到的一个可能的解决方案是画出上行线和下行线(即我取y_value[index] +- bandwidth[index]2并绘制这两条线。

然后我可以尝试填充这两条线之间的空间(如何填充?

如果您有什么建议?

谢谢你的建议。

塞缪尔,我想用python中的matplotlib绘制一条粗细不同的线。

python numpy matplotlib physics thickness
2个回答
1
投票

你可以使用 fill_between.

例如,要有一半的 bandwidth 上下各半(也可以用下面的方法画出原线) plot):

enter image description here

import matplotlib.pyplot as P 
import numpy as N

x_value = N.arange(0,10,1)
y_value = N.random.rand(10)
bandwidth = N.random.rand(10)*10
print bandwidth
P.fill_between(x_value, y_value+bandwidth/2, y_value-bandwidth/2, alpha=.5)
P.plot(x_value,y_value)
P.show()
© www.soinside.com 2019 - 2024. All rights reserved.