Created
December 16, 2021 13:04
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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