2013-11-21 5 views
3

커브의 플롯을 말하십시오. x^5 + x^4 + x^3 + x + 1 각 포인트 x는 정규 분포에서 취했습니다. 나는 평균의 벡터와 시그마 값의 벡터를 가지고있다.확률 밀도 플로팅

matplotlib.pyplot을 사용하면 평균값을 플로팅 할 수 있으며 평균 주위의 분산을 플로팅 할 수는 있지만 우아한 모양이 아니며 출력이 복잡해집니다. Here dashed yellow line is the variance and red line is the mean.

밀도 함수를 플로팅하는 다른 방법이 있습니까?

mu = [mu1, mu2, mu3..] 
sigma = [sigma1, sigma2, sigma3..] 
variance1 = [mu1+sigma1, mu2+sigma2, ..] 
variance2 = [mu1-sigma1, mu2-sigma2,..] 


import matplotlib.pyplot as plt 
plt.plot(x,mu) 
plt.plot(x,variance1, ls = "--") 
plt.plot(x,variance2,ls="--") 

x는 입력 배열은 다음과 같습니다

나는 이런 식으로 뭔가를 사용했다.

+2

'imshow' : 예를 들면? 바? 우리는 당신의 그래프, 다른 요소들, 그리고 예제가 어떻게 보이는지에 대해 더 많이 알 필요가 있습니다. 시작 코드로 예제 코드도 도움이 될 것입니다. –

답변

3

가장 일반적인 방법은 fill_between을 사용하여 신뢰 구간 사이의 영역을 음영 처리하는 것입니다.

import numpy as np 
np.random.seed(1977) 
import matplotlib.pyplot as plt 

# Generate data... 
x_obs = np.linspace(-2, 2, 20) 
true_model = [0.2, -0.1, 4, 2, 1, 0] 

noise = np.random.normal(0, 5, x_obs.shape) 
y_obs = np.polyval(true_model, x_obs) + noise 

# Fit to a 5-th order polynomial 
fit_model = np.polyfit(x_obs, y_obs, 5) 

x = np.linspace(-3, 3, 100) 
y_true = np.polyval(true_model, x) 
y_pred = np.polyval(fit_model, x) 

# Made up confidence intervals (I'm too lazy to do the math...) 
high_bound = y_pred + 3 * (0.5 * x**4 + 3) 
low_bound = y_pred - 3 * (0.5 * x**4 + 3) 

# Plot the results... 
fig, ax = plt.subplots() 
ax.fill_between(x, high_bound, low_bound, color='gray', alpha=0.5) 
ax.plot(x_obs, y_obs, 'ko', label='Observed Values') 
ax.plot(x, y_pred, 'k--', label='Predicted Model') 
ax.plot(x, y_true, 'r-', label='True Model') 
ax.legend(loc='upper left') 
plt.show() 

enter image description here

+0

고마워요. 이것은 내가 찾고 있었던 바로 그 것이다. –

관련 문제