leandro leandro - 1 month ago 13
Python Question

Font rendering in PDF when using "annotate"

I am plotting a series of graphs using matplotlib (in Linux Mint 18 - python 2.7.12), using the code below. The problem is, however, that when generating the PDF file, the fonts associated with the "annotate" directive (

plt.annotate()
) are very badly rendered. I could not find the problem. Does anyone has a clue?

The resulting picture is this:
enter image description here

(I expect that you see that the 0%, 10% ... 50% annotations have low resolution). Other plots with annotations did not have the same problem.
If I zoom into the picture, I see that these annotations are rendered as vector, but somehow they are rendered differently from the other fonts of the plot.

font = {'weight' : 'normal',
'size' : 8}
matplotlib.rc('font', **font)

concentrations = ["0","10","20","30","40","50"]
subplot = [ 321, 322, 323, 324, 325, 326 ]
runs = ["01","02","03","04","05","06","07","08","09","10"]
ic = -1
for c in concentrations :
ic = ic + 1
plt.subplot(subplot[ic])
for run in runs :
x, y = np.loadtxt(run+".dat",usecols=(0,1),comments="#",unpack=True)
plt.plot(x, y, 'b-', linewidth=1.0)
plt.xlim(0,1)
plt.ylim(0,r0[ic]+0.01)
plt.xticks(np.arange(0,1.1,0.25))
plt.annotate(c+"%", xy=(0.03, 0.02),**font)

plt.gcf().set_size_inches(3,4)
plt.gcf().savefig('../../tcf/alldecays.pdf')

Answer

It looks different, because you print these labels (XX%) several times (for each run).

Reducing the indentation of the annotate command (so it will only run once per each subplot) will fix the problem