altmany / export_fig

A MATLAB toolbox for exporting publication quality figures
BSD 3-Clause "New" or "Revised" License
1.28k stars 368 forks source link

Wrong font in contour labels #388

Closed samuelestenlund closed 7 months ago

samuelestenlund commented 8 months ago

Thanks for a very useful package!

But I do have one problem with it. I can't get it to export an eps with the correct font for the label numbers in a contour plot. All the other fonts works, but the numbers on the lines in the contour plot are in Courier instead of Garamond.

clear all
setfontname = ('Garamond');
x = [0 1 3];
y = [0 1 3];
d = [0 1 1; 1 2 2; 1 2 3];
levels = 0:0.5:3;

close all
figure('Position', [200, 200, 200, 200])
[C,h] = contourf(x,y,d,levels);
clabel(C,h,'FontName',setfontname)
xlabel('X axis [unit]','fontname',setfontname)
ylabel('Y axis [unit]','fontname',setfontname)
title('Figure title','fontname',setfontname)

fname = 'exporttest';
export_fig(fname,'-eps','-transparent')

image

altmany commented 7 months ago

This issue is presumably fixed in the latest release (v3.45).

The issue was originally due to an internal Matlab bug (the print function incorrectly exports all non-Helvetica contour labels as Courier). The fix in export_fig is to replace such Courier instances with the correct font name (in the print2eps function).

Note: If your figure contains multiple unique non-default FontNames, then this cannot be handled automatically; in such a case you can try to use the -regexprep option to replace '/Courier ' with '/Garamond ' etc.

Let me know if you still see a problem.