mtex icon indicating copy to clipboard operation
mtex copied to clipboard

Text scale mode for creating publication ready figures

Open djm87 opened this issue 3 years ago • 7 comments

Hi Guys,

There is a lot of monkeying around needed to produce suitable publication quality figures. This arises I think because some text positioning doesn't scale well when converted to a specific paper size and because text size is constant while the image size changes.

Consider

    setMTEXpref('FontSize',9);
    plotaStar2east
    figure
    plotIPDF(rodf,zvector,'figSize','tiny','MinMax')
    annotate([Miller(0,1,0,'hkl',CS),Miller(0,-1,0,'hkl',CS),...
        Miller(1,3,0,'hkl',CS),Miller(-1,3,0,'hkl',CS),...
        Miller(1,1,1,'hkl',CS),Miller(-1,1,1,'hkl',CS),...
        Miller(-1,1,2,'hkl',CS),Miller(1,1,2,'hkl',CS),...
        Miller(-1,3,1,'hkl',CS),Miller(1,3,1,'hkl',CS),...
        Miller(0,0,1,'hkl',CS),Miller(1,0,0,'hkl',CS),Miller(-1,0,0,'hkl',CS),...
        Miller(1,1,0,'hkl',CS),Miller(-1,1,0,'hkl',CS)],...
        'all','labeled','BackgroundColor','w')
     CLim(gcm,'equal');CLim(gcm,[0,3])
     title('')
     saveFigure([name '_z_ipf.tif'])
image The first thing you notice is that min is in the IPF. This happens all the time in PFs and IPFs. Some sort of auto scaling of inner and outer margins and text position would be awesome!

The second issue is that for most data layouts in papers the font size is not usable. This can be fixed by modifying the paperposition and position properties to the figure. However, there seems to be no consideration for label position and marker scaling when using paper size.

     h=gcf
     h.PaperUnits='inches'
     h.PaperPosition=[0,0,3.25,3]
     print([name '_z_ipf'],'-dpng')
image

Now we need to change some text position and to get the final result

     h.Units='inches'
     h.Position=[0,0,3.25,3]

I can then manually reposition the text and get the coordinate for the min and set them in the script:

        hhh = findall(gcf,'type','text');
        maxh=hhh(4)
        minh=hhh(2);
        minh.Position=[0.0020,0.5744, 0]

PF_U6_z_ipf

What I think would be nice is to 1) ensure min/max scales and positions nicely with PFs and IPFs. 2) include figSize option that allows a paper width argument. To make plots ease to interact with but still representative of the desired size, scale the MTEX text size and marker size relative to the paper size argument (i.e. if a figure size was the same as the paper size no scaling would occur. If the figure size was 2x the paper size the figure text would be scaled 2x).

Best, Dan

djm87 avatar Feb 23 '21 22:02 djm87

An example of the scaling would be:

    for i=1:4
        setMTEXpref('FontSize',9*i);
        plotaStar2east
        figure
        plotIPDF(rodf,zvector,'figSize','tiny','MinMax')
        annotate([Miller(0,1,0,'hkl',CS),Miller(0,-1,0,'hkl',CS),...
            Miller(1,3,0,'hkl',CS),Miller(-1,3,0,'hkl',CS),...
            Miller(1,1,1,'hkl',CS),Miller(-1,1,1,'hkl',CS),...
            Miller(-1,1,2,'hkl',CS),Miller(1,1,2,'hkl',CS),...
            Miller(-1,3,1,'hkl',CS),Miller(1,3,1,'hkl',CS),...
            Miller(0,0,1,'hkl',CS),Miller(1,0,0,'hkl',CS),Miller(-1,0,0,'hkl',CS),...
            Miller(1,1,0,'hkl',CS),Miller(-1,1,0,'hkl',CS)],...
          'all','labeled','BackgroundColor','w','MarkerSize',10*i)
            CLim(gcm,'equal');
            CLim(gcm,[0,3])
            title('')
            hhh = findall(gcf,'type','text');
            maxh=hhh(4)
            minh=hhh(2);
            minh.Position=[0.0020,0.5744, 0]
        % mtexColorbar
         h=gcf
         yxr=h.Position(4)/h.Position(3);
         h.Units='inches'
         h.Position=[0,0,3.25,3.25*yxr]*i

         h.PaperUnits='inches'
         h.PaperPosition=[0,0,3.25,3.25*yxr]*i
         print([name '_z_ipf' int2str(i)],'-dpng')
    end

Resizing in word to 3.25" width gives image

On my screen I get image

It would be nice if the positions scaled perfectly as well (i.e. no overlap issues), but in all cases the the scaled figures are approximately what you expect after resizing. Ideally the text would be resized for printing so the papersize is as specified.

djm87 avatar Feb 23 '21 23:02 djm87

Hi Daniel,

I usually do the resizing afterwards, i.e., when including the picture into the presentation / paper. This way I can keep all my figures such that they display nicely on screen and have the same fontSize all the time. Is there a reason not to resize them as images.

Ralf.

ralfHielscher avatar Feb 24 '21 06:02 ralfHielscher

