Use python to draw scatter plot python study notes 3

// Import necessary packages
from matplotlib import pyplot as plt
import numpy as np
//Define a function to generate scatter plots using certain columns of data in the document
def plotData(x1,y1,x2,y2):
plt.figure(figsize= (8,8))#Set the image size
plt.scatter(x1,y1,s=30,c='red',marker='o',alpha=1,label='gound truth')#Set
plt.scatter (x2,y2,s=30,c='blue',marker='o',alpha=1,label='predicted')
plt.title('error ')#image title
plt.xlabel('X(m )')#X axis name
plt.ylabel('Y(m)')
plt.legend(loc='upper right')#label
plt.savefig("examples.jpg")
plt.show()

//Read certain columns of data needed in the document
x1 = []
y1 = []
x2 = []
y2 = []
x1 = [float(l.split()[0]) for l in open("aaa. txt")]
y1 = [float(l.split()[1]) for l in open("aaa.txt")]
x2 = [float(l.split()[2]) for l in open(" aaa.txt")]
y2 = [float(l.split()[3]) for l in open("aaa.txt")]
plotData(x1,y1,x2,y2)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325560697&siteId=291194637