Matlab does not save the upper x-axis label
5 views (last 30 days)
Show older comments
So, I have a figure with two x-axes - a lower and an upper one to show the time in two units. But the label of the upper one does not get saved.
I have tried to play around with the outer position and if I set height at 0.95 or 1.0 (normalized), I do get both axis labels saved. BUT I'd very much like the figure to be longest horisontally i.e. outer positions like [0, 0.05 0.7 0.6] or something not too far from that.
Any idea how to do that? please ;)
- Henriette
My code:
for i = 1:size(filenames,2)
figure(1)
hold on
p1(i) = plot(x0,y0,'.','color',colors{i},'MarkerSize',8);
pfit(i) = plot(x0,fexp(K,x0),'-','Color','k','Linewidth',1.5);
end
figure(1);
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.1, 0.7, 0.6])
grid on
set(0,'defaultlinelinewidth',1)
set(0,'defaultpatchlinewidth',1)
set(gca,'Fontsize',11)
ax = gca;
ax.LineWidth = 1;
xlim([0 30])
ax1 = gca;
ax1_pos = ax1.Position;
ax2 = axes('Position',[0.1300 0.1100 0.7750 0.8150],'XAxisLocation','top',...
'YAxisLocation','right','Color','none','XTick',...
[0 1 2 3 4 5 6 7 8]*lifetimeval,'YTick',[]);
grid on;
set(0,'defaultlinelinewidth',1)
set(0,'defaultpatchlinewidth',1)
set(ax2,'Fontsize',11)
ax2.LineWidth = 1;
set(ax2,'xcolor','k')
set(ax2,'XTickLabel',{'0','1','2','3','4','5','6','7','8'})
ylabel(ax1,'Intensity [V]','Interpreter','latex')
xlabel(ax1,'Time [ms]','Interpreter','latex')
xlabel(ax2,'Time [lifetimes]','Interpreter','latex')
lgd1 = legend(ax2,[p1(7),p1(6),p1(5),p1(4),p1(3),p1(2),p1(1),pfit(1)],...
{'Gain: 30 dB','Gain: 25 dB','Gain: 20 dB','Gain: 15 dB','Gain: 10 dB','Gain: 5 dB','Gain: 0 dB','Exponential fits'},...
'Location','NorthEast');
set(lgd1, 'Box', 'on', 'Color', 'w')
hold off
saveas(gca,figname1,'epsc')
saveas(gca,figname1,'jpg')
5 Comments
dpb
on 17 Mar 2021
Using the File PrintAs and landscape mode, a saved .jpg looks like the above...it (print) appears smart enough to fit to page. Experiment there with programmatic control.
Answers (0)
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!