这是这篇文章的一个后续问题,其中讨论了轴,刻度和标签的着色.我希望为此开一个新的,扩展的问题是可以的.
add_subplot使用轴[ax1,ax2] 围绕双图(通孔)更改完整框架(刻度线和轴)的颜色会产生大量代码.此代码段会更改上图的框架颜色:
ax1.spines['bottom'].set_color('green')
ax1.spines['top'].set_color('green')
ax1.spines['left'].set_color('green')
ax1.spines['right'].set_color('green')
for t in ax1.xaxis.get_ticklines(): t.set_color('green')
for t in ax1.yaxis.get_ticklines(): t.set_color('green')
for t in ax2.xaxis.get_ticklines(): t.set_color('green')
for t in ax2.yaxis.get_ticklines(): t.set_color('green')
Run Code Online (Sandbox Code Playgroud)
因此,为了改变两个图的帧颜色,每个两个y轴,我需要16(!)行代码...这是它的样子:

到目前为止我挖出的其他方法:
matplotlib.rc:这里讨论; 全球而非本地变化.我想要一些不同颜色的其他情节.请不要在情节中讨论太多颜色...... :-)
matplotlib.rc('axes',edgecolor='green')
Run Code Online (Sandbox Code Playgroud)挖出轴的刺,然后改变它:这里也讨论过 ; 我觉得并不是很优雅.
for child in ax.get_children():
if isinstance(child, matplotlib.spines.Spine):
child.set_color('#dddddd')
Run Code Online (Sandbox Code Playgroud)是否有一种优雅的方式来凝聚上面的块,更多的是"pythonic"?
我在ubuntu下使用python 2.6.5和matplotlib 0.99.1.1.