Customized Scatter Plot

Using the iris dataset from scikit-learn, create a scatter plot showcasing petal length against petal width. For each data point, adjust the size of the point based on sepal length and its opacity based on sepal width.

Example Output:

Use the scatter method and utilize the s and alpha parameters.

import matplotlib.pyplot as plt
from sklearn.datasets import load_iris

def customized_scatter_plot():
    iris = load_iris()
    sizes =[:, 0] * 50
    alphas =[:, 1] / max([:, 1])
    plt.scatter([:, 2],[:, 3], s=sizes, c='blue', alpha=0.5)
    plt.xlabel("Petal Length (cm)")
    plt.ylabel("Petal Width (cm)")
    plt.title("Customized Scatter Plot for Iris Dataset")

# Example usage


© Let’s Data Science


Unlock AI & Data Science treasures. Log in!