跳转至

大学化学实验


资源

(如使用代码,您可能需要pip安装Python库

  • 2024春学堂在线答案
  • 实验报告参考合集 @ 随光
    数据处理代码
    import matplotlib.pyplot as plt
    import numpy as np
    import splines
    
    def main(dataList: list, reactionBeginIndex: int, dotsPerSecond: int = 300):
        """
        Args:
            dataList (list): 数据点 y 坐标
            reactionBeginIndex (int): 反应起始时刻
            dotsPerSecond (int, optional): 拟合曲线差值点个数. Defaults to 300.
        """
        dataListLenth = len(dataList)
        dataX = np.array(range(1, dataListLenth + 1))
        dataY = np.array(list(map(lambda x: x + 298.15, dataList)))
        points1 = np.array([[dataX[i], dataY[i]] for i in range(dataListLenth)])
        ax = plt.gca()
        spline = splines.CatmullRom(points1, alpha=0.5)
        total_duration = spline.grid[-1] - spline.grid[0]
        dots = int(total_duration * dotsPerSecond) + 1
        times = spline.grid[0] + np.arange(dots) / dotsPerSecond
        intersectionY = 3 / (reactionBeginIndex + 3 - dataListLenth) * (
            dataY[-1] - dataY[reactionBeginIndex + 2]) + dataY[reactionBeginIndex +
                                                               2]
        ax.plot(*spline.evaluate(times).T, marker='.', linestyle='',
                color="gray")  # 拟合曲线
        ax.plot(*np.asarray(spline.evaluate(spline.grid)).T,
                color='black',
                linestyle='',
                marker='x',
                markersize=10)  # 数据点
        plt.xticks(range(1, dataListLenth))  # x 坐标轴
        plt.axline((reactionBeginIndex, dataY.min()),
                (reactionBeginIndex, dataY.max()),
                linestyle="--",
                color="black")  # 竖直虚线
        plt.axline((dataListLenth, dataY[-1]),
                (reactionBeginIndex + 3, dataY[reactionBeginIndex + 2]),
                linestyle="--",
                color="black")  # 斜虚线
        plt.xlim([0, dataListLenth + 1])  # x 范围
        plt.ylim([dataY.min() - 1, dataY.max() + 1])  # y 范围
        plt.scatter(reactionBeginIndex, intersectionY, marker="o",
                    color="black")  # 虚线交点
        plt.xlabel("$\mathrm{t/30s}$")  # x 名称
        plt.ylabel("$\mathrm{T/K}$")  # y 名称
        plt.annotate("",
                    xy=(reactionBeginIndex - 0.4,
                        dataY[reactionBeginIndex - 1] - 0.1),
                    xytext=(reactionBeginIndex - 0.4, intersectionY + 0.1),
                    arrowprops=dict(arrowstyle="<->", ))  # Delta T 箭头
        plt.text(reactionBeginIndex - 1.5,
                (intersectionY + dataY[reactionBeginIndex - 1]) / 2,
                "     $\\Delta T$\n${}K$".format(
                    round(intersectionY - dataY[reactionBeginIndex - 1], 1)),
                bbox={
                    'facecolor': 'white',
                    'edgecolor': 'white',
                    'alpha': 1,
                    'pad': 1
                })  # Delta T 文字
        plt.show()
    
    if __name__ == "__main__":
        data = [
            18.1, 18.2, 18.2, 18.3, 18.2, 18.2, 27.8, 28.7, 28.8, 28.7, 28.7, 28.6,
            28.5, 28.5, 28.4
        ]  # 在这里修改实验数据
        reactionBeginIndex = 6  # 反应起始时刻
        main(data, reactionBeginIndex)