Use matplotlib to draw a scatter plot

  • 2020-09-28 08:59:22
  • OfStack

As shown below:


import matplotlib.pyplot as plt
import numpy as np
a = np.array([1,2,3,4])
b = np.array([1,2,3,4])
c = np.array([2,3,4,5])
d = np.array([2,3,4,5])
'''
figure Create a new painting window , Display the picture of the painting independently 
figsize  Represents the size of the new painting window 
dpi Is the resolution 
'''
plt.figure(figsize = (8,5),dpi = 80)
'''
 This is important , Need to focus on , Parameters have r,c,n3 A parameter 
 The point of using this function is to draw multiple images together 1 One painting window .
r    Said the number of rows 
c    The column line 
n    That's number one 
'''
plt.subplot(2,1,1)# said 1 Create two subgraphs under each drawing window, and select" 1 Two as a drawing 
plt.scatter(a,b,c = 'r')
plt.scatter(c,d,c = 'b')
# Will be in the first 1 I'm going to draw two colors. No 1 The sample points 
plt.subplot(2,1,2)
plt.scatter(a,b,c = 'black')
plt.show()

Related articles: