

The range and interval of values on the axes are set by default based on the input values. We have used the parameters marker and c to change the style and color of the individual points Modifying the axes limits and ticks Let us begin by changing the color and style of the marker ax.scatter(xs,ys,zs, marker="x", c="red") We can alter the appearance of the markers to make them more expressive. ax.set_xlabel("Atomic mass (dalton)")Īx.set_zlabel("Atomic velocity (x10⁶ m/s)")Īs we have seen in our previous examples, the marker for each point, by default, is a filled blue circle of constant size. We can set a label for each axis in a 3D plot by calling the methods set_xlabel, set_ylabel and set_zlabel on the axes object. Let us now add labels to each axis on the plot. fig = plt.figure(figsize=(4,4))Īx.scatter(2,3,4) # plot the point (2,3,4) on the figureĪs you can see, a single point has been plotted (in blue) at (2,3,4). To plot a single point, we will use the scatter()method, and pass the three coordinates of the point. Step 3: Plot the pointĪfter we create the axes object, we can use it to create any type of plot we want in the 3D space. Note that these two steps will be common in most of the 3D plotting you do in Python using Matplotlib. We will use this axis object ‘ax’ to add any plot to the figure. We then create a 3-D axis object by calling the add_subplot method and specifying the value ‘3d’ to the projection parameter. Here we are first creating a figure of size 4 inches X 4 inches. Step 2: Create figure and axes fig = plt.figure(figsize=(4,4))Īx = fig.add_subplot(111, projection='3d') For versions 3.2.0 and higher, you can plot 3D plots without importing mpl_3D. Note that the second import is required for Matplotlib versions before 3.2.0. It is, otherwise, not used anywhere else. The second import of the Axes3D class is required for enabling 3D projections. The first one is a standard import statement for plotting using matplotlib, which you would see for 2D plotting as well. Step 1: Import the libraries import matplotlib.pyplot as plt

Let us begin by going through every step necessary to create a 3D plot in Python, with an example of plotting a point in 3D space.
