Make longer subplot tick marks in matplotlib?
Asked Answered
I

1

28

I am trying to alter the tick marks along the axes of a python multipanel subplot. I have two panels that share a common x-axis. I have made the border around the plot thicker as well as making all of the tick marks along the axes thicker. I have two questions:

How can I make all tick marks (both axes) longer so they are more visible?

How do I add smaller but still noticable tick marks between major tick marks?

Here is a minimum working example of what I have so far.

from numpy import *
from scipy import *
from pylab import *
from random import *
import pylab
import matplotlib.pyplot as plt


#make the axis border thick
pylab.rc("axes", linewidth=4.0)
pylab.rc("lines", markeredgewidth=4)


#create a figure with two panels that shares the x-axis
f, (ax1, ax2) = plt.subplots(2, sharex=True, sharey=False)
#example figure1
ax1.plot(range(2),range(2),linewidth=2)
#example figure 2
ax2.plot(range(2),range(2),linewidth=2)



# Fine-tune figure; make subplots close to each other and hide x ticks for
# all but bottom plot.
f.subplots_adjust(hspace=0)
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
show()
Ivoryivorywhite answered 22/1, 2013 at 0:42 Comment(0)
L
33

Try the following:

#example figure1
ax1.plot(range(2),range(2),linewidth=2)
ax1.minorticks_on()
ax1.tick_params('both', length=20, width=2, which='major')
ax1.tick_params('both', length=10, width=1, which='minor')

You can repeat the same for ax2. Does this work for you?

Leatheroid answered 22/1, 2013 at 1:18 Comment(3)
How can you get a list of available parameters of axes.tick_params()?Resee
@Resee they are here in the docs matplotlib.org/api/_as_gen/…Apish
To hide an unwanted tickmark, I ended up with (slightly different syntax) ax.xaxis.set_tick_params(length=0, width=0, which='minor')Adaliah

© 2022 - 2024 — McMap. All rights reserved.