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

1 view (last 30 days)
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')

Answers (2)

Matt J
Matt J on 20 Oct 2021
I usually use export_fig(),

Walter Roberson
Walter Roberson on 20 Oct 2021
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

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!