How to increase plt.title font size?
import matplotlib.pyplot as plt
plt.figtext(.5,.9,'Temperature', fontsize=100, ha='center')
plt.figtext(.5,.8,'Humidity',fontsize=30,ha='center')
plt.show()
Probably you want this. You can easily tweak the fontsize
of both and adjust there placing by changing the first two figtext
positional parameters.
ha is for horizontal alignment
Alternatively,
import matplotlib.pyplot as plt
fig = plt.figure() # Creates a new figure
fig.suptitle('Temperature', fontsize=50) # Add the text/suptitle to figure
ax = fig.add_subplot(111) # add a subplot to the new figure, 111 means "1x1 grid, first subplot"
fig.subplots_adjust(top=0.80) # adjust the placing of subplot, adjust top, bottom, left and right spacing
ax.set_title('Humidity',fontsize= 30) # title of plot
ax.set_xlabel('xlabel',fontsize = 20) #xlabel
ax.set_ylabel('ylabel', fontsize = 20)#ylabel
x = [0,1,2,5,6,7,4,4,7,8]
y = [2,4,6,4,6,7,5,4,5,7]
ax.plot(x,y,'-o') #plotting the data with marker '-o'
ax.axis([0, 10, 0, 10]) #specifying plot axes lengths
plt.show()
Output of alternative code:
PS: if this code give error like ImportError: libtk8.6.so: cannot open shared object file
esp. in Arch like systems
. In that case, install tk
using sudo pacman -S tk
or Follow this link
fontsize can be assigned inside dictionary fontdict which provides additional parameters fontweight, verticalalignment , horizontalalignment
The below snippet should work
plt.title('Temperature \n Humidity', fontdict = {'fontsize' : 100})