我有一个如下所示的数据框:MM Initial Energy MM Initial Angle QM Energy QM Angle0 13.029277 120.0 18.048 120.01 11.173115 125.0 15.250 125.02 9.411475 130.0 12.668 130.03 7.762888 135.0 10.309 135.04 6.239025 140.0 8.180 140.05 4.853004 145.0 6.286 145.06 3.617394 150.0 4.633 150.07 2.544760 155.0 3.226 155.08 1.646335 160.0 2.070 160.09 0.934298 165.0 1.166 165.010 0.419003 170.0 0.519 170.011 0.105913 175.0 0.130 175.012 0.000000 -180.0 0.000 -180.013 0.105988 -175.0 0.130 -175.014 0.420029 -170.0 0.519 -170.015 0.937312 -165.0 1.166 -165.016 1.650080 -160.0 2.070 -160.017 2.548463 -155.0 3.227 -155.018 3.621227 -150.0 4.633 -150.019 4.856266 -145.0 6.286 -145.020 6.236939 -140.0 8.180 -140.021 7.760035 -135.0 10.309 -135.022 9.409117 -130.0 12.669 -130.023 11.170671 -125.0 15.251 -125.024 13.033293 -120.0 18.048 -120.0我想用 x 轴上的角度和 y 轴上的能量来绘制数据。这听起来很简单,但是会发生什么是 pandas 或 matplotlib 以我的情节看起来分裂的方式对 X 轴值进行排序。这是它的样子:但是,这就是我想要的:我的代码如下:df=pd.read_fwf('scan_c1c2c3h31_orig.txt', header=None, prefix='X')df.rename(columns={'X0':'MM Initial Energy', 'X1':'MM Initial Angle', 'X2':'QM Energy', 'X3':'QM Angle'}, inplace=True)df=df.sort_values(by=['MM Initial Angle'], axis=0, ascending=True)df=df.reset_index(drop=False)df2=pd.read_fwf('scan_c1c2c3h31.txt', header=None, prefix='X')df2.rename(columns={'X0':'MM Energy', 'X1':'MM Angle', 'X2':'QM Energy', 'X3':'QM Angle'}, inplace=True)
1 回答
Helenr
TA贡献1780条经验 获得超4个赞
如果您不需要重新调整绘图,我会根据正角绘图0-360并手动重新标记刻度:
fig, ax = plt.subplots()
(df.assign(Angle=df['MM Initial Angle']%360)
.plot(x='Angle', y=['QM Energy','MM Initial Energy'], ax=ax)
)
ax.xaxis.set_major_locator(MultipleLocator(20))
x_ticks = ax.get_xticks()
x_ticks = [t-360 if t>180 else t for t in x_ticks]
ax.set_xticklabels(x_ticks)
plt.plot()
添加回答
举报
0/150
提交
取消