【3.6】matplotlib-ticks

Get the current locations and labels:

>>> locs, labels = xticks()

Set label locations:

>>> xticks(np.arange(0, 1, step=0.2))

Set text labels:

>>> xticks(np.arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue'))

Set text labels and properties:

>>> xticks(np.arange(12), calendar.month_name[1:13], rotation=20)

Disable xticks:

>>> xticks([])

子图设置ticks

1.Use the axes methods of the subplot object (e.g. ax.set_xticks and ax.set_xticklabels) or

import matplotlib.pyplot as plt
x = range(5)
y = range(5)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(x,y)
ax.set_xticks([0,2,4])
ax.set_xticklabels(['a','b','c'])
plt.show()

2.Use plt.sca to set the current axes for the pyplot state machine (i.e. the plt interface).

import matplotlib.pyplot as plt

fig, axes = plt.subplots(nrows=3, ncols=4)

# Set the ticks and ticklabels for all axes
plt.setp(axes, xticks=[0.1, 0.5, 0.9], xticklabels=['a', 'b', 'c'],
        yticks=[1, 2, 3])

# Use the pyplot interface to change just one subplot...
plt.sca(axes[1, 1])
plt.xticks(range(3), ['A', 'Big', 'Cat'], color='red')

fig.tight_layout()
plt.show()

修改ticks字体大小

plt.rc('xtick', labelsize=6) 
plt.rc('ytick', labelsize=6) 

参考资料:

个人公众号,比较懒,很少更新,可以在上面提问题:

更多精彩,请移步公众号阅读:

Sam avatar
About Sam
专注生物信息 专注转化医学