【发布时间】:2016-07-21 04:11:26
【问题描述】:
我正在尝试使用 matplotlib 在 Python 中创建 3D 线框。
然而,当我开始绘制实际的图表时,线框以错误的方式连接,如下图所示。
如何强制 matplotlib 沿某个轴加入线框?
我的代码如下:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
def rossler(x_n, y_n, z_n, h, a, b, c):
#defining the rossler function
x_n1=x_n+h*(-y_n-z_n)
y_n1=y_n+h*(x_n+a*y_n)
z_n1=z_n+h*(b+z_n*(x_n-c))
return x_n1,y_n1,z_n1
#defining a, b, and c
a = 1.0/5.0
b = 1.0/5.0
c = 5
#defining time limits and steps
t_0 = 0
t_f = 32*np.pi
h = 0.01
steps = int((t_f-t_0)/h)
#3dify
c_list = np.linspace(5,10,6)
c_size = len(c_list)
c_array = np.zeros((c_size,steps))
for i in range (0, c_size):
for j in range (0, steps):
c_array[i][j] = c_list[i]
#create plotting values
t = np.zeros((c_size,steps))
for i in range (0, c_size):
t[i] = np.linspace(t_0,t_f,steps)
x = np.zeros((c_size,steps))
y = np.zeros((c_size,steps))
z = np.zeros((c_size,steps))
binvar, array_size = x.shape
#initial conditions
x[0] = 0
y[0] = 0
z[0] = 0
for j in range(0, c_size-1):
for i in range(array_size-1):
c = c_list[j]
#re-evaluate the values of the x-arrays depending on the initial conditions
[x[j][i+1],y[j][i+1],z[j][i+1]]=rossler(x[j][i],y[j][i],z[j][i],t[j][i+1]-t[j][i],a,b,c)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_wireframe(t,x,c_array, rstride=10, cstride=10)
plt.show()
我将其作为输出:
另一个角度的相同输出:
而我希望线框沿着波峰连接。抱歉,我不能给你我想看的图片,这是我的问题,但我想它更像是教程图片。
【问题讨论】:
-
尝试
scatter来解决它。当我将情节更改为ax.scatter(x,y,z_array,s=0.1)时,我可以看到一些看起来像 6 个堆叠的 Roessler 吸引子被挤压成 xy 平面的东西
标签: python numpy matplotlib 3d mplot3d