1

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?

3
  • You can help people who are looking at the question by putting actual code that creates the dataset (or a representative dataset) in your question. It currently looks like matlab notation or similar. Ideally I would be able to paste it into my interpreter and then happily mess around with mplot3d with your data. Commented Feb 20, 2013 at 18:22
  • 1
    @MrE does that help? I am now able to use ax.tri_surf matplotlib.org/mpl_toolkits/mplot3d/… but I am getting duplicate value errors. I would like to be able plot multiple points per x,y coordinate in 3d space. Commented Feb 20, 2013 at 18:51
  • Thanks, that's great. I'm just updating my matplotlib (the function is new it seems) but I'm pretty sure the answer is that you will have to do a scatter plot as you can't have a surface with multiple values per (x,y) coordinate in the same way you can't have a line with two values for one x coordinate Commented Feb 20, 2013 at 19:10

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

E Thanks! I was able to play around it some more and get a scatter plot like you said. I want to work on coloring the dots a bit and stuff so I can visualize it better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.