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

2 ビュー (過去 30 日間)
Ikha Muliawati
Ikha Muliawati 2018 年 10 月 28 日
編集済み: jonas 2018 年 10 月 28 日
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 件のコメント
jonas
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 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by