简体   繁体   中英

Fat band using matplotlib in python

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)

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.

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.

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 .

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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