Note: if you choose a smaller number of values for np.linspace the plot is not as smooth.įor this plot, I set the third argument of np.linspace to 25 instead of 200. So, I used np.linspace again to create a list of 200 numbers equally spaced out between -2 and 2 which can be seen by looking at the z-axis (the vertical one). To get some up/down movement, you need to modify the z-axis. If you just plotted x and y now, you would get a circle.
![planeplotter 6.3.2 download planeplotter 6.3.2 download](https://rtl1090.com/wp-content/uploads/2019/03/109002-1-193x300.jpg)
I passed this to np.sin() and np.cos() and saved them in variables x and y. there is a linear distance between them all. I created the variable theta using np.linspace which returns an array of 200 numbers between -12 and 12 that are equally spaced out i.e. To avoid repetition, I won’t explain the points I have already made above about imports and setting up the Figure and Axes objects.
![planeplotter 6.3.2 download planeplotter 6.3.2 download](https://live.staticflickr.com/8659/15785010622_6b7e31df64_b.jpg)
# Create space of numbers for cos and sin to be applied to # Standard importsĪx = fig.add_subplot(111, projection='3d') Here’s an example of the power of 3D line plots utilizing all the info above. Check your Python version in Jupyter Notebook.You can change the orientation by clicking and dragging (right click and drag to zoom in) which can really help to understand your data.Īs this is a static blog post, all of my plots will be static but I encourage you to play around in your own Jupyter or IPython environment. One amazing feature of Jupyter Notebooks is the magic command %matplotlib notebook which, if ran at the top of your notebook, draws all your plots in an interactive window. On the other hand, they are more complicated since we are so used to 2D plots. In some ways 3D plots are more natural for us to work with since we live in a 3D world. All the functions you know and love such as ax.plot() and ax.scatter() accept the same keyword arguments but they now also accept three positional arguments – X, Y and Z. Then you need to pass projection='3d' which tells matplotlib it is a 3D plot.įrom now on everything is (almost) the same as 2D plotting. If you just want a single Axes, pass 111 to indicate it’s 1 row, 1 column and you are selecting the 1st one. You set up your Figure in the standard way fig = plt.figure()Īnd add a subplots to that figure using the standard fig.add_subplot() method. This imports a 3D Axes object on which a) you can plot 3D data and b) you will make all your plot calls with respect to. If you are not comfortable with Figure and Axes plotting notation, check out this article to help you.īesides the standard import matplotlib.pyplot as plt, you must also from mpl_toolkits.mplot3d import axes3d. If you are used to plotting with Figure and Axes notation, making 3D plots in matplotlib is almost identical to creating 2D ones.