Home > Net >  Label are not shown in pdf saved from python plot
Label are not shown in pdf saved from python plot

Time:10-13

I have a plot in python and I should use a large font for the figure. However, when I save the figure in pdf format, it does not show the label. Could you please help me with that? Here is a code:

import numpy as np
import matplotlib.pyplot as plt

lw         = 2.5
lwn        = 1.7
beingsaved = plt.figure()
fnt_size   = 35
fnt_size   = 35
fnt_sizexx   = 35
csfont     = {'fontname':"Times New Roman", 'size': fnt_size}
csfontxx    = {'fontname':"Times New Roman", 'size': fnt_sizexx}
plt.rcParams["font.family"] = "Times New Roman"
plt.rcParams["axes.linewidth"]  = 0.5        

b= [16.72,22.27,16.24,13.69,16.64,33.46,10,22.11,35.79,32.53,25.,34,48.66,30.30,41.73]
a = [8.4, 6.6, 5.2, 4.0, 4.9, 10.9, 5.6, 5.2, 10.1, 7.1, 5.2, 9.1, 27.7, 6.5, 10.0]

plt.figure(figsize=(14,7.2))  

plt.plot(b,'-ob',linewidth=lw )


plt.xticks(rotation=90)

plt.xticks([0, 1,2,3, 4, 5, 6, 7,8,9,10,11,12,13,14], [f"{a[i]}" for i in range(15)])

plt.yticks([15,30,45], ["15", "30", "45"])

plt.xlabel('Percentage load (%)',**csfontxx)

plt.ylabel('Energy (%)',**csfont)

plt.xticks(**csfontxx) 

plt.yticks(**csfont)
plt.ylim(5, 50)
plt.xlim(0, 14)
plt.savefig('file.pdf', dpi=2000)
plt.show()

And here is the output in pdf format

enter image description here

  • Related