When I export the figure, the x-axis is halved even though I have set the interval in the code.

조회 수: 2 (최근 30일)
I have written this code. I attach the excel and the code. I have to export in .png.
Please help me. Thank you.
T1 = readtable('RM.xlsx', 'VariableNamingRule','preserve');
figure
plot(T1.('s (mm)'), T1.('F (N)'), '-r', T1.('s (mm)_1'), T1.('F (N)_1'),'-k', T1.('s (mm)_2'), T1.('F (N)_2'),'--r', T1.('s (mm)_3'), T1.('F (N)_3'),'--k', 'LineWidth',0.5)
grid
xlim([0 0.5])
ylim([0 5000])
ylabelname = sprintf('Load [N]','${D_{i}}$' );
ylabel(ylabelname, 'fontsize', 11, 'interpreter', 'latex')
set(gca,'xticklabel',num2str(get(gca,'xtick')','%.2f'))
L=legend('RM2-EPX1','RM2-EPX2','RM4-EPX1','RM4-EPX2', 'Location','northwest');
set(L,'Interpreter','latex')
set(gca,'TickLabelInterpreter','latex')
xlabel(sprintf('Displacement [mm]','${D_{i}}$'), 'Interpreter','latex')
ylabel(sprintf('Load [N]','${D_{i}}$'), 'Interpreter','latex')

답변 (2개)

Matt J
Matt J 2021년 10월 20일
I usually use export_fig(),

Walter Roberson
Walter Roberson 2021년 10월 20일
I do not observe that?
I observe a possible loss of quality, but keep in mind that the image taken includes the outside of the axes drawing area, and then that image has to fit within the inside of the drawing area when the image is displayed into an axes. If you were to display the image at the same size as the original space it covered, then it would probably look better.
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/773488/RM.xlsx'
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/773488/RM.xlsx'
T1 = readtable(filename, 'VariableNamingRule','preserve');
fig = figure;
ax = gca(fig);
plot(ax, T1.('s (mm)'), T1.('F (N)'), '-r', T1.('s (mm)_1'), T1.('F (N)_1'),'-k', T1.('s (mm)_2'), T1.('F (N)_2'),'--r', T1.('s (mm)_3'), T1.('F (N)_3'),'--k', 'LineWidth',0.5)
grid(ax)
xlim(ax, [0 0.5])
ylim(ax, [0 5000])
ylabelname = sprintf('Load [N]','${D_{i}}$' );
ylabel(ax, ylabelname, 'fontsize', 11, 'interpreter', 'latex')
set(ax, 'xticklabel',num2str(get(gca,'xtick')','%.2f'))
L=legend('RM2-EPX1','RM2-EPX2','RM4-EPX1','RM4-EPX2', 'Location','northwest');
set(L,'Interpreter','latex')
set(ax,'TickLabelInterpreter','latex')
xlabel(ax, sprintf('Displacement [mm]','${D_{i}}$'), 'Interpreter','latex')
ylabel(ax, sprintf('Load [N]','${D_{i}}$'), 'Interpreter','latex')
tf = tempname + ".jpg";
cleanMe = onCleanup(@() delete(tf));
exportgraphics(fig, tf);
figure();
img = imread(tf);
imagesc(img);
axis off

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by