Search code examples
pythonmatplotlibticker

python/matplotlib : imposed ticks with ticker partially missing


When plotting my figure with plt.axis('auto'), 'natural' x-ticks are written with frequency 500,

enter image description here

Wishing a frequency 200, I have used:

    import matplotlib.ticker as ticker

    ticks_loc = ticker.MultipleLocator(base=200)

    fig = plt.figure('Cutlines x-axis')
    ax = fig.add_subplot(111)
    ...
    plt.axis('equal')
    ax.xaxis.set_major_locator(ticks_loc)
    ax.yaxis.set_major_locator(ticks_loc)
    plt.grid()

which gives,

enter image description here

Curiously

  1. all the ticks are not represented (ticks -1000, -800, -600 are missing)
  2. plt.show() differs from savefig (in plt.show() 'only' ticks -1000 and -800 are missing, not -600).

I have tried reducing the font size (with very tiny one) and/or by writing vertically -> no effect : always the same ticks are missing.

Is there a way to have all the ticks visible (in horizontal mode) ?


Solution

  • Why don't you simply use xticks instead of ticker

    fig = plt.figure('Cutlines x-axis')
    ax = fig.add_subplot(111)
    ...
    xlim = ax.get_xlim()
    plt.xticks(np.arange(xlim[0], xlim[1]+200, 200))