Breaking News

# Scatter Plot using Matplotlib

5. Scatter Plot

### Plot Scatter Plot Using Matplotlib¶

With Pyplot, you can use the scatter() function to draw a scatter plot. The scatter() function plots one dot for each observation. It needs two arrays of the same length, one for the values of the x-axis, and one for values on the y-axis:

In [3]:
import matplotlib.pyplot as plt
x = [5, 7, 8, 5, 6, 7, 9, 2, 3, 4, 4, 4, 2, 6, 3, 6, 8, 6, 4, 1]
y = [7, 4, 3, 9, 1, 3, 2, 5, 2, 4, 8, 7, 1, 6, 4, 9, 7, 7, 5, 1]
plt.scatter(x,y)
plt.show()


### Multi Scatter Plot¶

In [20]:
import matplotlib.pyplot as plt
import numpy as np
x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
z = np.array([100,105,84,105,90,99,90,95,94,100,79,112,91])
plt.scatter(x, y)
plt.scatter(x, z)
plt.show()

In [21]:
X = [5,10,15,20,25,30,35,40]
Y = [15,67,45,14,97,69,55,35]
Z = [98,34,12,63,57,39,82,78]
plt.axis([0,50,0,120])
plt.title("Suicdes In India",fontsize=20,fontname='Times New Roman',color='#0B30EC',weight='bold')
plt.xlabel("Year",fontsize=20,fontname='Times New Roman',color='#0B30EC',weight='bold')
plt.ylabel("Total Suicides",fontsize=20,fontname='Times New Roman',color='#0B30EC',weight='bold')
plt.scatter(X,Y,label='Sensro 1')
plt.scatter(X,Z,label='Sensor 2')
plt.legend()
plt.show()

In [4]:
import matplotlib.pyplot as plt
x = [5, 7, 8, 5, 6, 7, 9, 2, 3, 4, 4, 4, 2, 6, 3, 6, 8, 6, 4, 1]
y = [7, 4, 3, 9, 1, 3, 2, 5, 2, 4, 8, 7, 1, 6, 4, 9, 7, 7, 5, 1]
plt.scatter(x,  y, s=100, c='green', marker='x')
plt.show()

In [10]:
import matplotlib.pyplot as plt
x = [5, 7, 8, 5, 6, 7, 9, 2, 3, 4, 4, 4, 2, 6, 3, 6, 8, 6, 4, 1]
y = [7, 4, 3, 9, 1, 3, 2, 5, 2, 4, 8, 7, 1, 6, 4, 9, 7, 7, 5, 1]
plt.scatter(x, y, s=100, c='red', edgecolor='black', linewidth=1)
plt.show()

In [15]:
import matplotlib.pyplot as plt
x = [5, 7, 8, 5, 6, 7, 9, 2, 3, 4, 4, 4, 2, 6, 3, 6, 8, 6, 4, 1]
y = [7, 4, 3, 9, 1, 3, 2, 5, 2, 4, 8, 7, 1, 6, 4, 9, 7, 7, 5, 1]
colors = [7, 5, 9, 7, 5, 7, 2, 5, 3, 7, 1, 2, 8, 1, 9, 2, 5, 6, 7, 5]
sizes = [209, 486, 381, 255, 191, 315, 185, 228, 174,
538, 239, 394, 399, 153, 273, 293, 436, 501, 397, 539]
plt.scatter(x,  y, s=sizes, c=colors, cmap='Reds', edgecolor='black',linewidth=1, alpha=0.75)
plt.show()

In [18]:
import matplotlib.pyplot as plt
x = [5, 7, 8, 5, 6, 7, 9, 2, 3, 4, 4, 4, 2, 6, 3, 6, 8, 6, 4, 1]
y = [7, 4, 3, 9, 1, 3, 2, 5, 2, 4, 8, 7, 1, 6, 4, 9, 7, 7, 5, 1]
colors = [7, 5, 9, 7, 5, 7, 2, 5, 3, 7, 1, 2, 8, 1, 9, 2, 5, 6, 7, 5]
sizes = [209, 486, 381, 255, 191, 315, 185, 228, 174,
538, 239, 394, 399, 153, 273, 293, 436, 501, 397, 539]
plt.scatter(x,  y, s=sizes, c=colors, cmap='Reds', edgecolor='black',linewidth=1, alpha=0.75)
cbar = plt.colorbar()
cbar.set_label('Satisfaction level')
plt.tight_layout()
plt.show()


## Groupby in Pandas – Data Science Tutorials

14- Groupby Groupby in Pandas¶Pandas groupby is used for grouping the data according to the …