user3053231
user3053231

Reputation:

change X ticks in matplotlib plot

I plotted a graph in matplotlib, and it looks like this : graph

On the x-axis are values [50,100,150,200,250]. I want to change them to [10,20,30,40,50]. But without changing or touching graph. I dont want use plt.xlim() because it changes only part of the displaying graph. How can I do this?

My plotting code:

def plot_random_angular():
    m = np.loadtxt('angle.txt')
    uhol = m[:,6]
    vys = []
    for x in xrange(1,len(uhol)):
        vys.append((uhol[x] - uhol[x-1])*4)
    x=np.linspace(0,len(vys),len(vys))
    plt.ylim(-5,5)
    plt.xlim(0,250)
    plt.grid()
    plt.xlabel('time [s]',fontsize = 18)
    plt.ylabel('angle [deg]',fontsize = 18)
    plt.plot(x,vys,'black')
    return vys

Upvotes: 4

Views: 2626

Answers (1)

CT Zhu
CT Zhu

Reputation: 54330

Make everything 1/5 of the original?:

ax=plt.gca() 
#ax.get_xticks() will get the current ticks
ax.set_xticklabels(map(str, ax.get_xticks()/5.0))

Upvotes: 1

Related Questions