How to set ticks on Fixed Position , matplotlib

后端 未结 2 1335
情深已故
情深已故 2020-11-27 05:24

Can anyone help me set the ticks on a fixed position using matplotlib? I\'ve tried using FixedPosition as this tutorial describes:

ax = pl.gca()
ax.xaxis.set         


        
相关标签:
2条回答
  • 2020-11-27 05:52

    Just use ax.set_xticks(positions) or ax.set_yticks(positions).

    For example:

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots()
    ax.set_xticks([0.15, 0.68, 0.97])
    ax.set_yticks([0.2, 0.55, 0.76])
    plt.show()
    

    enter image description here

    0 讨论(0)
  • 2020-11-27 06:05
    import numpy as np
    import matplotlib.ticker as ticker
    import matplotlib.pyplot as plt
    
    name_list = ('Omar', 'Serguey', 'Max', 'Zhou', 'Abidin')
    value_list = np.random.randint(0, 99, size = len(name_list))
    pos_list = np.arange(len(name_list))
    
    ax = plt.axes()
    ax.xaxis.set_major_locator(ticker.FixedLocator((pos_list)))
    ax.xaxis.set_major_formatter(ticker.FixedFormatter((name_list)))
    plt.bar(pos_list, value_list, color = '.75', align = 'center')
    
    plt.show()
    
    0 讨论(0)
提交回复
热议问题