简体   繁体   English

在python中使用matplotlib的胖带

[英]Fat band using matplotlib in python

I would like to plot a line with varying thickness using matplotlib in python.我想在 python 中使用 matplotlib 绘制一条粗细不同的线。

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)

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.我想用 x_value 和 y_value 绘制一条线,厚度随 x_value 位置变化并由带宽向量给出。

A possible solution that I see would be to draw the upper and lower line (ie I take y_value[index] +- bandwidth[index]/2 and plot those two lines.我看到的一个可能的解决方案是绘制上下线(即我取 y_value[index] +-bandwidth[index]/2 并绘制这两条线。

Then I could try to fill the space between the two lines (how?)然后我可以尝试填充两行之间的空间(如何?)

If you have any suggestions?如果你有什么建议?

Thank you,谢谢,

Samuel.塞缪尔。

You can do this using fill_between .您可以使用fill_between来做到这fill_between

For example, to have half the bandwidth above and half below (and also drawing the original line using plot ):例如,要拥有一半以上的bandwidth和一半以下的bandwidth (并且还使用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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM