Graph axis with different font types
130 次查看(过去 30 天)
显示 更早的评论
Hey all,
I would like to change my axis font type while writing units. It shouldn't be italised. I couldn't seperate it from the rest. Also I' highky welcome to improvement ideas for my figure. If you're able to help I'll be grateful. Thanks in advance.
Part of my code;
figure (1);
quiverC2D(X,Y,U,V,0);
set(gca, 'Color', 'white');
set(gca,'fontname','georgia','fontangle','italic')
set(gca,'FontSize',18)
axis tight
axis equal;
colorbar
colormap('jet')
title(sprintf('M1 Normal T%d Mean Velocity',j))
% title(sprintf('M1 Normal T%d %d-%s Mean Velocity',j,i,word))
xlabel('x [mm]')
ylabel ('y [mm]')
f1=getframe(gcf);
writeVideo(obj1,f1);
pause(0.1);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/666685/image.jpeg)
0 个评论
采纳的回答
Chunru
2021-6-27
You can use latex command \rm to set the font:
figure (1);
plot(rand(10,1))
set(gca, 'Color', 'white');
set(gca,'fontname','georgia','fontangle','italic')
set(gca,'FontSize',18)
title(sprintf('M1 Normal T%d Mean Velocity',1))
xlabel('x {\rm [mm]}')
ylabel ('y {\rm [mm]}')
更多回答(1 个)
Image Analyst
2021-6-27
See my attached demo where you can change virtually anything on the graph.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/666715/image.png)
% Demo to make a black graph with red Y axis, green X axis, and yellow grid. Markers are magenta with green lines between them.
% Initialization steps:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 24;
% Create sample data.
X = 1 : 20;
Y = rand(1, 20);
% Plot green lines between the markers.
plot(X, Y, 'g-', 'LineWidth', 3);
hold on;
% Plot magenta markers.
plot(X, Y, 'ms', 'LineWidth', 3, 'MarkerSize', 15);
grid on;
title('Y vs. X, Font Size 20', 'FontSize', 20, 'Color', 'b', 'FontWeight', 'bold');
% Make labels for the two axes.
xlabel('X Axis, Font Size 18');
ylabel('Y axis, Font Size 24');
yticks(0 : 0.2 : 1);
% Get handle to current axes.
ax = gca
% Now let's have fun changing all kinds of things!
% This sets background color to black.
ax.Color = 'k'
ax.YColor = 'r';
% Make the x axis dark green.
darkGreen = [0, 0.6, 0];
ax.XColor = darkGreen;
% Make the grid color yellow.
ax.GridColor = 'y';
ax.GridAlpha = 0.9; % Set's transparency of the grid.
% Set x and y font sizes.
ax.XAxis.FontSize = 18;
ax.YAxis.FontSize = 24;
% Make the axes tick marks and bounding box be really thick.
ax.LineWidth = 3;
% Let's have the tick marks go outside the graph instead of poking inwards
ax.TickDir = 'out';
% The below would set everything: title, x axis, y axis, and tick mark label font sizes.
% ax.FontSize = 34;
% Bold all labels.
ax.FontWeight = 'bold';
hold off
% Now do stuff with the figure, as opposed to the axes control that is ON the figure.
% Maximize the figure
g = gcf; % Get handle to the current figure.
g.WindowState = 'maximized'; % Make it full screen.
g.Name = 'Demo by Image Analyst'; % Put a custom string into the titlebar.
g.NumberTitle = 'off'; % Don't have it put "Figure 1" before the name.
g.MenuBar = 'figure'; % or 'none'
g.ToolBar = 'figure'; % or 'none'
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!