Вопрос

I have a data set created by....

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()))

I would like to create 3d graphs of count vs pairs of i, j, and k (so 3 graphs total). I have looked through examples here: http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#surface-plots, but they all seem to be creating values on the fly. How do I plot the surface or mesh graphs that I want?

Это было полезно?

Решение

I've got to dash but this is how I would attempt to plot your data - the count vs (i,j) example - see the index slicing on the last line or so. Happy to take a further look if you need.

>>> 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()
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top