使用python绘制散点图

// Import necessary packages
from matplotlib import pyplot as plt
import numpy as np
//定义一个函数实现利用文档中某几列数据生成散点图
def plotData(x1,y1,x2,y2):
plt.figure(figsize=(8,8))#设置图片大小
plt.scatter(x1,y1,s=30,c=‘red’,marker=‘o’,alpha=1,label=‘gound truth’)#设置
plt.scatter(x2,y2,s=30,c=‘blue’,marker=‘o’,alpha=1,label=‘predicted’)
plt.title('error ')#图片标题
plt.xlabel(‘X(m)’)#X轴名称
plt.ylabel(‘Y(m)’)
plt.legend(loc=‘upper right’)#标签
plt.savefig(“examples.jpg”)
plt.show()

//读取文档中需要的某几列数据
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)

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页