Make longer subplot tick marks in matplotlib?

这一生的挚爱 提交于 2019-12-04 15:55:45

问题


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()

回答1:


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?



来源:https://stackoverflow.com/questions/14449753/make-longer-subplot-tick-marks-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!