Filling between two lines

不打扰是莪最后的温柔 提交于 2021-02-05 09:47:41

问题


I've plotted two lines based on some scattered points, however, I now need to fill the area between the two lines.

counts_dataset = dataset('file','file.txt','Delimiter','\t');
x = counts_dataset.x;
y1 = counts_dataset.y1;
y2 = counts_dataset.y2;

line1 = line(x, y1,'Color', [.8 .8 .8])
line2 = line(x, y2,'Color', [.8 .8 .8])

I am now trying to fill in the region between the two lines as so:

fill([x fliplr(x)],[y2 fliplr(y1)],'c')

However, this gives me this plot:

disregard the scatter points

Am I using the fill function incorrectly? How can I shade between the two lines?


回答1:


Probably you have some trouble with your data. The following code does exactly what you want:

x = 1:10;
y1 = sin(x) + 3;
y2 = sin(x);
fill([x fliplr(x)], [y2 fliplr(y1)], 'c')



来源:https://stackoverflow.com/questions/36555528/filling-between-two-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!