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)
相关推荐
MoRanzhi12034 分钟前
第4篇 · 使用 PyQt5 实现 2048:平滑动画与性能优化
python·性能优化·qtimer·pyqt5·qpainter·gui动画·2048游戏
海姐软件测试24 分钟前
Python 自动化与 AI 结合:基于 Jenkins 的回归验证实践
人工智能·python·自动化
Haoyunyi31 分钟前
2026年做期货量化,和三年前已经不是一回事了
大数据·人工智能·python·金融·区块链
再__努力1点1 小时前
一个开源的AI边缘计算平台:一个项目把算能、瑞芯微、x86的NPU全打通了
人工智能·python·课程设计·媒体·流媒体
小oo呆1 小时前
【学习心得】Python函数参数中的两个特殊分隔符
开发语言·python
SEO_juper1 小时前
AI 爬虫 robots.txt 检查工具:你的站是不是把 AI 挡在门外了
开发语言·人工智能·爬虫·python·外贸独立站
看我debug1 小时前
Android 运行时分析工作台 (Demo)。统一管理 Frida 脚本、自动注入(修改运行时代码)、收集结构化结果、生成 JSON 报告。
android·python·pip
染指11101 小时前
151.Agent-LangGraph-Send发送(Map-Reduce模式)
人工智能·python·langchain·状态模式·agents
OKkankan1 小时前
python 进阶(三):面向对象进阶——从“会写 class”到设计可维护的后端对象
开发语言·数据结构·python
用户0332126663671 小时前
Python 办公自动化:用 Python 快速生成精美 PPT 演示文稿
python