简体   繁体   English

使用 matplotlib 绘制一个简单的 3d numpy 数组

[英]Plotting a simple 3d numpy array using matplotlib

I want to plot the result of a numerical method for a three dimensional system of ODEs.我想为 ODE 的三维系统绘制数值方法的结果。 My output is in the form (let's suppose we have computed three steps):我的输出采用以下形式(假设我们已经计算了三个步骤):

import numpy as np
v= np.array([[1,2,3], [4,5,6], [7,8,9]])

Where the first value in every 3-tuple is the x coordinate, the second is y coordinate and the third is the z coordinate.每个 3 元组中的第一个值是 x 坐标,第二个是 y 坐标,第三个是 z 坐标。

I would like the most simple and efficient way of plotting these points on a 3D grid.我想要在 3D 网格上绘制这些点的最简单有效的方法。 The problem seems to be that the data should be formated like np.array([[1,4,7], [2,5,8], [3,6,9]]) .问题似乎是数据的格式应该像np.array([[1,4,7], [2,5,8], [3,6,9]])

You can plot the result in 3D like this:您可以像这样在 3D 中绘制结果:

import matplotlib.pyplot as plt, numpy as np
from mpl_toolkits.mplot3d import Axes3D

v= np.array([[1,2,3], [4,5,6], [7,8,9]])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(v[:,0],v[:,1],v[:,2])
plt.show()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM