1

So currently, I have all these coordinates and so it's quite easy to create a 3D scatter plot of all the combination of coordinates.

fig = plt.figure(figsize=(20,10)) ax = plt.axes(projection='3d') z = numpy.transpose(z_coords_row)[0:100] x = numpy.transpose(x_coords_row)[0:100] y = numpy.transpose(y_coords_row)[0:100] plt.xticks(numpy.arange(-1.5, 1.5, .25)) plt.yticks(numpy.arange(-1.5, 1.5, .5)) ax.scatter(x, y, z,s=1) ax.view_init(elev=10., azim=45) 

This code gives me a result as so: https://i.sstatic.net/KKw1D.png

I've run into lots of problems trying to connect each point with a line to the next point in sequence. How do I go about connecting each point with the next in the array so that it's a smooth line graph?

3
  • I know nothing about 3d charts... but i know this process is called interpolation. According to wiki, interpolation is a method of constructing new data points within the range of a discrete set of known data points. Maybe this new keyword will help you. Commented Jun 8, 2016 at 20:08
  • From what I've used so far though, the interpolation only works for 1D and only gives more sets of points rather than a line though? Anyone feel free to correct me if I'm wrong Commented Jun 8, 2016 at 20:09
  • docs.scipy.org/doc/scipy-0.14.0/reference/generated/… Commented Jun 8, 2016 at 20:14

1 Answer 1

3

If you have enough points using only your coordinates I think what you are looking for is plot3D. If you need it more smooth line it might be worth looking into scipy.interpolate.RegularGridInterpolator which would help generate more points, which you could then insert into plot3D.

Example of usage of plot3D:

import numpy import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure(figsize=(20,10)) ax = plt.axes(projection='3d') z_coords_row = numpy.sin(numpy.linspace(0,2*numpy.pi,100))+5 x_coords_row = numpy.sin(numpy.linspace(0,2*numpy.pi,100)) y_coords_row = numpy.cos(numpy.linspace(0,2*numpy.pi,100)) z = numpy.transpose(z_coords_row)[0:100] x = numpy.transpose(x_coords_row)[0:100] y = numpy.transpose(y_coords_row)[0:100] plt.xticks(numpy.arange(-1.5, 1.5, .25)) plt.yticks(numpy.arange(-1.5, 1.5, .5)) ax.scatter(x, y, z,s=5) ax.plot3D(x,y,z) ax.view_init(elev=10., azim=45) 

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

When I try using the ax.plot3D(x,y,z), it gives me the error: 'ValueError: third arg must be a format string'. Am I using it wrong?
@JesseBatson Could you verify that the type of your ax is matplotlib.axes._subplots.Axes3DSubplot'?
It verified that <class 'matplotlib.axes._subplots.Axes3DSubplot'>
I don't know if this matters, but I am also using Python 2.7 in case you happen to be using a different version?
@JesseBatson The code above works on both 3.x and 2.7. Could you try to run the exact piece of code above as a standalone script (adding plt.show() at the end) or running it in a jupyter notebook with %matplotlib inline.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.