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

标签 matlab plot graph bar-chart stacked-chart

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

我在 MATLAB 文档的任何地方都找不到这样做的地方。

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

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

最佳答案

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

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 轴上旋转标签

关于Matlab,在一张图中绘制两个数据系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3242796/

相关文章:

algorithm - 证明无向图由该算法转化为有向图的最大出度的上界O(log n)

c++ - 对于计算密集型函数,类函数参数是否比 C++ 中的类变量更好?

matlab - 将元素添加到 matlab 元胞数组成员变量

MATLAB:在 MATLAB 的编辑器中折叠代码单元

python - 计算 Matplotlib 文本旋转

Python Matplotlib : plot with 2-dimensional arguments : how to specify options?

python - Matplotlib:为多个 twinx() 轴上色

javascript - ChartJS 显示时间数据的差距

matlab - Matlab中find()的奇怪用法

python - 如何使用 matplotlib 补丁绘制日历