I'm trying to do a pyplot graph but am unable to access the function family where I change the 'x tick labels'. I know the function exists but my code doesn't want to recognise it. From what I've found on the internet, I might need to move beyond using plt.plot
but don't really understand why I need to do this.
Here is my code:
import matplotlib.pyplot as plt
def grapher(number_of_steps, probabilities):
'''
Takes the number of positions and probabilities for these posistions. Plots them
Positions are on 1D Quantum Walk line and assumed to be a circle (?) eventually, but
for the loops to be so long as for it to appear as a straight line for our purposes
'''
P = 2*(number_of_steps)+1 # Number of Positions
positions_plot = np.arange(0,P)
plt.style.use('seaborn-ticks')
plt.plot(positions_plot, probabilities, marker = 'o', linestyle = "--", label = r"Probability" )
ticks = np.arange(0,P,P//10) #Location of Ticks
plt.xticks(ticks)
plt.xlim(0,P)
ax.set_xticklabels(range(-N, N+1, P // 10))
plt.legend()
plt.show()
And this is my error
File "discretewalk.py", line 134, in grapher ax.set_xticklabels(range(-N, N+1, P // 10)) NameError: name 'ax' is not defined