How to set ticks on Fixed Position , matplotlib

后端 未结 2 1363
情深已故
情深已故 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 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()
    

提交回复
热议问题