How can I change the color and font on the second y axis of a subplot?

112 ビュー (過去 30 日間)
SSB
SSB 2014 年 4 月 19 日
回答済み: DanielFromIllinois 2023 年 2 月 1 日
I have a Matlab subplot:
subplot(4,2,2); plotyy(x,y,x,z)
xlabel('x','FontSize',8); set(gca,'FontSize',8); legend('y','z','Location','Best');
set(legend,'FontSize',8); title('y and z','FontSize',10);
But the font on the right axis is 10, not 8, and the color is blue. I would to change the color and font. Many thanks for any help!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 19 日
Try this
close
x=0:0.1:10;
y=sin(x)
z=cos(x)
subplot(4,2,2);
[ax,h1,h2]=plotyy(x,y,x,z);
hl=legend('y','z','Location','Best');
set(hl,'FontSize',8)
title('y and z','FontSize',10)
xlabel('x','FontSize',8);
set(ax,'FontSize',10);
set(h2,'color','g')
  2 件のコメント
SSB
SSB 2014 年 4 月 19 日
This is great Azzi, I have adapted your code, which also helped me make some additional changes. Many thanks!
Sara Fawal
Sara Fawal 2020 年 7 月 23 日
Hello Azzi,
Is there a way to set ALL the Y axis colors in a subplot to black using the findall command?
I want to do this: set(findall(gcf, 'ALL Y Axis Colors', 'k'))
Can it be done.
Thank you

サインインしてコメントする。

その他の回答 (2 件)

Mischa Kim
Mischa Kim 2014 年 4 月 19 日
編集済み: Mischa Kim 2014 年 4 月 19 日
SSB, one way would be to use the plot tools. See icon in the lower right corner in the screen shot:
In the plot tools editor you can select the figure objects and change their properties. Once you are done adapting your figure you can choose > File > Generate Code... and learn how to do all those changes programmatically.
  3 件のコメント
Mischa Kim
Mischa Kim 2014 年 4 月 19 日
In the plot browser start by selecting the corresponding Axes (no title) and continue by changing properties as needed.
SSB
SSB 2014 年 4 月 19 日
Thanks. For some reason I was just not able to click on the second y-axis, but I think I have it now.

サインインしてコメントする。


DanielFromIllinois
DanielFromIllinois 2023 年 2 月 1 日
You can also find the YAxis properties for left and right like so:
fh = figure;
x = 1:10;
y = 1:10;
%pltos on the left axis.
plot(x,y)
%plots on the right axis.
yyaxis right
plot(x,y*2)
%The YAxis object is stored under the Axes child of the figure.
%It has a property 'Color' that you can use to set the color to black.
%The line below will set the color to black.
fh.Children.YAxis(2) = 'k';

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by