Data Visualization with Matplotlib

16 / 20

Getting Stared with Matplotlib - Create a Scatter Plot using Pyplot

Scatter plots show how much one variable is affected by another. The relationship between two variables is called their correlation.

INSTRUCTIONS
  • Import pyplot

    import matplotlib.<< your code goes here >> as plt
    
  • Import rand to generate random values for the x-, and y-coordinates

    from numpy.random import << your code goes here >>
    
  • Now we will call the scatter module to generate the scatter plot.

    for color in ['red', 'green', 'blue']:
        n = 100
        x, y = rand(2, n)
        scale = 500.0 * rand(n) ** 5
        plt.<< your code goes here >>(x, y, s=scale, c=color, alpha=0.3, edgecolors='blue')
    
    plt.grid(True)
    plt.show()
    

    Here, s is a scalar or array-like shape, and is an option argument. c defines the color. alpha defines the alpha blending value, or the transparency. edgecolor is the line color of the shapes. grid displays the plot grid.

Get Hint See Answer


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...