大熊猫散射矩阵

问题描述 投票:0回答:1

我试图用完整的数据帧和它的子集选择绘制散点图。我想在一个和子集中绘制另一种颜色的全数据框的叠加。我尝试这样做:

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

python pandas matplotlib scatter-plot
1个回答
2
投票

这看起来像熊猫中的一个小虫。以下是它应该是这样的:

pandas/plotting/_tools.pyline 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))
© www.soinside.com 2019 - 2024. All rights reserved.