how to change axis font color?
39 ビュー (過去 30 日間)
古いコメントを表示
Bradley
2024 年 12 月 30 日 19:20
編集済み: Benjamin Kraus
2025 年 1 月 1 日 12:59
Im making an app and I want to allow users to change the color of all font on the plot, I have a drop down menu with various color options and when I select one then click 'plot', I want the color to change. I tried set(gca, 'Color', color) but that changes the color of the background, which is good to know but not exactly what I want. I figured FontColor would work but I guess thats not a recognized property. Any ideas on how to update color of the text given user input? Thanks!
0 件のコメント
採用された回答
Benjamin Kraus
2024 年 12 月 30 日 19:29
編集済み: Benjamin Kraus
2024 年 12 月 30 日 19:39
There are several color related properties on the axes, but the one you are looking for is the XColor or YColor (or ZColor).
ax = axes;
xlabel("X Label");
ylabel("Y Label");
set(ax,'LineWidth',4) % So the colors are more obvious
set(ax,'XColor','green');
set(ax,'YColor','red');
You can see the full list of properties on the Axes Properties documentation page, but here are a few more properties that will give you more fine-grained control:
figure
ax = axes;
view(3) % So you can see the z-axis
xlabel(ax,'X Label');
ylabel(ax,'Y Label');
zlabel(ax,'Z Label');
grid(ax,'on');
ax.XMinorGrid = true;
ax.LineWidth = 4; % To make the colors more prominent
ax.XColor = [1 0 0];
ax.YColor = [0 1 0];
ax.ZColor = [0 0 1];
ax.GridColor = [1 1 0];
ax.MinorGridColor = [1 0 1];
ax.XAxis.Color = [1 0 0]; % Redundant with ax.XColor
ax.XAxis.TickLabelColor = [0 1 1];
ax.XAxis.Label.Color = [0 1 0];
4 件のコメント
Walter Roberson
2024 年 12 月 30 日 22:06
Do you happen to have yyaxis in effect? If so then you probably need one of
ax2.YAxis(1).TickLabelColor = color2;
or
ax2.YAxis(2).TickLabelColor = color2;
その他の回答 (1 件)
Walter Roberson
2024 年 12 月 30 日 22:42
To change the font color while leaving alone the grid lines, see these examples
xtickformat('\color{red}%g') %red
ytickformat('\color[rgb]{0.8,0.3,0.6}%g') %some random color
title('appropriate title', 'Color', 'b') %blue
xlabel('appropriate label', 'Color', [0.4 0.6 0.7]) %some random color
The xtickformat and ytickformat use a different syntax than title() and xlabel() -- you are adding 'tex' commands into the tick labels. You can do this because the default TickLabelInterpreter property is 'tex' .
If you choose to instead use LaTex specification, you will need to add
ax = gca;
ax.XAxis.TickLabelInterpreter = 'latex';
ax.YAxis(1).TickLabelIntepreter = 'latex';
if length(ax.YAxis) > 1; ax.YAxis(2).TickLabelIntepreter = 'latex'; end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!