I would like to have a plot with two y-axes with their labels of the same dimension (24 points).
I am using this code:
figure1=figure('Color','White','Position',[1,41,1000,600],'Renderer', 'Painters')
%Label sizing
size_labels=24;
legend_label=13;
ticks_label_size=12;
%Primary axis plot
plot(age,t_set_avg,'LineWidth',1.2,'Color', [0.9290, 0.6940, 0.1250]);
hold on
ylabel('Air temperature [°C]','Fontsize',size_labels,'Fontweight','bold');
%Secondary axis plot
yyaxis right
plot(age,weight,'--','LineWidth',1.2,'Color',[0.4, 0.4, 0.4]);
a = get(gca,'XTickLabel');
set(gca,'XTickLabel',a,'fontsize',ticks_label_size,'YColor','k');
xlabel('Days of production cycle','Fontsize',size_labels,'Fontweight','bold');
ylabel('Broiler live weight [kg]','Fontsize',size_labels,'Fontweight','bold');
%Legend
legend('\theta_{set\_opt}','\theta_{set\_H}','Fontsize',legend_label);
When I check on the Property Inspector, the size of the label of secondary y-axis is 24 points (as I set) but the primary on is 13.2 points.
Where is my mistake?
Thank you for your help

 Akzeptierte Antwort

ANKUR KUMAR
ANKUR KUMAR am 15 Mär. 2021

0 Stimmen

figure1=figure('Color','White','Position',[1,41,1000,600],'Renderer', 'Painters')
size_labels=24;
legend_label=13;
ticks_label_size=12;
plot([1:25],randi(10,1,25),'LineWidth',1.2,'Color', [0.9290, 0.6940, 0.1250]);
hold on
ylabel('Air temperature [°C]','Fontsize',size_labels,'Fontweight','bold');
yyaxis right
plot([1:25],randi(10,1,25),'--','LineWidth',1.2,'Color',[0.4, 0.4, 0.4]);
xlabel('Days of production cycle','Fontsize',size_labels,'Fontweight','bold');
ylabel('Broiler live weight [kg]','Fontsize',size_labels,'Fontweight','bold');
legend({'\theta_{set\_opt}','\theta_{set\_H}'},'location','best','FontSize',legend_label);
Below code gives the fontsize of both ylable, and both having the same fontsize as 24.
yyaxis left
left_axis=get(gca,'ylabel');
left_axis.FontSize
yyaxis right
right_axis=get(gca,'ylabel');
right_axis.FontSize

6 Kommentare

Thank you Ankur!
The problem was this part of my code that I used to set the size of the TickLabels
a = get(gca,'XTickLabel');
set(gca,'XTickLabel',a,'fontsize',ticks_label_size,'YColor','k');
I eliminated those lines (as yiu did in your code) and the ylabels size is now correct.
I think that, hence, my real problem is to set TickLabels without interfere with ylabels....do you have any suggestion?
ANKUR KUMAR
ANKUR KUMAR am 16 Mär. 2021
Bearbeitet: ANKUR KUMAR am 16 Mär. 2021
Refer this complete code to set ticklabel font size.
clc
clear
figure1=figure('Color','White','Position',[1,41,1000,600],'Renderer', 'Painters')
size_labels=14;
legend_label=12;
ticks_label_size=30;
plot([1:25],randi(10,1,25),'LineWidth',1.2,'Color', [0.9290, 0.6940, 0.1250]);
hold on
ylabel('Air temperature [°C]','Fontsize',size_labels,'Fontweight','bold');
yyaxis right
plot([1:25],randi(10,1,25),'--','LineWidth',1.2,'Color',[0.4, 0.4, 0.4]);
xlab=xlabel('Days of production cycle','Fontsize',size_labels,'Fontweight','bold');
ylabel('Broiler live weight [kg]','Fontsize',size_labels,'Fontweight','bold');
legend({'\theta_{set\_opt}','\theta_{set\_H}'},'location','best','FontSize',legend_label);
ax=gca;
ax.XAxis.FontSize = ticks_label_size;
xlab.FontSize=size_labels;
yyaxis left
left_axis=get(gca,'ylabel');
left_axis.FontSize
yyaxis right
right_axis=get(gca,'ylabel');
right_axis.FontSize
ax.XAxis.FontSize
Andrea Costantino
Andrea Costantino am 16 Mär. 2021
Thank you, I have just tried but it seems to me that the ticklabel font size does not change changing the value of the ticks_label_size variable. According to the Property Inspector it remains 10 pt.
ANKUR KUMAR
ANKUR KUMAR am 16 Mär. 2021
I hope it works. I cross checked the results.
Andrea Costantino
Andrea Costantino am 16 Mär. 2021
Yes it works perfectly.
Thank you so much!
Adam Danz
Adam Danz am 17 Mär. 2021
Bearbeitet: Adam Danz am 17 Mär. 2021
Cleaner:
yyaxis left
plot(__)
yl(1) = ylabel('Air temperature [°C]','Fontweight','bold');
yyaxis right
plot(__)
a = __
set(__)
xlabel(__)
yl(2) = ylabel('Broiler live weight [kg]','Fontweight','bold');
legend(__)
set(yl,'FontSize',24)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by