How to plot different data sets in Bar Horizontal Chart with different scale of X-Axes?

조회 수: 2 (최근 30일)
Hello everyone,
I want to plot concentration of each gaseous component in flue gas, but it has different scale of values. Therefore, i categorized the gases into 2 groups: gas 1 and gas 2, with the corresponding concentration (con1 and con2).
I want to visualize my graph in Bar-Horizontal, so the Y-axes consists of only string, and the X-axes shows the concentration. However i do not know, how to add TickLabel for the gas2 and plot the concentration of gas2 to the existing graph with the scale of second X-axes.
So this is the code i already made from several references:
if true
gas1= {'CO_{2}';'H_{2}O'; 'O_{2}';'N_{2}'};
gas2={'HCl'; 'HBr';'HF';'NO';'NO_{2}';'SO_{2}'};
con1=[6 5.99;8 7.99;15 14.97;71 70.87];
con2=[2500 2497.29;400 399.57;100 99.90;200 199.78;316.70 316.36];
barh(con1);
set(gca, 'YTickLabel',gas1, 'YTick',1:numel(gas1));
xlabel('Gaseous component in flue gas')
ax1 = findobj(gca, 'type', 'axes');
axPos = get(ax1, 'Position');
set(ax1, 'Position', axPos + [0 0.3 0 -0.3]);
set(ax1, 'LineWidth', 2);
axes(ax1); xlabel('Concentration of H_{2}O,O_{2}, N_{2},CO_{2} (%)');
ax2 = axes('position', (axPos .* [1 1 1 1e-3]) + [0 0.15 0 0], 'color', 'none', 'linewidth', 2);
axes(ax2); xlabel('Concentration of HCl, HBr, HF, NO, NO_{2}, SO_{2} (mg/m^{3} i.N.tr)');
set(ax2, 'xlim', [30 2600]);
end
And this is the result:
I am so thankful for your help.
Best Regards, Ikha

채택된 답변

jonas
jonas 2018년 10월 28일
편집: jonas 2018년 10월 28일
That axes on the bottom is just for show and lacks functionality. This line of code right here sets its height close to zero:
ax2 = axes('position', (axPos .* [1 1 1 1e-3]) + [0 0.15 0 0],...
If it has no height then you cannot plot anything on it (or at least you do not want to). If you got this code from somewhere else, then the intention was probably to scale the data to fit with the second axes, while actually plotting it on the first axes. Another option would be to use two aligned axes, such as yyaxis.
Making one axes disconnected from the other one is a bit tricky. A hacky solution would be creating a third invisible axes that has the same position as the first axes but the same scale as the second, and use that for plotting.
  댓글 수: 2
Ikha Muliawati
Ikha Muliawati 2018년 10월 28일
편집: Ikha Muliawati 2018년 10월 28일
Hello Jonas,
Thank you for your answer and hints.
Yes, i got the code from others in this forum. Ok. I understand, so i need the height and the scale for the second axes.
Yes. I tried already with yyaxis. But my problem actually there are more than 2 groups of gases. So, i think if i can manage 2 groups, i will manage more than 2 as well.
Best Regards, Ikha
jonas
jonas 2018년 10월 28일
편집: jonas 2018년 10월 28일
Could you perhaps make a small sketch of how you want the final result to look? 8 different cases and 2 bars for each gas?
I can write something later tonight as long as I know what the end result should look like.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by