-3

I want to use python to plot some specific points in 3D given their coordinates. I want to use the matplotlib library but I'm not sure if there's an easy way of doing this.

Let's say I want to plot the following points: (1,0,0) (2,2,2) (-1,2,0) (1,2,1)

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Welcome to StackOverflow. Please take the [tour](http://stackoverflow.com/tour) have a look around, and read through the [HELP center](http://stackoverflow.com/help), then read [How to Ask Question](http://stackoverflow.com/help/how-to-ask), [What types of questions should I avoid asking?](http://stackoverflow.com/help/dont-ask) and provide a [MCVE : Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). If people around can easily read and understand what you mean, or what the problem is, they'll be more likely willing to help :) – Dwhitz Jun 13 '17 at 07:54
  • See https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#mplot3d-tutorial – Bart Jun 13 '17 at 08:03

1 Answers1

2

Since some of the examples around are overly complicated, a minimal example for a 3D scatter plot in matplotlib would look like this:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

fig, ax = plt.subplots(subplot_kw=dict(projection='3d') )

points = [(1,0,0), (2,2,2), (-1,2,0), (1,2,1)]
x,y,z = zip(*points)
ax.scatter(x,y,z, s=100)
plt.show()

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712