Search code examples
matplotlibloglog

markers on loglog matplotlib figure


I'm plotting multiple curves in loglog scale in matplotlib and, to make them distinguishable, I'm using markers. Since there are a lot of data points, I use markevery=100. But with the horizontal axis on the logarithmic scale, these get clustered. Is there a way to get the markers to space out logarithmically too?


Solution

  • Rather than specifying an integer for markevery which will place a marker at every Nth datapoint, use a float which ensures that the points will be equally spaced along the line (regardless of whether a linear or log scale is used).

    every=0.1, (i.e. a float) then markers will be spaced at approximately equal distances along the line; the distance along the line between markers is determined by multiplying the display-coordinate distance of the axes bounding-box diagonal by the value of every.

    t = np.arange(0.01, 30, 0.01)
    plt.loglog(t, 20 * np.exp(-t / 10.0), '-o', markevery=0.1)
    

    enter image description here