Rob*_*ert 5 python plot contour
我试图在运气不佳的情况下在python中重现这个情节:

它是目前在SuperMongo中完成的简单数字密度轮廓.我想放弃它支持Python,但我能得到的最接近的是:

这是通过使用hexbin().我怎么能让python情节与SuperMongo相似呢?我没有足够的代表发布图片,对不起链接.谢谢你的时间!
来自 SuperMongo 同伴 => 蟒蛇患者的简单等高线图示例:
import numpy as np
from matplotlib.colors import LogNorm
from matplotlib import pyplot as plt
plt.interactive(True)
fig=plt.figure(1)
plt.clf()
# generate input data; you already have that
x1 = np.random.normal(0,10,100000)
y1 = np.random.normal(0,7,100000)/10.
x2 = np.random.normal(-15,7,100000)
y2 = np.random.normal(-10,10,100000)/10.
x=np.concatenate([x1,x2])
y=np.concatenate([y1,y2])
# calculate the 2D density of the data given
counts,xbins,ybins=np.histogram2d(x,y,bins=100,normed=LogNorm())
# make the contour plot
plt.contour(counts.transpose(),extent=[xbins.min(),xbins.max(),
ybins.min(),ybins.max()],linewidths=3,colors='black',
linestyles='solid')
plt.show()
Run Code Online (Sandbox Code Playgroud)
产生一个漂亮的等高线图。
轮廓功能提供了很多花哨的调整,例如让我们手动设置级别:
plt.clf()
mylevels=[1.e-4, 1.e-3, 1.e-2]
plt.contour(counts.transpose(),mylevels,extent=[xbins.min(),xbins.max(),
ybins.min(),ybins.max()],linewidths=3,colors='black',
linestyles='solid')
plt.show()
Run Code Online (Sandbox Code Playgroud)
最后,在 SM 中可以在线性和对数尺度上绘制等高线图,所以我花了一些时间试图弄清楚如何在 matplotlib 中做到这一点。这是一个示例,当 y 点需要绘制在对数刻度上而 x 点仍然在线性刻度上时:
plt.clf()
# this is our new data which ought to be plotted on the log scale
ynew=10**y
# but the binning needs to be done in linear space
counts,xbins,ybins=np.histogram2d(x,y,bins=100,normed=LogNorm())
mylevels=[1.e-4,1.e-3,1.e-2]
# and the plotting needs to be done in the data (i.e., exponential) space
plt.contour(xbins[:-1],10**ybins[:-1],counts.transpose(),mylevels,
extent=[xbins.min(),xbins.max(),ybins.min(),ybins.max()],
linewidths=3,colors='black',linestyles='solid')
plt.yscale('log')
plt.show()
Run Code Online (Sandbox Code Playgroud)
这会产生一个看起来与线性非常相似的图,但有一个很好的垂直对数轴,这就是预期的:
你检查过matplotlib 的等高线图吗?