2016-07-31 56 views
4

以下步驟在jupyter筆記本內部進行,試圖使seaborn.pairplot()工作。來自/usr/local/lib/python2.7/site-packages/matplotlib/matplotlib/transforms.pyc的錯誤使該功能停止工作。Seaborn OS X:seaborn.pairplot()ValueError:'transform'必須是'matplotlib.transform.Transform'的實例

下面是Python庫版本:

print(matplotlib.__version__, sns.__version__) 

('1.5.1', '0.7.1') 

虹膜數據集的CSV格式讀取

data = pandas.read_csv('iris.csv') 
data_no_nans = data.dropna() 
sns.pairplot(data_no_nans) 

錯誤消息:

ValueError        Traceback (most recent call last) 
<ipython-input-4-001343d0343b> in <module>() 
----> 1 sns.pairplot(data) 

/usr/local/lib/python2.7/site-packages/seaborn/linearmodels.pyc in pairplot(data, hue, hue_order, palette, vars, x_vars, y_vars, kind, diag_kind, markers, size, aspect, dropna, plot_kws, diag_kws, grid_kws) 
    1588      hue_order=hue_order, palette=palette, 
    1589      diag_sharey=diag_sharey, 
-> 1590      size=size, aspect=aspect, dropna=dropna, **grid_kws) 
    1591 
    1592  # Add the markers here as PairGrid has figured out how many levels of the 

/usr/local/lib/python2.7/site-packages/seaborn/axisgrid.pyc in __init__(self, data, hue, hue_order, palette, hue_kws, vars, x_vars, y_vars, diag_sharey, size, aspect, despine, dropna) 
    1253   if despine: 
    1254    utils.despine(fig=fig) 
-> 1255   fig.tight_layout() 
    1256 
    1257  def map(self, func, **kwargs): 

/usr/local/lib/python2.7/site-packages/matplotlib/figure.pyc in tight_layout(self, renderer, pad, h_pad, w_pad, rect) 
    1752           renderer, 
    1753           pad=pad, h_pad=h_pad, w_pad=w_pad, 
-> 1754           rect=rect) 
    1755 
    1756   self.subplots_adjust(**kwargs) 

/usr/local/lib/python2.7/site-packages/matplotlib/tight_layout.pyc in get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer, pad, h_pad, w_pad, rect) 
    347          subplot_list=subplot_list, 
    348          ax_bbox_list=ax_bbox_list, 
--> 349          pad=pad, h_pad=h_pad, w_pad=w_pad) 
    350 
    351  if rect is not None: 

/usr/local/lib/python2.7/site-packages/matplotlib/tight_layout.pyc in auto_adjust_subplotpars(fig, renderer, nrows_ncols, num1num2_list, subplot_list, ax_bbox_list, pad, h_pad, w_pad, rect) 
    126   tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots]) 
    127   tight_bbox = TransformedBbox(tight_bbox_raw, 
--> 128          fig.transFigure.inverted()) 
    129 
    130   row1, col1 = divmod(num1, cols) 

/usr/local/lib/python2.7/site-packages/matplotlib/matplotlib/transforms.pyc in __init__(self, bbox, transform, **kwargs) 
    1080    msg = ("'transform' must be an instance of" 
    1081     " 'matplotlib.transform.Transform'") 
-> 1082    raise ValueError(msg) 
    1083   if transform.input_dims != 2 or transform.output_dims != 2: 
    1084    msg = "The input and output dimensions of 'transform' must be 2" 

ValueError: 'transform' must be an instance of 'matplotlib.transform.Transform' 

Regplot完美的作品

sns.regplot(x="petal_length", y="petal_width", data=data) 

編輯

我懷疑它與matplotlib的字體管理器發生故障的事情。我刪除了〜/ .cache/fontconfig的和辛辣的目錄,並得到了一個新的錯誤消息:AttributeError的:「模塊」對象有沒有屬性「鎖定」

AttributeError       Traceback (most recent call last) 
<ipython-input-3-001343d0343b> in <module>() 
----> 1 sns.pairplot(data) 

/usr/local/lib/python2.7/site-packages/seaborn/linearmodels.pyc in pairplot(data, hue, hue_order, palette, vars, x_vars, y_vars, kind, diag_kind, markers, size, aspect, dropna, plot_kws, diag_kws, grid_kws) 
    1588      hue_order=hue_order, palette=palette, 
    1589      diag_sharey=diag_sharey, 
-> 1590      size=size, aspect=aspect, dropna=dropna, **grid_kws) 
    1591 
    1592  # Add the markers here as PairGrid has figured out how many levels of the 

/usr/local/lib/python2.7/site-packages/seaborn/axisgrid.pyc in __init__(self, data, hue, hue_order, palette, hue_kws, vars, x_vars, y_vars, diag_sharey, size, aspect, despine, dropna) 
    1253   if despine: 
    1254    utils.despine(fig=fig) 
-> 1255   fig.tight_layout() 
    1256 
    1257  def map(self, func, **kwargs): 

/usr/local/lib/python2.7/site-packages/matplotlib/figure.pyc in tight_layout(self, renderer, pad, h_pad, w_pad, rect) 
    1737   """ 
    1738 
-> 1739   from .tight_layout import (get_renderer, get_tight_layout_figure, 
    1740         get_subplotspec_list) 
    1741 

/usr/local/lib/python2.7/site-packages/matplotlib/tight_layout.py in <module>() 
    15 from matplotlib.transforms import TransformedBbox, Bbox 
    16 
---> 17 from matplotlib.font_manager import FontProperties 
    18 rcParams = matplotlib.rcParams 
    19 

/usr/local/lib/python2.7/site-packages/matplotlib/matplotlib/font_manager.py in <module>() 
    1448     verbose.report("Using fontManager instance from %s" % _fmcache) 
    1449   except: 
-> 1450    _rebuild() 
    1451  else: 
    1452   _rebuild() 

/usr/local/lib/python2.7/site-packages/matplotlib/matplotlib/font_manager.py in _rebuild() 
    1433 
    1434   if _fmcache: 
-> 1435    with cbook.Locked(cachedir): 
    1436     json_dump(fontManager, _fmcache) 
    1437 

AttributeError: 'module' object has no attribute 'Locked' 
+0

適用於我的相同版本。 –

+0

我猜它值得一提的是它的自制matplotlib和pip seaborn安裝。 – FreedomToWin

回答

1

所以我現在回答我的問題。

我用MacPorts的虛擬環境

sudo port selfupdate 
sudo port install python27 
sudo port install py27-virtualenv 


/opt/local/bin/virtualenv-2.7 $HOME/local/python/27 

添加到.bash_profile中解決了這個問題:在終端

alias py27="source $HOME/local/python/27/bin/activate" 

運行設置虛擬env和與PIP安裝所需的軟件包。

py27 
which pip 
    $HOME/local/python/27/bin/pip 
pip install ipython etc 

奇怪的是,自制安裝錯誤,我想知道是否有任何衝突的軟件包安裝。

不知道它的相關,但這裏是我的.bash_profile:

# some settings to prefer homebrew paths in case it exists: 
if which -s brew ; then 
    PATH="/usr/local/bin:/usr/local/sbin:$PATH" 
fi 

# set PATH so it includes user's private bin if it exists 
if [ -d "$HOME/bin" ] ; then 
    PATH="$HOME/bin:$PATH" 
fi 

這可能問題而搞亂的東西了。

+0

我沒有那些自制開關:但我確實得到了同樣的錯誤。 'brew matplotlib'中有一些不妥之處 – javadba

相關問題