基于矩阵的python中的3d图

时间:2013-02-20 17:30:37

标签: python dataset mplot3d

我有一个由....创建的数据集

import random

count = []
for i in range(1, 4):
    for j in range(3, 6):
        for k in range(15,19):
            count.append((i, j, k, random.random()))

我想创建countijk对的三维图表(总共3个图表)。我在这里查看了示例:http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#surface-plots,但它们似乎都在动态创建值。如何绘制我想要的曲面图或网格图?

1 个答案:

答案 0 :(得分:1)

我必须冲刺,但这是我尝试绘制数据的方式 - count vs (i,j)示例 - 查看最后一行左右的索引切片。如果您需要,很高兴再看看。

>>> from mpl_toolkits.mplot3d import Axes3D
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> import random
>>> 
>>> count = []
>>> for i in range(1, 4):
...     for j in range(3, 6):
...         for k in range(15,19):
...             count.append((i, j, k, random.random()))
...             
...         
...     
... 
>>> data = np.array(count)
>>> fig = plt.figure()
>>> ax = fig.gca(projection='3d')
>>> 
>>> # I think this is the sort of thing you want:
>>> 
>>> ax.plot_trisurf(data[:,0], data[:,1], data[:,3])
/usr/local/lib/python2.7/dist-packages/matplotlib/delaunay/triangulate.py:103: DuplicatePointWarni
ng: Input data contains duplicate x,y points; some values are ignored.
  DuplicatePointWarning,
<mpl_toolkits.mplot3d.art3d.Poly3DCollection object at 0x46e8390>
>>> plt.show()