Skip to content

Instantly share code, notes, and snippets.

@kwang2049
Created December 16, 2021 13:04
Show Gist options
  • Save kwang2049/0f6f50e393eb4bd3e554fe0eb3f5a8a5 to your computer and use it in GitHub Desktop.
Save kwang2049/0f6f50e393eb4bd3e554fe0eb3f5a8a5 to your computer and use it in GitHub Desktop.
Showing how to change the default font when using the matplotlib from python.
from matplotlib import pyplot as plt
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.serif'] = ['Times New Roman'] + plt.rcParams['font.serif']
plt.rcParams['font.size'] = 20
x = [1, 2, 3]
y1 = [1, 2, 3]
y2 = [2, 3, 4]
plt.plot(x, y1, label='y1')
plt.plot(x, y2, label='y2')
plt.xlabel('x')
plt.ylabel('y')
plt.grid(linestyle='dashed')
plt.legend()
plt.savefig('figure.png', bbox_inches='tight')
plt.savefig('figure.pdf', bbox_inches='tight')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment