How to edit the font size and font name of y-labels while using the toolbox of addaxis?

3 次查看(过去 30 天)
Hello,
I am trying to plot a figure with 3 y-axes using the toolbox of addaxis. The code successfully runs without any errors, but unfortunately, it only edits the font size and font name of the labels of the x-axis and main y-axis, whereas it does not edit the font size and font name that I define for addaxislabel.
Can someone help me to solve this issue?
The code is given as follows:
figure(1)
plot(time,c_nacl_out,'LineWidth',1.3,'Color','black')
ylim([204 207]);
addaxis(time,Q_nacl_in ,[0 6],'LineWidth',1.3,'Color','#C13BD5');
addaxis(time,Q_nacl_out,[0 6],'LineWidth',1.3,'Color','#0AA4A9');
%%%%% Axis Lable %%%%%
gx = gca;
gx.XLabel.String = 'Time (hours)';
gx.XLabel.FontSize = 13;
gx.XAxis.FontName = 'Palatino Linotype';
gx.YLabel.String = 'Outlet Concentration of NaCl (g/L)';
gx.YLabel.FontSize = 13;
gx.YAxis.FontName = 'Palatino Linotype';
addaxislabel(2,'Inlet Volumetric Flow Rate of Brine (L/min)','FontSize',13,'FontName','Palatino Linotype');
addaxislabel(3,'Outlet Volumetric Flow Rate of Brine (L/min)','FontSize',13,'FontName','Palatino Linotype');
legend('Outlet Concentration of NaCl (g/L)','Inlet Volumetric Flow Rate of Brine (L/min)','Outlet Volumetric Flow Rate of Brine (L/min)')
The resuting figure is attached below. Only the labels of x-axis and main y-axis are edited, whereas the labels of the other y-axes are not affected.

采纳的回答

DGM
DGM 2021-12-29
编辑:DGM 2021-12-29
It seems addaxis() is a bit in need of maintenance. The object handles are supposed to be stored in the userdata of the main axis, but they aren't. You can still find them though.
addaxislabels() only accepts two arguments; all others are ignored. It could be rewritten to handle extra settings, but I'm not going to do that. It would be cleaner to just dig up the appropriate axes handles and process all three in the same way instead of dealing with the main and additional axes as if they're different.
N = 1000;
time = linspace(1,24,N);
c_nacl_out = rand(1,N);
Q_nacl_in = rand(1,N);
Q_nacl_out = rand(1,N);
plot(time,c_nacl_out,'LineWidth',1.3,'Color','black')
ylim([204 207]);
addaxis(time,Q_nacl_in ,[0 6],'LineWidth',1.3,'Color','#C13BD5');
addaxis(time,Q_nacl_out,[0 6],'LineWidth',1.3,'Color','#0AA4A9');
%%%%% Axis Lable %%%%%
ylabels = {'Outlet Concentration of NaCl (g/L)', 'Inlet Volumetric Flow Rate of Brine (L/min)', 'Outlet Volumetric Flow Rate of Brine (L/min)'};
gx = gca;
gx.XLabel.String = 'Time (hours)';
hax = getaddaxisdata(gx,'axisdata');
hax = [hax{:}];
hax = [gca hax(1,:)];
for k = 1:numel(hax)
hax(k).FontName = 'Palatino Linotype';
hax(k).FontSize = 13;
hax(k).YLabel.String = ylabels{k};
end
legend(ylabels)
  1 个评论
Mohamed Elasmar
Mohamed Elasmar 2021-12-29
Thank you very much DGM! I am really grateful for your help.
I have integrated the lines that you have suggested for the section of "Axis Lable" and it successfully ran and gave me the following figure:

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by