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 (

) 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
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.annotate(c+"%", xy=(0.03, 0.02),**font)



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