How to plot different data sets in Bar Horizontal Chart with different scale of X-Axes?
1 次查看(过去 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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!