How to Combine Line and Bar Charts with multiple groups in the same figure?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Francisco Javier Hernandez Santiago
am 19 Jul. 2019
Beantwortet: dpb
am 20 Jul. 2019
I found below code to combine 1 group of line and bars
days = 0:5:35;
conc = [515 420 370 250 135 120 60 20];
temp = [29 23 27 25 20 23 23 17];
yyaxis left
b = bar(days,temp);
yyaxis right
p = plot(days,conc);
Also, found below code to display group of bars:
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
bar(y)
Wondering if it's possible to combine both in just one figure in order to use the same axis in all the groups and named each bar differently as below image:
Thanks.
2 Kommentare
dpb
am 19 Jul. 2019
The image is essentially
hF=figure;
hF.Color='w';
for i=1:4
hAx(i)=subplot(1,4,i); % create subplot
end
excepting the figure window will needs must be wide and short to mimic the shape as compared to the default figure.
Also, it isn't possible to change the axis line color or visibility independently of the axis tick label color so if going to show the y-axis tick values, the axis line is going to be visible, too.
Alternatively, one can draw the labels independently with text().
Francisco Javier Hernandez Santiago
am 19 Jul. 2019
Bearbeitet: Francisco Javier Hernandez Santiago
am 19 Jul. 2019
Akzeptierte Antwort
dpb
am 20 Jul. 2019
Oh...didn't follow what were after...thought it was to create the image-like figure...
The following will get you started --
hB=bar(y); % the grouped bar--save handle, we need some data
xoff=hB(1).XOffset % the offset of bars in each group (hidden property)
dx=[xoff 0 -xoff].'; % XOffset value is negative, this is the three loc's relative center
yyaxis right % make a new axis
hL=plot(1+dx,10*[2 2 3],'*-'); % just made up one set of data
ylim([15 50]) % and adjusted limits to make show where wanted
for the general case, create the array of x,y data for each group as above except each group is centered around 1:4, of course, not the hardcoded '1' I used above.
To draw smooth curve you'll have to increase the number of points between the limits (linspace is perfect for this job) and evaluate the curve at enough points to make the smooth curve; the above just gives two straight lines, of course between three points.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!