在两行之间填充 [英] Filling between two lines

查看:63
本文介绍了在两行之间填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经根据一些分散的点绘制了两条线,但是,我现在需要填充两条线之间的区域.

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:

忽略分散点

我是否错误地使用了填充功能?如何在两行之间加阴影?

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

推荐答案

可能您的数据有麻烦.以下代码完全符合您的要求:

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

这篇关于在两行之间填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