Ask Your Question
1

How to change axes labels font size in PGF (possible bug?)?

asked 2016-04-05 22:53:33 +0100

Eugene gravatar image

updated 2016-04-06 20:16:11 +0100

Hi!

I am trying to change axes labels font size during export to PGD using the following code:

# Change font style
from matplotlib import rc

font = {'family':'serif',
        'serif':['Computer Modern Unicode'],
        'size': 10, }

rc('font', **font)

# Create and save test plot
file_name = '/tmp/foo.pgf'
p = plot(sin, 0, 2 * pi,  axes_labels=('$x$', '$y$'))
p.save(file_name)

# Check font size
with open(file_name, 'r') as f:
    for line in f:
        if 'fontsize' in line:
            print line,

And then suddenly these lines appear in the output of the last block:

\pgftext[x=1.495728in,y=2.740143in,,top]{\rmfamily\fontsize{10.000000}{12.000000}\selectfont 1}% \pgftext[x=2.612150in,y=2.740143in,,top]{\rmfamily\fontsize{10.000000}{12.000000}\selectfont 2}% \pgftext[x=3.728572in,y=2.740143in,,top]{\rmfamily\fontsize{10.000000}{12.000000}\selectfont 3}% \pgftext[x=4.844994in,y=2.740143in,,top]{\rmfamily\fontsize{10.000000}{12.000000}\selectfont 4}% \pgftext[x=5.961415in,y=2.740143in,,top]{\rmfamily\fontsize{10.000000}{12.000000}\selectfont 5}% \pgftext[x=7.077837in,y=2.740143in,,top]{\rmfamily\fontsize{10.000000}{12.000000}\selectfont 6}% \pgftext[x=7.645397in,y=2.795699in,left,base]{\rmfamily \fontsize{16.000000}{19.200000} \selectfont (\displaystyle x)}% \pgftext[x=0.323750in,y=0.203598in,right,]{\rmfamily\fontsize{10.000000}{12.000000}\selectfont -1}% \pgftext[x=0.323750in,y=1.499649in,right,]{\rmfamily\fontsize{10.000000}{12.000000}\selectfont -0.5}% \pgftext[x=0.323750in,y=4.091749in,right,]{\rmfamily\fontsize{10.000000}{12.000000}\selectfont 0.5}% \pgftext[x=0.323750in,y=5.387800in,right,]{\rmfamily\fontsize{10.000000}{12.000000}\selectfont 1}% \pgftext[x=0.379306in,y=5.602445in,,bottom]{\rmfamily \fontsize{16.000000}{19.200000} \selectfont (\displaystyle y)}%

Why does font size 16 requested, font size 10 was specified explicitly.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-04-06 21:13:15 +0100

Eugene gravatar image

The problem was that the Sage uses additional scaling coefficient to font size of labels called axes_labels_size, setting it to 1 and using fontsize directive resolves the problem:

p = plot(sin, 0, 2 * pi,  axes_labels=('$x$', '$y$'))
p.save(file_name)

becomes

p = plot(sin, 0, 2 * pi,  axes_labels=('$x$', '$y$'), axes_labels_size=1, fontsize=12)
p.save(file_name)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-04-05 22:53:33 +0100

Seen: 1,050 times

Last updated: Apr 06 '16