2010-08-09 33 views

回答

15

爲了躲右和插曲的頂刺,你需要在兩個設置相關刺的顏色'none',以及爲xtick設置刻度位置爲'left',爲ytick設置'bottom'(以便隱藏刻度標記以及脊椎)。

不幸的是,目前還沒有人可以通過matplotlibrc訪問。在matplotlibrc中指定的參數經過驗證,然後存儲在一個名爲rcParams的字典中。然後由單個模塊檢查該字典中的一個鍵,其值將作爲其默認值。如果他們沒有檢查他們的選項之一,則該選項不能通過rc文件更改。

由於rc系統的性質,以及刺的編寫方式,改變代碼,允許這不會是簡單的:

棘目前通過用於定義相同rc參數獲得它們的顏色軸顏色;您不能將其設置爲'none'而不隱藏所有軸圖。他們也不知道他們是否是toprightleftbottom —這些實際上只是存儲在字典中的四個獨立的spine。單獨的脊柱物體不知道它們組成的圖的哪一側,所以您不能只在脊柱初始化期間添加新的rc參數並指定適當的一個。

self.set_edgecolor(rcParams['axes.edgecolor']) 

./matplotlib/lib/matplotlib/spines.py,__init __(),線54

如果有大量的現有代碼,使得將所述軸對每個參數手動設置參數會太麻煩,您可以交替使用輔助函數遍歷所有Axis對象併爲您設置值。

下面是一個例子:

import matplotlib 
import matplotlib.pyplot as plt 
import numpy as np 
from matplotlib.pyplot import show 

# Set up a default, sample figure. 
fig = plt.figure() 
x = np.linspace(-np.pi,np.pi,100) 
y = 2*np.sin(x) 

ax = fig.add_subplot(1,2,2) 
ax.plot(x,y) 
ax.set_title('Normal Spines') 

def hide_spines(): 
    """Hides the top and rightmost axis spines from view for all active 
    figures and their respective axes.""" 

    # Retrieve a list of all current figures. 
    figures = [x for x in matplotlib._pylab_helpers.Gcf.get_all_fig_managers()] 
    for figure in figures: 
     # Get all Axis instances related to the figure. 
     for ax in figure.canvas.figure.get_axes(): 
      # Disable spines. 
      ax.spines['right'].set_color('none') 
      ax.spines['top'].set_color('none') 
      # Disable ticks. 
      ax.xaxis.set_ticks_position('bottom') 
      ax.yaxis.set_ticks_position('left') 

hide_spines() 
show() 

show()之前只需致電hide_spines(),它會隱藏在所有的數字,show()顯示器。我想不出一個更簡單的方法來改變大量的數字,除了花時間來修補matplotlib並在rc中增加對所需選項的支持。

13

要matplotlib不要畫上,右刺,一個可以設置matplotlibrc文件

axes.spines.right : False 
axes.spines.top : False 
+0

以下您也可以卸載從頂部和右軸從matplotlibrc文件蜱? – jkokorian 2016-11-08 13:39:24

+0

@jkokorian:在即將發佈的matplotlib 2.0.0版本中,您可以設置'xtick.top'和'ytick.right'選項。 – Roun 2016-11-08 22:13:59

相關問題