1

I have a working script to display information from a gyroscope. I represent Euler angles with a line of varying thickness representing angular velocity like the following. This is for the x axis; data is stored in a pandas dataframe df, idx is a list of time steps:

scaling = 0.1
# x
ax1 = plt.subplot(gs[0,0:2]) # row span 2 columns
widths = np.absolute(df['avelo']['x'].iloc[start:end])
widths *= scaling
ax1.scatter(idx,df['angle']['x'].iloc[start:end],s=widths,c = 'blue')
for i in steplist:
        ax1.axvline(steps[i], linestyle = 'dashed', c = '0.8' )
ax1.axhline(0, linestyle = 'dashed', c = '0.8' ) 

The axvlines indicate events. Currently the x axis displays time steps. I would like to hide those and replace them with avxline labels step1, step2, etc. I know how to hide the x ticks, but how do I replace them with the avxline labels in the right spots?

Edit: added a plot to clarify the question. plot described in th post

Steve
  • 945
  • 3
  • 13
  • 22
  • Have you looked at https://stackoverflow.com/questions/11244514/modify-tick-label-text – jared Jun 07 '23 at 19:22
  • Yeah, I don't want to change the tick labels. I want to hide those and add labels below the avxlines, which are not ticks and aren't aligned with the ticks (see image I added). I don't think I can use the text method because it would be outside the plot area. – Steve Jun 07 '23 at 19:43
  • Brilliant, thanks. I didn't realize I could define the ticks that way. – Steve Jun 07 '23 at 20:16

1 Answers1

1

Following this answer, you can change the xtick labels to what you want. Since the ticks don't line up with the step locations, you will have to adjust the tick locations to match the step locations.

import numpy as np
import matplotlib.pyplot as plt

plt.close("all")

x = np.linspace(0, 10, 1000)
y = 0.5*np.sin(5*x)

Nsteps = 7
steps = np.linspace(x.min(), x.max(), Nsteps)

fig, ax = plt.subplots()
ax.plot(x, y)
for step in steps:
    ax.axvline(step, color="k", ls="--", alpha=0.5)
ax.set_xticks(steps, [f"Step {n}" for n in range(Nsteps)])
fig.tight_layout()
fig.show()

enter image description here

jared
  • 4,165
  • 1
  • 8
  • 31