Matlab, graph of two data series in one graph

In MATLAB, you can create a single graph from two related data sources with the first source plotted along the bottom of the x axis, and the second one along the top edge of the x axis?

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

The last chart I need is as follows:

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

+4
source share
2 answers

I tried to reproduce the graph as close as possible. Here is 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 use XTICKLABEL_ROTATE to rotate the labels along the x axis

+6
source

Check out the documentation for the bar function. You can use it to create graphs, such as:

bar2.gif

bar_ex2.gif

0
source

Source: https://habr.com/ru/post/1315594/


All Articles