Matplotlib: How to force integer tick labels?

后端 未结 2 1130
谎友^
谎友^ 2020-12-05 09:06

My python script uses matplotlib to plot a 2D \"heat map\" of an x, y, z dataset. My x- and y-values represent amino acid residues in a protein and can therefore only be int

2条回答
  •  旧时难觅i
    2020-12-05 09:56

    This should be simpler:

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

    import matplotlib.pyplot as plt
    from matplotlib.ticker import MaxNLocator
    #...
    ax = plt.figure().gca()
    #...
    ax.xaxis.set_major_locator(MaxNLocator(integer=True))
    

提交回复
热议问题