python绘制钻头外径磨损图

python 复制代码
import matplotlib.pyplot as plt
import numpy as np
srcpath=r'C:\Users\user\Documents\F1-21\data0.125-1.8.txt'

def openreadtxt(file_name):
    data = []
    with open(file_name, 'r') as file:
        file_data = file.readlines()  # 读取所有行
        for row in file_data:
            tmp_list = row.split()
            tmp = [float(x) for x in tmp_list]
            data.append(tmp)  # 将每行数据插入data中
    return data
if __name__ == "__main__":
    data=openreadtxt(srcpath)
    data_T1=data[0:9]
    data_T2=data[9:]
    xs=np.linspace(0.02,0.32,16)

    fig=plt.figure(figsize=(5,4))
    plt.rcParams['xtick.direction'] = 'in'  # 将x周的刻度线方向设置向内
    plt.rcParams['ytick.direction'] = 'in'  # 将y轴的刻度方向设置向内
    # plt.rcParams['font.family'] = ["Times New Roman"]  # 字体设置为Times NewRoman
    plt.rcParams['font.sans-serif'] = ['SimHei']
    clist = ['blue', 'red', 'green', 'black', 'darkgreen', 'lime', 'gold', 'purple', 'green', 'cyan', 'salmon', 'grey',
             'mediumvioletred', 'darkkhaki', 'gray', 'darkcyan', 'violet', 'powderblue']
    markerlst = ['o', '*', 'x', '>', '<', '^', 'D', 'd', '1', '2', '3', '4', 'o', '*', 'x', '>', '<', '^', 'D', 'd',
                 '1', '2', '3', '4', 'o', '*', 'x', '>', '<', '^', 'D', 'd', '1', '2', '3', '4']
    linestylelst = ['-', '--', '-.', ':', '-', '--', '-.', ':', '-', '--', '-.', ':', '-', '--', '-.', ':', '-', '--',
                    '-.', ':', '-', '--', '-.', ':']

    for i in range(len(data_T1)):
        plt.plot(xs[2:],data_T1[i][2:],c=clist[1], marker=markerlst[i], markersize='10', linewidth='3', linestyle=linestylelst[1],  label=f'T1-{i+1}')

    for i in range(len(data_T2)):
        if i==4 or i==3:
            continue
        plt.plot(xs[2:], data_T2[i][2:], c=clist[2], marker=markerlst[i], markersize='10', linewidth='3', linestyle=linestylelst[1], label=f'T2-{i+1}')



    font1 = {'family': 'SimHei', 'weight': 'normal', 'size': 16}
    # 图例展示位置,数字代表第几象限
    plt.legend(loc=4,prop=font1,ncol=4,framealpha=0.5)
    plt.xticks(xs[2:])
    plt.yticks(np.linspace(0.124,0.132,9))
    plt.grid(True, linestyle='--', alpha=0.5)
    plt.xlabel("到钻尖的距离(mm)", fontdict={'size': 16})
    plt.ylabel("钻头外径(mm)", fontdict={'size': 16})
    plt.title("SHC Φ0.125-1.8", fontdict={'size': 20})
    fig.autofmt_xdate()
    plt.show()

    figure1 = fig.get_figure()  # 获取图形
    figure1.savefig("C:\\Users\\user\\Documents\\1.jpg", dpi=300)
相关推荐
默_笙17 小时前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
qq_4260039617 小时前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫17 小时前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技18 小时前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读18 小时前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时19 小时前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
奇思妙想聪明勤奋的小羊19 小时前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
lpfasd12320 小时前
2026年第38周GitHub趋势周报
python·科技·github
IZero0720 小时前
Jev 与 Laya
python·语言模型