2.折线图

该博客内容涉及将三个数据文件'y1.txt'、'y2.txt'和'y3.txt'的内容合并成一个新的数据文件,并利用numpy和matplotlib库绘制了关于'current'、'top1'和'top5'的评价标准曲线图。图表清晰展示了随着Epoch(周期)增加,各项指标的变化趋势,用于评估模型性能。
摘要由CSDN通过智能技术生成
import numpy as np
import matplotlib.pyplot as plt
with open("C:\\Users\\dell\\Desktop\\shujuji.txt","w+")as fd:
    with open('C:\\Users\\dell\\Desktop\\accuracy.txt', 'r') as fa:            #############需输入y1.txt地址
        with open('C:\\Users\\dell\\Desktop\\top1.txt', 'r') as fb:              #############需输入y2.txt地址
            with open('C:\\Users\\dell\\Desktop\\top5.txt', 'r') as fc:          #############需输入y3.txt地址
                i=0
                for line in fa:
                    i=i+1
                    linea=line.strip('\r\n')
                    lineb=fb.readline()
                    linec=fc.readline()
                    fd.write(str(i)+" "+linea+" "+lineb.strip('\r\n')+" "+linec.strip('\r\n'))
                    fd.write("\n")
#######################合并  y1 y2 y3 ######################
                                            
x = []
y1 = []
y2 = []
y3 = []

with open("C:\\Users\\dell\\Desktop\\shujuji.txt","r")as fd:
    for line in fd:
        line = line.strip('\n')
        line = line.split(' ')
        x.append(float(line[0]))
        y1.append(float(line[1]))
        y2.append(float(line[2]))
        y3.append(float(line[3]))
######################  txt转变为数组  ######################
    
plt.plot(x,y1,c='royalblue', label="current") 
plt.plot(x,y2,c='coral',label="top1")  
plt.plot(x,y3,c='black',label="top5")  # 画线

plt.scatter(x,y1,c='royalblue')
plt.scatter(x,y2,c='coral') 
plt.scatter(x,y3,c='black')   # 画点

plt.legend(loc='best',frameon=False) # 图例边框

plt.xticks(range(0, 21, 1))
plt.yticks(range(0, 110,10))# x,y轴刻度

plt.xlabel("Epoch", fontdict={'size': 16})
plt.ylabel("Percentage%", fontdict={'size': 16})
plt.title("评价标准图", fontdict={'size': 20})
plt.show()
######################  作图  ######################

使用Three.js绘制折线图需要用到以下步骤: 1. 创建场景:使用`THREE.Scene()`创建一个3D场景对象。 2. 创建相机:使用`THREE.PerspectiveCamera()`创建一个透视相机,用于捕捉场景中的物体。 3. 创建渲染器:使用`THREE.WebGLRenderer()`创建一个WebGL渲染器,用于将场景渲染到浏览器中。 4. 创建几何体:使用`THREE.Geometry()`创建一个几何体对象,用于存储折线图的顶点信息。 5. 创建材质:使用`THREE.LineBasicMaterial()`创建一个材质对象,用于设置折线的颜色和宽度。 6. 创建折线:使用`THREE.Line()`将几何体和材质对象组合成一个折线对象。 7. 将折线添加到场景中:使用`scene.add(line)`将折线添加到场景中。 8. 渲染场景:使用`renderer.render(scene, camera)`将场景渲染到浏览器中。 下面是一个简单的例子,演示如何使用Three.js绘制一个折线图: ```javascript // 创建场景 var scene = new THREE.Scene(); // 创建相机 var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); camera.position.z = 5; // 创建渲染器 var renderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); // 创建几何体 var geometry = new THREE.Geometry(); geometry.vertices.push(new THREE.Vector3(-2, 0, 0)); geometry.vertices.push(new THREE.Vector3(0, 2, 0)); geometry.vertices.push(new THREE.Vector3(2, 0, 0)); // 创建材质 var material = new THREE.LineBasicMaterial({ color: 0x00ff00, linewidth: 2 }); // 创建折线 var line = new THREE.Line(geometry, material); // 将折线添加到场景中 scene.add(line); // 渲染场景 renderer.render(scene, camera); ``` 这个例子创建了一个三角形折线图,其顶点坐标分别为(-2,0,0),(0,2,0)和(2,0,0)。您可以根据需要修改顶点坐标和材质属性,来绘制自己想要的折线图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值