Change Font Size in Matplotlib

python_tutorials

Introduction

Matplotlib is one of the most widely used data visualization libraries in Python. Much of Matplotlib’s popularity comes from its customization options – you can tweak just about any element from its hierarchy of objects.

In this tutorial, we’ll take a look at how to change the font size in Matplotlib.

Change Font Size in Matplotlib

There are a few ways you can go about changing the size of fonts in Matplotlib. You can set the fontsize argument, change how Matplotlib treats fonts in general, or even changing the figure size.

Let’s first create a simple plot that we’ll want to change the size of fonts on:

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(figsize=(12, 6))

x = np.arange(0, 10, 0.1)
y = np.sin(x)
z = np.cos(x)

ax.plot(y, color='blue', label='Sine wave')
ax.plot(z, color='black', label='Cosine wave')
fig.suptitle('Sine and cosine waves')

 

 

To finish reading, please visit source site