Skip to main content
added 55 characters in body
Source Link
Quang Hoang
  • 151.1k
  • 11
  • 63
  • 86

If you don't need to rescale the plot, I would plot against the positive angles 0-360 and manually re-label the ticks:

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()

Output:

enter image description here enter image description here

If you don't need to rescale the plot, I would plot against the positive angles 0-360 and manually re-label the ticks:

fig, ax = plt.subplots()
(df.assign(Angle=df['MM Initial Angle']%360)
   .plot(x='Angle', y=['QM Energy','MM Initial Energy'], ax=ax)
)
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()

Output:

enter image description here

If you don't need to rescale the plot, I would plot against the positive angles 0-360 and manually re-label the ticks:

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()

Output: enter image description here

Source Link
Quang Hoang
  • 151.1k
  • 11
  • 63
  • 86

If you don't need to rescale the plot, I would plot against the positive angles 0-360 and manually re-label the ticks:

fig, ax = plt.subplots()
(df.assign(Angle=df['MM Initial Angle']%360)
   .plot(x='Angle', y=['QM Energy','MM Initial Energy'], ax=ax)
)
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()

Output:

enter image description here