Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How to Visualize a Dataset in 3D Scatter Plot

3D Scatter Plot

Description of 3D Scatter Plot

  • Description:
    A 3D scatter plot is a three-dimensional plot that allows you to visualize the relationships between three continuous variables. Each point in the plot represents a data point in 3D space, with the x, y, and z coordinates corresponding to the three variables.
Step-by-Step Process
  • Import the Required Libraries:
    Use Matplotlib to generate the plot.
    NumPy is useful for creating synthetic data or performing calculations for the plot.
  • Prepare the Data:
    Create or load a dataset with three continuous variables that you wish to plot.
  • Set Up the 3D Plot:
    Use Axes3D from Matplotlib to create a 3D plot.
  • Create the 3D Scatter Plot:
    Use scatter() to plot the data points in 3D space.
  • Customize the Plot:
    Add labels, titles, and customize the appearance of the plot (e.g., point colors, sizes).
  • Display the Plot:
    Use plt.show() to display the plot.
Sample Source Code
  • # Code for 3D Scatter plot

    import pandas as pd
    import matplotlib.pyplot as plt

    data = {
    'Years of Experience': [1, 2, 3, 5, 8, 10, 12, 15, 18, 20],
    'Age': [22, 24, 26, 30, 35, 40, 45, 50, 55, 60],
    'Salary': [35000, 40000, 45000, 60000, 75000, 85000, 95000, 110000, 120000, 130000]
    }
    df = pd.DataFrame(data)

    fig = plt.figure(figsize=(10, 7))
    ax = fig.add_subplot(111, projection='3d')

    # Create the 3D scatter plot
    ax.scatter(df['Years of Experience'], df['Age'], df['Salary'], c='b', marker='o')

    ax.set_xlabel('Years of Experience')
    ax.set_ylabel('Age')
    ax.set_zlabel('Salary')
    ax.set_title('3D Scatter Plot of Salary Dataset')

    plt.show()
Screenshots
  • 3D Scatter Plot