[Python] how to display metadata in scatter plot in matplotlib?

Discussão em 'Python' iniciado por Stack, Abril 16, 2025.

  1. Stack

    Stack Membro Participativo

    I have a scatter plot. I want to add some metadata to each point in my scatter plot. looking at documentation , i found annotate function( matplotlib.pyplot.annotate) , has anyone use this or some other function , such that we can add metadata to each point or are there are similar libraries, like matplotlib, which can display metadata , on clicking/hovering individual points in the scatterplot?

    import matplotlib.pyplot as plt
    import numpy as np

    # Generate random data for x and y axes
    x = np.random.rand(20)
    y = np.random.rand(20)
    colors = np.random.rand(20)
    area = (30 * np.random.rand(20))**2 # point radii

    # Create the scatter plot
    plt.scatter(x, y, s=area, c=colors, alpha=0.5)

    # Add labels and title
    plt.xlabel('X-axis')
    plt.ylabel('Y-axis')
    plt.title('Scatter Plot Example')

    # Display the plot
    plt.show()

    Continue reading...

Compartilhe esta Página