2016-04-14 72 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