熊猫散射矩阵

时间:2019-03-15 10:40:31

标签: python pandas matplotlib scatter-plot

我正在尝试绘制具有完整数据帧及其子集选择的散点图。我想将一个和子集都绘制为全数据帧的另一种颜色的覆盖图。我尝试这样做:

ax1 = scatter_matrix(entireColumns,color='Blue', alpha=0.4, figsize=(20, 20), diagonal='hist')
ax2 = scatter_matrix(selectedPoints,color='Red', alpha=0.4, figsize=(20, 20), diagonal='hist',ax=ax1)

但是我得到了错误:

     57             ax1 = scatter_matrix(entireColumns,color='Blue', alpha=0.4, figsize=(20, 20), diagonal='hist')#hist_kwds={'bins':5}#'kde#,color=colors
---> 58             ax2 = scatter_matrix(selectedPoints,color='Red', alpha=0.4, figsize=(20, 20), diagonal='hist',ax=ax1)
     59             plt.show()
     60             #parallel_coordinates(entireColumns, subsetColumns[0],color=('#556270', '#4ECDC4', '#C7F464'))

/usr/local/lib/python3.5/dist-packages/pandas/plotting/_misc.py in scatter_matrix(frame, alpha, figsize, ax, grid, diagonal, marker, density_kwds, hist_kwds, range_padding, **kwds)
     82     for i, a in zip(lrange(n), df.columns):
     83         for j, b in zip(lrange(n), df.columns):
---> 84             ax = axes[i, j]
     85 
     86             if i == j:

IndexError: too many indices for array

不带ax参数,两个都打印:

enter image description here

1 个答案:

答案 0 :(得分:2)

这看起来像是熊猫中的虫子。而是这样的样子:

pandas/plotting/_tools.py中转到line 196。那里的代码看起来像这样:

if ax is None:
    fig = plt.figure(**fig_kw)
else:
    if is_list_like(ax):
        ax = _flatten(ax)
        if layout is not None:
            warnings.warn("When passing multiple axes, layout keyword is "
                          "ignored", UserWarning)
        if sharex or sharey:
            warnings.warn("When passing multiple axes, sharex and sharey "
                          "are ignored. These settings must be specified "
                          "when creating axes", UserWarning,
                          stacklevel=4)
        if len(ax) == naxes:
            fig = ax[0].get_figure()
            return fig, ax
        else:
            raise ValueError("The number of passed axes must be {0}, the "
                             "same as the output plot".format(naxes))

替换为

if ax is None:
    fig = plt.figure(**fig_kw)
else:
    if is_list_like(ax):
        fax = _flatten(ax)
        if layout is not None:
            warnings.warn("When passing multiple axes, layout keyword is "
                          "ignored", UserWarning)
        if sharex or sharey:
            warnings.warn("When passing multiple axes, sharex and sharey "
                          "are ignored. These settings must be specified "
                          "when creating axes", UserWarning,
                          stacklevel=4)
        if len(fax) == naxes:
            fig = fax[0].get_figure()
            if squeeze:
                return fig, fax
            else:
                return fig, ax
        else:
            raise ValueError("The number of passed axes must be {0}, the "
                             "same as the output plot".format(naxes))