IT정보/코딩

matplotlib 수식 폰트 바꾸기 & 수식 폰트와 일반 폰트 혼용

미친 통계학자 2021. 6. 30. 20:00

논문에 넣을 그림을 그리는데 수식이 이쁘게 표현되지 않아 방법을 찾아보았습니다.

또한, 수식 폰트와 일반 폰트를 혼용해서 쓰는 방법도 찾았습니다.

 

(1) 첫 번째는 수식 폰트와 일반 폰트를 혼용해서 쓰는 경우입니다.

network라는 글자만 일반 폰트를 사용하려면 \mathrm{network} 이런 식으로 코드를 작성하면 됩니다.

import matplotlib.pyplot as plt
plt.rcParams['axes.unicode_minus'] = False

plt.plot(1)
plt.xlabel('$x_{network}$',size=20)
plt.ylabel('$x_{\mathrm{network}}$',size=20)

(2) 두 번째는 수식 폰트를 바꾸는 방법입니다.

폰트를 바꾸지 않으면 위 그림처럼 x가 수식 표현 같지가 않습니다.

plt.rcParams['mathtext.fontset'] = 'cm' 으로 수식 폰트를 cm으로 바꿔주면 수식 표현과 비슷하게 바뀌는 걸 확인할 수 있습니다.

plt.rcParams['mathtext.fontset'] = 'cm'

plt.plot(1)
plt.xlabel('$x_{network}$',size=20)
plt.ylabel('$x_{\mathrm{network}}$',size=20)

 

※ 참고문헌

https://matplotlib.org/3.3.0/users/dflt_style_changes.html#math-text

 

Changes to the default style — Matplotlib 3.3.0 documentation

The default font has changed from "Bitstream Vera Sans" to "DejaVu Sans". DejaVu Sans has additional international and math characters, but otherwise has the same appearance as Bitstream Vera Sans. Latin, Greek, Cyrillic, Armenian, Georgian, Hebrew, and Ar

matplotlib.org

https://stackoverflow.com/questions/43714059/matplotlib-how-to-access-internal-cm-font

 

matplotlib: how to access internal cm font?

I am using python2.7 on Windows 10, with Anaconda, and having some issue configuring font. First of all, I am aware that this issue is quickly resolved if I install required fonts. But I want to k...

stackoverflow.com

 

반응형