Search code examples
pythonmatplotlibplotaxes

how to make a particular axis which isn't linear or log?


I want to replicate this axis (see picture) and I have a range of values from 1-10 - what format is this in and how can it be achieved in matplotlib?

enter image description here


Solution

  • import matplotlib.pyplot as plt
    import matplotlib.ticker as ticker
    import numpy as np
    
    fig, ax = plt.subplots()
    x = np.linspace(1, 11, 100)
    y = np.sin(x)
    ax.plot(x, y)
    ax.set_xscale('log')
    ax.xaxis.set_major_formatter(ticker.ScalarFormatter())
    ax.xaxis.set_major_locator(ticker.FixedLocator([1, 3, 6, 10]))
    ax.set_xlim(0, 11)
    plt.show()
    

    enter image description here