难以绘制二维lognorm曲面

时间:2018-10-25 04:58:02

标签: python matplotlib scipy

这是我正在使用的代码,我还附加了输出。我想将二维lognorm函数绘制为3d曲面,上面的代码应该这样做,但是输出会导致整个平面倾斜,而不仅仅是z值倾斜。任何帮助或建议,将不胜感激。

dx = 90 - (-90)
dy = 90 - (-90)
c = [dx + dx/2.0, dy+dy/2.0]
z = np.zeros((400, 400))
x = np.linspace(-90, 90, 400)
y = x.copy()
for i in range(len(x)):
    for j in range(len(y)):
        p =[x[i], y[j]]
        d = math.sqrt((p[0]-c[0])**2 + (p[1]-c[1])**2)
        t = d

        z[i][j] = lognorm.pdf(t, 1.2)




fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')
ax.plot_surface(x,y, z, cmap = 'viridis')



plt.show()

输出所提供的代码

enter image description here

理想情况下,我希望它看起来像这样。 this is the image here

1 个答案:

答案 0 :(得分:0)

我认为您想绘制3D表面,这是一个示例:

#!/usr/bin/python3
# 2018/10/25 14:44 (+0800)
# Plot a 3D surface 

from scipy.stats import norm, lognorm
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

xy = np.linspace(-5, 5, 400)
xx, yy = np.meshgrid(xy)
t = np.sqrt(xx**2 + yy**2)
zz = lognorm.pdf(t, 1.2)

fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')
ax.plot_surface(xx,yy, zz, cmap = 'viridis')

plt.show()

enter image description here