user1551817
user1551817

Reputation: 7471

changing the xticks on a python plot

I think I'm doing something silly but I just can't see it.

In Python, I have an imshow plot, and I want to change the values on the x axis.

plt.xticks=(np.arange(grid_resid.shape[1]),xp)
plt.imshow(grid_resid[:,:], aspect="auto")
plt.show()

grid_resid.shape[1] is 1830 (0 - 1829) and the default x axis on the plot runs from 0 - 1829.

I want to change the xticks to the values of the list 'xp'. Which looks something like:

[ 53293.103161  53294.103161  53295.103161 ...,  55120.103161  55121.103161  55122.103161]

and which also has 1830 components.

My xticks however are still running from 0-1829. Could somebody point out why this is please?

Upvotes: 0

Views: 636

Answers (1)

cge
cge

Reputation: 9888

xticks is a function, not a variable, so you don't want to assign to it. Also, you need to run it after imshow:

plt.imshow(grid_resid[:,:], aspect="auto")
plt.xticks(np.arange(grid_resid.shape[1]),xp)
plt.show()

Note that as your labels look long, you might want to use the rotation= argument to xticks in order to rotate the labels.

Upvotes: 1

Related Questions