I have a graph like this
The data on the x axis means hours, so I want the x axis to set as 0, 24, 48, 72.....instead of the value now, which is difficult to see the data between [0,100]
fig1 = plt.figure()
ax = fig1.add_subplot(111)
ax.set_yscale('log')
ax.plot(x,y,'b-')
According to the the first answer, I got this:

Look at the docs :
xlocs, xlabs = plt.xticks()
put in xlocs your range, and in xlabs what you want to display.
then:
plt.xticks(xlocs, xlabs)
It sounds like you want to changes the limits of the plotting display - for that use xlim (and ylim for the other axis). To change the xticks themselves is provided in the answer by @fp. Show below is an example using without/with xlim:
# Sample data
import numpy as np
N = 2000
X = np.random.gamma(.5,size=N)*100
import pylab as plt
plt.subplot(2,1,1)
plt.hist(X,bins=300)
plt.subplot(2,1,2)
plt.hist(X,bins=300)
plt.xlim(0,100)
plt.show()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With