Search code examples
pythonmatplotlibseabornsize

How to change the size of the axis, ticks and labels for a plot in matplotlib


I'd like to Change the size of the axis, because the size of label in small

plt.figure(figsize=(16,8))
plt.plot(csv_reader["loss"],label='perte de formation')
plt.plot(csv_reader["val_loss"],label='perte de validation')
plt.yscale("log")
plt.xlabel('Epochs')
plt.ylabel('Log-loss')

plt.grid()
plt.legend()
plt.show()


Solution

  • You can change the font size globally:

    plt.rcParams['font.size'] = 12
    

    Or you can change it for individual components:

    plt.rc('axes', titlesize=12)
    
    plt.rc('axes', labelsize=12)
    
    plt.rc('xtick', labelsize=12)
    
    plt.rc('ytick', labelsize=12)