Hi Ralf,

I'm finding it difficult for instance to make a plot that that fits in a 3 inch paper width, has three PFs and has 9point font.

Scaling afterwards is fine, but the issue remains that if the font is large relative to the size of PF or IPF object you want to report in a paper you get something like:

image

After changing the position of the min max and the margins I can get this:

image

I tend to have this issue with most plots.

Dan

djm87 avatar Feb 24 '21 06:02 djm87

Hi Daniel,

my workflow is that I have a default fontSize that goes well with the figureSize on my screen. So figures in Matlab look ok in most cases. Then I export them without setting any paperwidth but straight forward with

saveFigure('xasd.png') or saveFigure('xasd.pdf')

The resulting figures look exactly as on the screen and I can easily include them into my presentations / paper.

Ralf.

ralfHielscher avatar Feb 24 '21 07:02 ralfHielscher

Hi Ralf,

Applying your strategy, a 30 pt font in MTEX is the maximum that looks good for the small figure size (see example below). This is a 5 point font after resizing to half page figure in word and I think this isn't reasonable for most publications and that the datalayout for model experiment comparison etc... is commonly needed. To rephrase the issue that I would like addressed: 1) to have built in flexibility for common plots that covers the reasonable font size that might be needed for data layouts in publications. 2) to have an option where the figure size is used to scale the font so you get a target font size when importing and resizing in word (Rather than getting the figure size and scaling the font like I did below). This way a user can deal with the formatting issues that occur for whatever their desired font size and data layout.

If I'm misunderstanding what you are saying still, then please modify the code snippet.

Best, Dan

CS = crystalSymmetry('432', [3.6 3.6 3.6]);
odf=uniformODF(CS);

%Max font size that doesn't give min max issues
fntsz=30
setMTEXpref('FontSize',fntsz);
figure;plotPDF(odf,{Miller(1,0,0,CS),Miller(1,1,0,CS),Miller(1,1,1,CS)},'figSize','small','minmax')
saveFigure('xasd1.png')   

%Compute font size on paper 
h=gcf
h.Units='inches'
paperWidth=3
eqfntsz=fntsz*paperWidth/h.Position(3)

%Font size in mtex needed for 9pt font 
fntsz=9*h.Position(3)/paperWidth

setMTEXpref('FontSize',fntsz);
figure;plotPDF(odf,{Miller(1,0,0,CS),Miller(1,1,0,CS),Miller(1,1,1,CS)},'figSize','small','minmax')
saveFigure('xasd2.png')      
image

djm87 avatar Feb 24 '21 16:02 djm87

Also, I like the idea of embedding fonts with pdf export, but there is some bug such that if I run

CS = crystalSymmetry('432', [3.6 3.6 3.6]);
odf=uniformODF(CS);

%Max font size that doesn't give min max issues
fntsz=30
setMTEXpref('FontSize',fntsz);
figure;plotPDF(odf,{Miller(1,0,0,CS),Miller(1,1,0,CS),Miller(1,1,1,CS)},'figSize','small','minmax')  
saveFigure('xasd1.pdf','-fillpage')  

I get image

i.e. a 30 point font in the figure.

If I run

CS = crystalSymmetry('432', [3.6 3.6 3.6]);
odf=uniformODF(CS);

%Max font size that doesn't give min max issues
fntsz=30
setMTEXpref('FontSize',fntsz);
figure;plotPDF(odf,{Miller(1,0,0,CS),Miller(1,1,0,CS),Miller(1,1,1,CS)},'figSize','small','minmax')  

and separately run

saveFigure('xasd1.pdf','-fillpage')

I get what I expect

image

Using saveFigure with png does not have this difference in plotting. Any thoughts on why this occurs?

djm87 avatar Feb 24 '21 17:02 djm87

I can confirm the strange behaviour with the pdf output in the first run (re-running is fine), althought I can't see what magic saveFigure() is doing after exporting the file for the first time. It does not happen for .eps, nor does it stem from export_fig().

CS = crystalSymmetry('432', [3.6 3.6 3.6]);
odf=uniformODF(CS);

%Max font size that doesn't give min max issues
fntsz=30
setMTEXpref('FontSize',fntsz);
figure;plotPDF(odf,{Miller(1,0,0,CS),Miller(1,1,0,CS),Miller(1,1,1,CS)},'figSize','small','minmax')
f = gcm;
for i=1:length(f.children)
   ax = getappdata(f.children(i),'sphericalPlot')
   ax.TL.Position(1) = ax.TL.Position(1)-0.1;
   ax.BL.Position(1) = ax.BL.Position(1)-0.1;
   ax.BL.Position(2) = ax.BL.Position(2)-0.12;
   
   ax.BL.FontSize=24;
   ax.TL.FontSize=24;
end
f.drawNow
export_fig(gcf,'dummy.pdf'); % looks fine, reproduces screen
saveFigure('1strun.pdf','-bestfit') %1st run looks wrong, 2nd run is fine
saveFigure('2ndrun.pdf','-bestfit') %2nd run is fine, almsot reproduces screen

kilir avatar Feb 24 '21 18:02 kilir