我尝试做一个2D直方图,并通过一种插值获得“平滑”的图像.因此,我将plt.hist2d和plt.imshow结合起来
import matplotlib.pyplot as plt import numpy as np data = np.loadtxt("parametre_optMC.dat",skiprows=50,usecols=(1,2)) h,x,y,p = plt.hist2d(data[:,0],data[:,1],bins = 20) plt.imshow(h,origin = "lower",interpolation = "gaussian") plt.savefig("test.pdf")
正如您在下面的图片中看到的那样,这两个图是叠加的,这是我需要帮助的问题
添加clf有效,但我失去了轴尺寸:
import matplotlib.pyplot as plt import numpy as np data = np.loadtxt("parametre_optMC.dat",bins = 20) plt.clf() plt.imshow(h,interpolation = "gaussian") plt.savefig("test.pdf")
解决方法
也许最好绘制核密度估计值?
import seaborn as sns import numpy as np import matplotlib.pyplot as plt data = np.random.multivariate_normal([0,[(1,.6),(.6,1)],100) f,ax = plt.subplots(figsize=(7,7)) sns.kdeplot(data,shade=True,ax=ax)