Search code examples
pythonmatplotlibaxes

Change length of one (or however many) ticks


I'd like to change the tick length (tick beyond the plot frame) for an arbitrary tick.

I can set the visibility of just one tick (for example the second one) with

ax.xaxis.majorTicks[1].set_visible(False)

So intuitively, I tried the following to no avail:

ax1.xaxis.majorTicks[1].set_length(20)

I looked through the axes object and tried some other things, for example setting one to the color blue with the following code, again to no avail:

ax1.xaxis.majorTicks[1]._color = 'blue'

Is this possible?


Solution

  • The tick is a marker of a Line2D. The line is accessed as tick1line (or tick2line in case of the opposite axis).

    ax1.xaxis.get_major_ticks()[3].tick1line.set_color("red")
    ax1.xaxis.get_major_ticks()[3].tick1line.set_markersize(8)
    ax1.xaxis.get_major_ticks()[3].tick1line.set_markeredgewidth(3)
    

    enter image description here