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

1 view (last 30 days)
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

Accepted Answer

jonas
jonas on 28 Oct 2018
Edited: jonas on 28 Oct 2018
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 Comments
Ikha Muliawati
Ikha Muliawati on 28 Oct 2018
Edited: Ikha Muliawati on 28 Oct 2018
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 on 28 Oct 2018
Edited: jonas on 28 Oct 2018
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!