How to plot different data sets in Bar Horizontal Chart with different scale of X-Axes?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/192831/image.jpeg)
I am so thankful for your help.
Best Regards, Ikha
0 commentaires
Réponse acceptée
jonas
le 28 Oct 2018
Modifié(e) : jonas
le 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Object Programming dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!