我无法更改带有双轴的绘图上的刻度标签属性。我希望文本很小,并且字体与默认字体不同。在我尝试使用 twiny() 之前,我找到了一种运行良好的方法。如图所示,第二个轴不响应刻度格式指令。我错过了一些重要的东西还是 matplotlib 中存在错误?
Ubuntu 12.04、Python 2.7.3、matplotlib 1.1.1rc
#!/usr/bin/env python
# coding: utf-8
from matplotlib import pyplot as p
from numpy import sin, cos, arange
x = arange(0, 10, .01)
for plotnum in range(1,5):
p.subplot(2, 2, plotnum)
ax1 = p.gca()
p.plot(sin(x),x)
ax2 = p.twiny()
p.plot(cos(x)+plotnum,x, 'g--')
# Set size all tick labels
# Works for first axes (lower x-ticks) and can also change font
for tickset in [ax1.xaxis.get_major_ticks()]:
[(tick.label.set_fontsize(plotnum*4), tick.label.set_fontname('ubuntu mono')) for tick in tickset]
# Does not work for second axes (upper x-ticks)
for tickset in [ax2.xaxis.get_major_ticks()]:
[(tick.label.set_fontsize(plotnum*2), tick.label.set_fontname('ubuntu mono')) for tick in tickset]
# This works, but doesn't allow changing font
#ax2.tick_params(axis='both', which='major', labelsize=plotnum*2)
这是一张图片:
编辑:修正了刻度线的不正确缩进
编辑:插入图像(Thriveth)