A python tool is used to help those who do not have Python or other draw tools to draw pictures quickly.

Code

import re
import matplotlib.pyplot as plt
import tkinter as tk
from tkinter import messagebox

# 设置中文输出
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False

# 创建Gui
Gui = tk.Tk()
Gui.title('画图')
Gui.geometry('630x330')

# 一些Gui部件参数
tip_1 = tk.Label(text='曲线颜色可自行修改:\n绿色:green(g)  红色:red(r) 紫色:magenta(m)\n白色:withe(w  黄色:yellow(y)  蓝色bluek(b) ')
tip_2 = tk.Label(text='坐标必须用***英文***逗号分割,例:2.5 , 1 , 6.78 , 156\n只画一条线时保持坐标1或坐标2为空均可           不填即为默认值')

tip_x_1 = tk.Label(text='输入横坐标1:')
content_x_1 = tk.Entry(width=70)

tip_y_1 = tk.Label(text='输入纵坐标1:')
content_y_1 = tk.Entry(width=70)

tip_x_2 = tk.Label(text='输入横坐标2:')
content_x_2 = tk.Entry(width=70)

tip_y_2 = tk.Label(text='输入纵坐标2:')
content_y_2 = tk.Entry(width=70)

tip_x_start_point = tk.Label(text='输入X轴起点:')
content_x_start_point = tk.Entry(width=10)

tip_x_end_point = tk.Label(text='输入X轴终点:')
content_x_end_point = tk.Entry(width=10)

tip_y_start_point = tk.Label(text='输入Y轴起点:')
content_y_start_point = tk.Entry(width=10)

tip_y_end_point = tk.Label(text='输入Y轴终点:')
content_y_end_point = tk.Entry(width=10)

tip_x_name = tk.Label(text='输入X轴名称:')
content_x_name = tk.Entry(width=30)

tip_y_name = tk.Label(text='输入Y轴名称:')
content_y_name = tk.Entry(width=30)

tip_title_name = tk.Label(text='输入图像名称')
content_title_name = tk.Entry(width=30)

tip_line_color_1 = tk.Label(text='输入曲线颜色1:')
content_line_color_1 = tk.Entry(width=2)
content_line_color_1.insert(0, 'r')

tip_line_color_2 = tk.Label(text='输入曲线颜色2:')
content_line_color_2 = tk.Entry(width=2)
content_line_color_2.insert(0, 'b')

tip_line_width = tk.Label(text='输入曲线宽度:')
content_line_width = tk.Entry(width=2)
content_line_width.insert(0, '1')

tip_x_1.place(x=10, y=50)
content_x_1.place(x=90, y=50)

tip_y_1.place(x=10, y=80)
content_y_1.place(x=90, y=80)

tip_x_2.place(x=10, y=110)
content_x_2.place(x=90, y=110)

tip_y_2.place(x=10, y=140)
content_y_2.place(x=90, y=140)

tip_x_start_point.place(x=10, y=170)
content_x_start_point.place(x=90, y=170)

tip_x_end_point.place(x=150, y=170)
content_x_end_point.place(x=230, y=170)

tip_y_start_point.place(x=290, y=170)
content_y_start_point.place(x=370, y=170)

tip_y_end_point.place(x=430, y=170)
content_y_end_point.place(x=510, y=170)

tip_x_name.place(x=10, y=200)
content_x_name.place(x=90, y=200)

tip_y_name.place(x=290, y=200)
content_y_name.place(x=370, y=200)

tip_title_name.place(x=10, y=230)
content_title_name.place(x=90, y=230)

tip_line_color_1.place(x=290, y=230)
content_line_color_1.place(x=380, y=230)

tip_line_color_2.place(x=430, y=230)
content_line_color_2.place(x=520, y=230)

tip_line_width.place(x=290, y=260)
content_line_width.place(x=380, y=260)

tip_1.place(x=10, y=260)
tip_2.place(x=10, y=5)


def draw():
    try:
        # 创建画布
        fig, axes = plt.subplots()
        
        # 创建一个空列表来储存x坐标
        x_list_1 = []
        # 获取x坐标的输入框内容
        str_x_list_1 = content_x_1.get()
        # 输入框内容作为一个字符串,如"1,2,3,4,5"
        # 所以利用正则匹配来匹配字符串中的数字
        list_str_x_list_1 = re.findall(r"\d+\.?\d*", str_x_list_1)
        # 将匹配完的数字添加到x_list_1中
        for i in list_str_x_list_1:
            i = float(i)
            x_list_1.append(i)

        # y坐标同理
        y_list_1 = []
        str_y_list_1 = content_y_1.get()
        list_str_y_list_1 = re.findall(r"\d+\.?\d*", str_y_list_1)
        for i in list_str_y_list_1:
            i = float(i)
            y_list_1.append(i)

        # 第二条曲线的x坐标
        x_list_2 = []
        str_x_list_2 = content_x_2.get()
        list_str_x_list_2 = re.findall(r"\d+\.?\d*", str_x_list_2)
        for i in list_str_x_list_2:
            i = float(i)
            x_list_2.append(i)

        # 第二条曲线的y坐标
        y_list_2 = []
        str_y_list_2 = content_y_2.get()
        list_str_y_list_2 = re.findall(r"\d+\.?\d*", str_y_list_2)
        for i in list_str_y_list_2:
            i = float(i)
            y_list_2.append(i)

        # 获取x轴的起点终点
        if content_x_start_point.get() == "":
            # x_start_point = 0
            # x_end_point = max(max(x_list_1),max(x_list_2))
            pass
        else:
            x_start_point = float(content_x_start_point.get())
            x_end_point = float(content_x_end_point.get())
            axes.set(xlim=[x_start_point, x_end_point])

        # 获取y轴的起点终点
        if content_y_start_point.get() == "":
            pass
        else:
            y_start_point = float(content_y_start_point.get())
            y_end_point = float(content_y_end_point.get())
            axes.set(ylim=[y_start_point, y_end_point])

        # 获取x轴名称
        x_name = content_x_name.get()

        # 获取y轴名称
        y_name = content_y_name.get()

        # 获取表头名称
        title_name = content_title_name.get()

        # 获取曲线1颜色
        line_color_1 = str(content_line_color_1.get())

        # 获取曲线2颜色
        line_color_2 = str(content_line_color_2.get())

        # 获取线宽
        line_width = float(content_line_width.get())

        # 设置画布参数
        axes.set(title='%s' % (title_name), ylabel='%s' % (y_name), xlabel='%s' % (x_name))
        # 绘图
        plt.plot(x_list_1, y_list_1, color=line_color_1, linewidth=line_width)
        plt.plot(x_list_2, y_list_2, color=line_color_2, linewidth=line_width)
        plt.show()

    except:
        tk.messagebox.showerror('Error', '请检查输入内容')


# 创建Button按钮并绑定draw函数
Button_draw = tk.Button(Gui, text='draw', command=draw)
Button_draw.place(x=570, y=290)
Gui.mainloop()

预览效果

程序预览

输出图片

下载链接

点我下载 密码1234