
If we want to view the 3D plot from different angles, we can take the help of matplotlib’s mplot3d library.

We also passed the color argument in the plot3D() function to specify the color to be red. Following the same, we have chosen the value of x to be the sine and the value of y to be the cosine function of z.We then choose values of z as discrete values using the linspace() function of NumPy.Here we passed the parameter projection=’3d’.This makes the program understand that the required plot is a three-dimensional plot. We have identified the dimension of the figure as (8,8). Basically, this tells the program about creating the figure specifying its dimension, etc. Hence we have imported matplotlib.pyplot as plt,numpy as np, and mpl_toolkits as mplot3d. We have imported the name of the libraries with different names so that it becomes convenient for us to write the code.We have imported essential libraries in the subsequent lines and created or initialized the figure. It enables the interactive mode, and now we can interact with the object and rotate it easily. In the above example, we have used a %matplotlib notebook.Example %matplotlib notebookĪx = fig.add_subplot(111, projection='3d') Let us see with the below example how we can rotate a 3D plot using matplotlib in python. Sometimes, we need to visualize the 3D plot from a different point of view, and in that can, a rotating 3D plot would be much better. Rotate 3D Scatter Plot using Matplotlib’s Toolkit mplot3d At last, we called the show() method to visualize the plot. We used the scatter3D() method and gave the generated data as an argument. It will set the axis for 3-dimensional space. These data points will represent the 3-dimensions of a scatter plot.Īfter that, the axes() method is called, and given an argument, projection is equal to 3d. Scatter_plot = ax.scatter3D(x, y, z, c = (x+y+z), cmap = color_map)įirst of all, we have imported the required libraries like NumPy, Matplotlib, and mplot3d, and then we generated data using arange(), sin(), and cos() method with the help of NumPy. The color bar is generally displayed with a dedicated axis. If we want to map the scaler values with colors, we can use the color bar. 3D Scatter Plot with Color-bar using Matplotlib’s Toolkit mplot3d

Now, we used scatter3D() method and gave the generated data as an argument. It will create a blank figure of the size figsize.Īfter that, the axes() method is called, and given an argument, projection is equal to 3d. Next, we called the figure() method and gave an argument figsize. These data points will represent the 3-dimensions of a scatter plot. Example from mpl_toolkits import mplot3dįirst of all, we have imported the required libraries like NumPy, matplotlib, and mplot3d, and then we generated data using arange(), sin(), and cos() method with the help of NumPy. Let’s see the above steps with an example.

Import the required libraries such as NumPy, pandas, matplotlib, mplot3d.Here, the data points are plotted along the x-axis, y-axis, and z-axis (in the case of 3 dimensions), and by default, these data points are denoted using points.Ī 3-dimension scatter plot is used to visualize complex data points in a much simpler form with the help of cartesian coordinates.Ī simple approach to plotting a 3D scatter plot is:

Scatter Plot is also similar to all other plots. If an object has width, height, and depth, it is a 3D object in much simpler words. 3D or 3 Dimensional, if an object has 3 dimensions (or parameters) to measure its position (or location), it is called a 3D object. Change the View Angle of the 3D Scatter PlotģD Scatter Plot using Matplotlib’s Toolkit mplot3dīefore going into too much technical, let’s recall the basic understanding of 3D.Rotate 3D Scatter Plot using Matplotlib’s Toolkit mplot3d.3D Scatter Plot with Color-bar using Matplotlib’s Toolkit mplot3d.3D Scatter Plot using Matplotlib’s Toolkit mplot3d.
