【发布时间】:2011-12-08 09:37:53
【问题描述】:
这是this 帖子的一种后续问题,其中讨论了轴、刻度和标签的颜色。我希望可以为此打开一个新的扩展问题。
使用轴 [ax1, ax2] 围绕双图(通过add_subplot)更改完整框架(刻度和轴)的颜色会导致大量代码。这个 sn-p 改变了 上图的框架的颜色:
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:讨论过here;全局变化,而不是局部变化。我想要其他一些不同颜色的图。请不要讨论情节中的颜色过多... :-)
matplotlib.rc('axes',edgecolor='green') -
挖出轴的刺,然后改变它:还讨论了here;我认为不是很优雅。
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。
【问题讨论】:
标签: python colors matplotlib