是否可以创建scipy.stats.skewnorm函数的二维图。在scipy网站上,它提供了一维版本,但我不确定如何将其转换为二维版本。任何帮助将不胜感激。
答案 0 :(得分:0)
要直接从这两个站点借用代码:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import skewnorm
fig = plt.figure(figsize=(15,15))
ax = fig.add_subplot(111, projection='3d')
#generate data from skewnorm dist
x,y = skewnorm.rvs(.2, size=1000),skewnorm.rvs(.2, size=1000)
hist, xedges, yedges = np.histogram2d(x, y, bins=4, range=[[0, 4], [0, 4]])
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25)
xpos = xpos.flatten('F')
ypos = ypos.flatten('F')
zpos = np.zeros_like(xpos)
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = hist.flatten()
ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b', zsort='average')
plt.show()