python - Matplotlib: How to force integer tick labels? -


my python script uses matplotlib plot 2d "heat map" of x, y, z dataset. x- , y-values represent amino acid residues in protein , can therefore integers. when zoom plot, looks this:

2d heat map float tick marks

as said, float values on x-y axes not make sense data , therefore want this: enter image description here

any ideas how achieve this? code generates plot:

def plotdistancemap(self):     # read on x,y,z     x = self.currentgraph['xdata']     y = self.currentgraph['ydata']     x, y = numpy.meshgrid(x, y)     z = self.currentgraph['zdata']     # define colormap     cmap = colors.listedcolormap(['blue', 'green', 'orange', 'red'])     cmap.set_under('white')     cmap.set_over('white')     bounds = [1,15,50,80,100]     norm = colors.boundarynorm(bounds, cmap.n)     # draw surface plot     img = self.axes.pcolor(x, y, z, cmap=cmap, norm=norm)     self.axes.set_xlim(x.min(), x.max())     self.axes.set_ylim(y.min(), y.max())     self.axes.set_xlabel(self.currentgraph['xtitle'])     self.axes.set_ylabel(self.currentgraph['ytitle'])     # cosmetics     #matplotlib.rcparams.update({'font.size': 12})     xminorlocator = multiplelocator(10)     yminorlocator = multiplelocator(10)     self.axes.xaxis.set_minor_locator(xminorlocator)     self.axes.yaxis.set_minor_locator(yminorlocator)     self.axes.tick_params(direction='out', length=6, width=1)     self.axes.tick_params(which='minor', direction='out', length=3, width=1)     self.axes.xaxis.labelpad = 15     self.axes.yaxis.labelpad = 15     # draw colorbar     colorbar = self.figure.colorbar(img, boundaries = [0,1,15,50,80,100],                                      spacing = 'proportional',                                     ticks = [15,50,80,100],                                      extend = 'both')     colorbar.ax.set_xlabel('angstrom')     colorbar.ax.xaxis.set_label_position('top')     colorbar.ax.xaxis.labelpad = 20     self.figure.tight_layout()           self.canvas.draw() 

this should simpler:

(from https://scivision.co/matplotlib-force-integer-labeling-of-axis/)

import matplotlib.pyplot plt matplotlib.ticker import maxnlocator #... ax = plt.figure().gca() #... ax.xaxis.set_major_locator(maxnlocator(integer=true)) 

Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -