My code
import numpy as np
import matplotlib.pyplot as plt
with open('nm.dat','r') as f:
vst = map(float, f)
print vst
a=np.asarray(vst)
print len(a)
a11=a.reshape(4,22)
plt.imshow(a11, cmap='hot', interpolation='nearest')
plt.colorbar()
plt.show()
My image
I would like my x axis to be marked with equidistant 0,8,16,24,32,40,48,56,64,72,80,88 ticks.For y axis 0,2,4,6,8. How to solve this?
Use xticks() method to show all the X-coordinates in the plot. Use yticks() method to show all the Y-coordinates in the plot. To display the figure, use show() method.
The xticks() and yticks() function takes a list object as argument. The elements in the list denote the positions on corresponding action where ticks will be displayed. ax. set_xticks([2,4,6,8,10]) This method will mark the data points at the given positions with ticks.
You are missing the extent argument in imshow. imshow assumes that there is a linear relation between pixels and your "physical" unit. You could just use:
plt.imshow(a11, cmap='hot', interpolation='nearest', extent=[0,88,0,8], origin='lower')
The extent variable has to be given such that extent=[xmin,xmax,ymin,ymax]. The origin='lower' argument is to specify that your [0,0] coordinate has to be placed in the bottom left of the axis. Otherwise, it is placed in the top left of the axis.
Finally, for showing only some particular ticks, you may want to use:
ax = plt.gca()
xticks = [0,8,16,24,32,40,48,56,64,72,80,88]
yticks = [0,2,4,6,8]
ax.xaxis.set_xticks(xticks)
ax.xaxis.set_yticks(yticks)
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