matplotlib - 极地到3d图表

时间:2014-10-30 08:00:44

标签: python matplotlib

能够使用matplotlib.pyplot绘制极坐标图(下面的代码),并尝试使用Axes3D从这些数据中绘制3D图表,但没有得到如何绘制的线索。

使用python 2.7。

import numpy as np
import matplotlib.pyplot as plt

fig   = plt.figure()
ax1   = fig.add_subplot(121, polar=True)
ax2   = fig.add_subplot(122, polar=True)
h     = [-20, -15, -10,  -5,   0,  -3, -10, -16, -20 ]         # horizontal data
v     = [  0,  -5, -15, -18, -20, -10,  -5,  -1,   0 ]         # vertical data
theta = np.linspace( 0, -2 * np.pi, 9 )                        # theta

x_range_1 = [ 90,  45,   0,  -45, -90, -135, 180, 135 ]
x_range_2 = [  0, -45, -90, -135, 180,  135,  90,  45 ]

ax1.set_rmax(0)
ax1.set_rmin(-40)
ax1.set_yticks(range(-40, 0, 5))
ax1.set_xlim(135)
ax1.set_xticklabels(x_range_1)

ax2.set_rmax(0)
ax2.set_yticks(range(-40, 0, 5))
ax2.set_xlim(135)
ax2.set_xticklabels(x_range_2)

ax1.grid( True )
ax1.plot( theta, h, label = 'horizontal' )

ax2.grid( True )
ax2.plot( theta, v, label = 'vertical' )

plt.show()

下面是我试过的3D代码.. ax1显示水平极坐标图,ax2是3D(但是,我确信3D不是正确的......)

from mpl_toolkits.mplot3d import axes3d
import numpy as np
import matplotlib.pyplot as plt

fig   = plt.figure()
ax1   = fig.add_subplot(121, polar=True)
ax2   = fig.add_subplot(122, projection='3d')
h     = [ -20, -15, -10,  -5,   0,  -3, -10, -16, -20 ]        # horizontal data
v     = [   0,  -5, -15, -18, -20, -10,  -5,  -1,   0 ]        # vertical data
theta = np.linspace( 0, -2 * np.pi, 9 )                        # theta

x_range_1 = [ 90,  45,   0,  -45, -90, -135, 180, 135 ]
x_range_2 = [  0, -45, -90, -135, 180,  135,  90,  45 ]

ax1.set_rmax(0)
ax1.set_rmin(-40)
ax1.set_yticks(range(-40, 0, 5))
ax1.set_xlim(135)
ax1.set_xticklabels(x_range_1)

ax1.grid( True )
ax1.plot( theta, h, label = 'horizontal' )

ax2.grid( True )
R,P = np.meshgrid( h, theta ) 
X,Y = R * np.cos(P), R * np.sin(P)               # transform [R,P] to cartesian system 
Z   = v                                          # ( ( R**2 - 1 )**2 )

ax2.plot_surface( X, Y, Z, label = '3d' )

plt.show()

以下是上述程序的输出 https://docs.google.com/file/d/0Bw8wTgcsK-k8d3JvRmVuUUxfSE0/edit CURRENT_OUTPUTs

以下是我实际期待的那种图表, EXPECTED_OUTPUT https://docs.google.com/file/d/0Bw8wTgcsK-k8aFZhcnZPYmJTdkk/edit

提前感谢您的帮助。

0 个答案:

没有答案