2016-04-14 74 views
1

matplotlib颜色,我需要一些背景行添加到我的人物,如粗体线x=0y=0和对角线。每当我改变图的颜色方案/“样式”时,我都必须手动改变这些线的颜色。获取从样式板

有没有办法检索当前人物风格的颜色?

回答

3

我不知道我完全理解你想实现什么,但你可能会发现plt.style.library有用:

让我们bmh风格作为一个例子。

调用plt.style.library['bmh']会产生:

RcParams({u'axes.edgecolor': u'#bcbcbc', 
      u'axes.facecolor': u'#eeeeee', 
      u'axes.grid': True, 
      u'axes.labelsize': u'large', 
      u'axes.prop_cycle': cycler(u'color', [u'#348ABD', u'#A60628', u'#7A68A6', u'#467821', u'#D55E00', u'#CC79A7', u'#56B4E9', u'#009E73', u'#F0E442', u'#0072B2']), 
      u'axes.titlesize': u'x-large', 
      u'legend.fancybox': True, 
      u'lines.linewidth': 2.0, 
      u'mathtext.fontset': u'cm', 
      u'patch.antialiased': True, 
      u'patch.edgecolor': u'#eeeeee', 
      u'patch.facecolor': u'blue', 
      u'patch.linewidth': 0.5, 
      u'text.hinting_factor': 8}) 

所以如果你需要一个特定的设置,你访问它是这样的:

plt.style.library['bmh']['axes.facecolor'] 

这给:

u'#eeeeee' 

附:上面的代码假设你有这样导入:

import matplotlib.pyplot as plt 
+0

谢谢!以及如何获得当前激活哪种配色方案? –

+0

我不认为有'matplotlib'内置函数可以做到这一点。据我所知可以归结为检查你的'rcParams'中有哪些值是活动的。 – Primer