2015-07-04 28 views
0

我想绘制如下图所示的分布 - 分布的尾部。我已经尝试过但并不完全去那里:使用Python重现一个图中提供的两个分布

import matplotlib.pyplot as plt 
import numpy as np 
import matplotlib.mlab as mlab 
import math 

mean1 = 0 
variance1 = 1 
sigma1 = math.sqrt(variance1) 
x = np.linspace(-3,3.5,100, endpoint=True) 
plt.plot(x,mlab.normpdf(x,mean1,sigma1)) 

mean2 = 0.4 
variance2 = 2 
sigma2 = math.sqrt(variance2) 
y = np.linspace(-4,3.5,100, endpoint=False) 
plt.plot(x,mlab.normpdf(y,mean2,sigma2)) 
##plt.axis('off') 
plt.yticks([]) 
plt.xticks([]) 
plt.show() 

任何建议都会很感激?

enter image description here

回答

3

你想fill_between

import matplotlib.pyplot as plt 
import numpy as np 
import matplotlib.mlab as mlab 
import math 

mean1 = 0 
variance1 = 1 
sigma1 = math.sqrt(variance1) 
x = np.linspace(-3,3.5,100, endpoint=True) 
y1 = mlab.normpdf(x,mean1,sigma1) 
fig, ax = plt.subplots() 
ax.plot(x,y1) 

mean2 = 0.4 
variance2 = 2 
sigma2 = math.sqrt(variance2) 
y = np.linspace(-4,3.5,100, endpoint=False) 
y2 = mlab.normpdf(y,mean2,sigma2) 
ax.plot(x,y2) 


ax.fill_between(x[:30], y1[:30], color='blue') 
ax.fill_between(x[:30], y2[:30], color='green') 
ax.fill_between(x[-30:], y1[-30:], y2[-30:], color='red', alpha=0.5) 
ax.set_yticks([]) 
ax.set_xticks([]) 
plt.savefig('fill_norms.png') 
plt.show() 

enter image description here

这是一个疯狂的简单的例子 - 见cookbook examples,并期待在where条款;你的填充高光可以适应你正在绘制的线条的变化(例如,一个自动的红色fill_ between every BADTHING超过GOODTHING,而不需要找出索引(在这个例子中是30或者-30))。

+0

我的OP不够清楚。我主要想要在右侧获得尾巴分布 – Ibe

+2

你的意思是你的Y值是错的吗?这是一个统计问题,而不是编程问题。 – cphlewis

+0

问题是 - 统计和颜色尾巴。修正了一切,但只有剩下的东西是如何像样本图一样对y1和y2的右侧颜色进行着色? – Ibe

相关问题