Fix Extra Space in Figure using xlabel

I am currently trying to prepare some figures for a final draft of my paper. I have generated some data and plotted a histogram using histfit. I then attempt to label the data using xlabel. I then set the size of the histogram to save it.
All well and good. However, when I save the figure using saveas, I have a big space between the m and the 2. As expected, Matlab is interpreting this as LaTeX code and it's appearing as a superscript. However, I'd like to get rid of the space between the m and the 2.
What's strange is that if I save as an eps, I have this problem, but if I save as a pdf I don't. Here's my minimal working example:
hSize=[6.5,2.5];
A=50*rand(200,1);
histfit(A,20,'gamma')
xlabel('Measured Area (m^2)')
ylabel('Frequency')
set(gcf,'Color',[1 1 1],'PaperUnits','inches','PaperSize',hSize,...
'PaperPosition',[0 0 hSize]);
saveas(gcf, [mypath, '/example.eps'],'epsc') %replace mypath with your own path

1 Kommentar

jamesdg
jamesdg am 12 Feb. 2015
I didn't upload an image of the figure since I can't upload eps files, but here's a screenshot of my figure so you have an idea of what I mean:

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Star Strider
Star Strider am 12 Feb. 2015

0 Stimmen

See if the FEX contribution export_fig can save it correctly for you. It’s gotten great reviews.

6 Kommentare

daniel
daniel am 12 Feb. 2015
weird, I have never had this problem... try export_fig on file exchange, its great.
jamesdg
jamesdg am 12 Feb. 2015
I took a look and tried it out -- a great package. Unfortunately it gives me the same problem.
jamesdg
jamesdg am 12 Feb. 2015
Again, that's only for the .eps file; as with saveas, I have no problems if I save as .jpg or .png. PDF gives me the same problem as EPS.
The only other thing I can think of is to see if using the 'Interpreter','latex' option would help. You can find information on LaTeX here. Its syntax is slightly different from TeX.
Otherwise, experiment with variations, such as:
xlabel('Measured Area (m^{2})')
or
xlabel('Measured Area (m²)')
It doesn’t seem that it would make a difference, but it might.
Thanks, the following worked (though it changed the font -- not a problem for me, but heads up for anyone using this in the future):
xlabel('Measured Area ($m^{2}$)','Interpreter','latex')
Star Strider
Star Strider am 12 Feb. 2015
My pleasure!
I’ve had LaTeX work when other options didn’t. You can also specify the font in xlabel, but I’m not sure if all fonts work and play well with LaTeX.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Printing and Saving finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by