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)
相关推荐
特立独行的猫A9 小时前
别再用 nohup 了:让应用在后台常驻的正确姿势与 systemd 服务详解
java·后端·python
吃我一窝jio12 小时前
Python与Go线程模型深度对比
java·开发语言·python
zwd200513 小时前
Manim 怎么放大画面的某一部分?
python·动画·可视化·manim·数学动画
屿华AI14 小时前
AUTOSAR 实战-诊断工具 | UDS 0x27 安全访问的配置化实现:种子密钥算法插件化设计
python·测试工具·汽车
RobinDevNotes14 小时前
Claude Code 剪视频,不上传、不要 API Key
人工智能·python·音视频·开发工具·ipython
如夏倾城15 小时前
VRRP(虚拟路由器冗余协议Virtual Router Redundancy Protocol)
网络·python·网络协议·安全·智能路由器·负载均衡·信息与通信
IvanCodes16 小时前
LangChain(04):Runnable 与 LCEL 的执行与组合机制
python·langchain·agent
特创数字科技16 小时前
纯本地离线运行的文档脱敏工具(技术分享)
前端·驱动开发·python
东莞市云毅网络有限公司17 小时前
用 Playwright 搭一套问答平台引用监测的最小骨架
python·数据清洗·rag·企业知识库·文档解析
Thanks_ks17 小时前
【第 010 讲】全面掌握 Python 变量与常量:变量的定义与赋值 | 标识符与命名规范 | 变量的底层机制 | 常量与魔术数字
python·内存·变量·标识符·常量·赋值·命名规范