问题描述
我想在python中使用matplotlib绘制一条厚度变化的线.
I would like to plot a line with varying thickness using matplotlib in python.
更清楚地说,我有以下变量
To be clearer, I have the following variable
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 位置变化并由带宽向量给出.
I would like to plot a line with x_value and y_value and a thickness that vary with the x_value position and given by the bandwidth vector.
我看到的一个可能的解决方案是绘制上下线(即,我采用y_value [index] + -widthband [index]/2并绘制这两条线.
A possible solution that I see would be to draw the upper and lower line (i.e. I take y_value[index] +- bandwidth[index]/2 and plot those two lines.
然后我可以尝试填充两行之间的空间(如何?)
Then I could try to fill the space between the two lines (how?)
如果您有任何建议?
谢谢
塞缪尔.
推荐答案
您可以使用 fill_between
.
You can do this using fill_between
.
例如,要使 bandwidth
上一半,下一半(并且还使用 plot
绘制原始线):
For example, to have half the bandwidth
above and half below (and also drawing the original line using plot
):
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()
这篇关于在python中使用matplotlib的胖子乐队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!