How to change the degree range on a plot?
10 次查看(过去 30 天)
显示 更早的评论
How to change from -10 degrees to 10 degrees on the x-axis?
%% Sensitive parameter P5
figure('Name','Zmiana wartości kąta położenia warstw forniru między sobą w osi podłużnej')
plot(1,1)
plot(L_18(:,1),L_18(:,2),L_18(:,1),L_18(:,3),L_18(:,1),L_18(:,4),...
L_18(:,1),L_18(:,5),L_18(:,1),L_18(:,6),L_18(:,1),L_18(:,7),...
L_18(:,1),L_18(:,8), L_18(:,1),L_18(:,9),L_18(:,1),L_18(:,10),...
L_18(:,1),L_18(:,11),L_18(:,1),L_18(:,12),L_18(:,1),L_18(:,13),...
L_18(:,1),L_18(:,14), L_18(:,1),L_18(:,15),L_18(:,1),L_18(:,16),...
L_18(:,1),L_18(:,17),L_18(:,1),L_18(:,18),'LineWidth',1.5),
set (gcf,'position',[200,200,170,170]) % X pos, Y pos, X size, Y size
set (gca, 'FontSize',9,'fontname','Times New Roman','ytick',-0.05:0.05:0.2) %Size font axis
grid on,
ytickformat('%g%%')
% degree symbol in x-axis - START
xt=get(gca,'xtick');
for k=1:numel(xt);
xt1{k}=sprintf('%d°',xt(k));
end
set(gca,'xticklabel',xt1);
% degree symbol in x-axis - END
set(gca,'colororder',parula(16)) % to avoid color repetition in plotting lines
ylim([0 0.2])
yticks(0:0.2:0.2)
xticks(-10:10:10)
xlim([-10 10]) % How to change from -10 degrees to 10 degrees on a x-axis?
title('SK_5','FontSize',10,'fontname','Times New Roman')
0 个评论
采纳的回答
Jaimin
2024-9-4
编辑:Jaimin
2024-9-4
From the description, I understand that you want to adjust the x-axis limits from -50 to +50 to -10 to +10.
Here, I have attached one workaround to achieve this. (Since I don't have the "L_18" matrix, I've generated random data instead.)
% Generate random data
x = linspace(-20, 20, 100); % x values from -20 to 20
y = 5 * randn(1, 100); % Random y values, scaled for better visibility
% Create the figure and plot
figure('Name', 'Random Data Displayed with Limited X-Axis Range')
plot(x, y, 'LineWidth', 1.5)
set(gcf, 'Position', [200, 200, 400, 300]) % X pos, Y pos, X size, Y size
set(gca, 'FontSize', 9, 'FontName', 'Times New Roman') % Size font axis
grid on
% Add degree symbol to x-axis labels
xticks(-10:5:10) % Set x-axis ticks from -10 to 10
xlim([-10 10]) % Limit x-axis to -10 to 10
% Update x-axis tick labels to include degree symbol
xt = get(gca, 'XTick');
xt1 = arrayfun(@(val) sprintf('%d°', val), xt, 'UniformOutput', false);
set(gca, 'XTickLabel', xt1);
% Set y-axis limits for better visualization
ylim([-15 15]) % Adjust as needed for your data
title('Random Data with X-Axis Limited to -10 to 10', 'FontSize', 10, 'FontName', 'Times New Roman')
Here I have used “arrayfun” to update the “xticks”.
For more information about “arrayfun” please refer following MathWorks Documentation
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!