Matlab,在一张图中绘制两个数据系列

发布于 2024-09-09 18:35:51 字数 251 浏览 6 评论 0 原文

在 MATLAB 中,是否可以创建两个相关数据源的单个图形,其中第一个源沿 x 轴底部绘制,第二个源从 x 轴顶部向下绘制?

我在 MATLAB 文档中找不到完成此操作的任何地方。

我需要的最终图表的形式如下:

http://www.epa.gov/ncer/progress/images/ R827933C033_02_003.gif

In MATLAB, is it possible to create a single graph of two related data sources with the first source plotted along the bottom of the x-axis and the 2nd source plotted down from the top of the x-axis?

I can't find anywhere in the MATLAB documentation where this is done.

The final graph I need is in a form like this:

http://www.epa.gov/ncer/progress/images/R827933C033_02_003.gif

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖凝香 2024-09-16 18:35:51

我试图尽可能接近地重现你的图表。这是我最终得到的结果:

t = linspace(datenum('01-19-2002'), datenum('06-27-2002'), 12);
x1 = randi(40, [12 1]);
x2 = randi(40, [12 1]);
z = 100-x1-x2;

hAxR = axes();
hAxL = axes();

h = bar(t, [x1 z x2], 'stacked');

set(h(1),'facecolor','y')
set(h(2),'facecolor',[.8 .8 .8])
set(h(3),'facecolor','r')
legend(h, {'s1' 's2' 's3'}, ...
   'orientation','horizontal', 'location','northoutside')

set(hAxL, 'xtick',t, 'xlim',[datenum('01-01-2002') datenum('07-15-2002')])
datetick(hAxL, 'x',2,'keepticks','keeplimits')
xticklabel_rotate

ylabel(hAxL, 'label1')
ylabel(hAxR, 'label2')

set(hAxR, 'position',get(hAxL,'position'), 'color','none', 'xtick',[], ...
    'ydir','reverse', 'yaxislocation','right', 'ylim',get(hAxL,'ylim'))
set(hAxL, 'YGrid','on')

graph

我正在使用 XTICKLABEL_ROTATE 在 x 轴上旋转标签

I tried to reproduce your graph as close as possible. Here's what I ended up with:

t = linspace(datenum('01-19-2002'), datenum('06-27-2002'), 12);
x1 = randi(40, [12 1]);
x2 = randi(40, [12 1]);
z = 100-x1-x2;

hAxR = axes();
hAxL = axes();

h = bar(t, [x1 z x2], 'stacked');

set(h(1),'facecolor','y')
set(h(2),'facecolor',[.8 .8 .8])
set(h(3),'facecolor','r')
legend(h, {'s1' 's2' 's3'}, ...
   'orientation','horizontal', 'location','northoutside')

set(hAxL, 'xtick',t, 'xlim',[datenum('01-01-2002') datenum('07-15-2002')])
datetick(hAxL, 'x',2,'keepticks','keeplimits')
xticklabel_rotate

ylabel(hAxL, 'label1')
ylabel(hAxR, 'label2')

set(hAxR, 'position',get(hAxL,'position'), 'color','none', 'xtick',[], ...
    'ydir','reverse', 'yaxislocation','right', 'ylim',get(hAxL,'ylim'))
set(hAxL, 'YGrid','on')

graph

I am using XTICKLABEL_ROTATE to rotate the labels on the x-axis

柠檬色的秋千 2024-09-16 18:35:51

查看 bar 上的文档功能。您可以使用它来创建如下所示的图表:

bar2.gif

bar_ex2.gif

Check out the documentation on the bar function. You can use it to create graphs like the following:

bar2.gif

bar_ex2.gif

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文