焊接性能分析代码(Python)

welding_performance_data.xls数据文件。

welding_strength toughness
500 10
520 12
480 8
550 15
490 9
530 13
510 11
540 14
470 7
560 16
900 18
600 12
1500 13
911 15
781 15

import pandas as pd
import matplotlib.pyplot as plt
import tkinter as tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg


def analyze_and_visualize():
    try:
        data = pd.read_csv('welding_performance_data.csv')
        mean_strength = data['welding_strength'].mean()
        std_dev_toughness = data['toughness'].std()

        root = tk.Tk()
        root.title('Welding Performance Analysis')

        fig, axs = plt.subplots(2, 1, figsize=(10, 8))

        axs[0].hist(data['welding_strength'], bins=10, edgecolor='black')
        axs[0].set_title('Distribution of Welding Strength')
        axs[0].set_xlabel('Welding Strength')
        axs[0].set_ylabel('Frequency')

        axs[1].scatter(data['welding_strength'], data['toughness'])
        axs[1].set_title('Relationship between Welding Strength and Toughness')
        axs[1].set_xlabel('Welding Strength')
        axs[1].set_ylabel('Toughness')

        canvas = FigureCanvasTkAgg(fig, master=root)
        canvas.get_tk_widget().pack()

        root.mainloop()
    except FileNotFoundError:
        print("Data file 'welding_performance_data.csv' not found.")
    except KeyError as e:
        print(f"Missing required column in data file: {e}")


if __name__ == "__main__":
    analyze_and_visualize()

你可能感兴趣的:(python,开发语言)