这是对this帖子的后续问题,讨论了轴线、刻度和标签的着色。我希望可以开一个新的、扩展的问题来讨论。
通过
通过
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')
所以,要更改带有两个y轴的两个图的框架颜色,我需要16行代码... 这就是它的样子:
到目前为止,我挖掘出来的其他方法有:
matplotlib.rc: discussed here; changes globally, not locally. I want to have some other plots in different colors. Please, no discussions about too many colors in plots... :-)
matplotlib.rc('axes',edgecolor='green')
dig out the spines of the axis, then change it: also discussed here; not really elegant, I think.
for child in ax.get_children(): if isinstance(child, matplotlib.spines.Spine): child.set_color('#dddddd')
有没有一种更加"Pythonic"的优雅方式来压缩上面的代码块?
我正在使用在Ubuntu下的Python 2.6.5和matplotlib 0.99.1.1。