IT/Python

matplotlib 에서 latex 쓰기

준나이 2022. 11. 19. 05:00

 

import numpy as np
import numpy.random as rnd
import scipy.stats
import scipy.special
import matplotlib
import matplotlib.pyplot as plt

# 다음과 같이 선언
matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]
matplotlib.rc('text', usetex=True)

# 다음과 같이 사용
eps_std = 0.63
plotv = np.linspace(-2, 3, 500)
p_v_c_s = np.vstack([scipy.stats.norm.pdf(plotv, loc=l, scale=eps_std) for l in [0, 1]]).T
lines = plt.plot(plotv, p_v_c_s)
plt.legend(lines, ['S=0', 'S=1'])
plt.xlabel('$v$')
plt.ylabel('$p(v|s)$')
plt.title(f"Density of observing $V$ given $S$, $\sigma={eps_std}$")

 

출력되는 이미지



'IT > Python' 카테고리의 다른 글

np.unravel_index() 설명 및 사용예시 정리  (0) 2022.11.15
python encoding  (0) 2018.10.15