|
|
本帖最后由 chuan437 于 2024-9-28 11:06 编辑
今天这里介绍一段很简单的python代码来绘制能量折线图。
脚本使用说明:
这里最需要注意的是设置list0,其中存储了你的一系列能量。
出图的效果如下图,其中有些设置(例如线型,颜色等)可参照注释自行调整。
代码见附件,绘制能量折线图.py。推荐在jupyter notebook中运行该脚本。
代码如下:
- import matplotlib.pyplot as plt
- # 假设list0是你的能量列表
- list0 = [-685.2534481,-685.3582154,-685.253315]
- # 对list0进行处理,得到绘图采用的list1
- list1=[]
- for i in list0:
- list1.append(i)
- list1.append(i)
- # 反应坐标,例如,可以是反应进度或者时间
- # 这里我们使用索引作为反应坐标
- reaction_coordinates = list(range(len(list1)))
- h=(max(list0)-min(list0))*0.05
- # 绘制能量折线图
- plt.figure(figsize=(10, 5)) # 设置图形的大小
- # 绘制连接平台的折线
- plt.plot(reaction_coordinates, list1, marker='o', color='red', linestyle='--',label='Energy Change')
- # 绘制平台
- reaction_coordinates1=[i+1 for i in reaction_coordinates]
- for i in range(len(list1)-1):
- if i % 2 == 0:
- plt.hlines(list1[i], reaction_coordinates[i], reaction_coordinates1[i], lw=5, color='black', label='Energy Level' if i==0 else "")
- plt.text(reaction_coordinates[i]+0.5,list1[i]-h, f'{list1[i]:.5f}', ha='center', va='top')
- plt.ylim(min(list1) - 5*h, max(list1) + 5*h)
- plt.grid(True) #显示网格线
- plt.xlabel('Reaction Coordinate') # 设置x轴标签
- plt.xticks([])
- plt.ylabel('Energy (Hatree)') # 设置y轴标签
- plt.legend() # 显示图例
- # plt.tight_layout() # 自动调整子图参数,使之填充整个图像区域
- plt.show() # 显示图形
复制代码
|
评分 Rate
-
查看全部评分 View all ratings
|