Skip to content

ENH: pandas.plotting.scatter_matrix to support plotting function hexbin in addition to scatter #56887

Open
@shadiakiki1986

Description

@shadiakiki1986

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I wish I could use the scatter_matrix function to make hexbin plots

Feature Description

Add a new parameter nondiagonal to scatter_matrix to support hexbin instead of scatter

def scatter_matrix(...):
    ...
    if nondiagonal=="scatter":
        ax.scatter(...)
    if nondiagonal=="hexbin":
        ax.hexbin(...)
    ...

Alternative Solutions

Seaborn pairplot using kind = hist. Link: https://seaborn.pydata.org/generated/seaborn.pairplot.html

Additional Context

The general consensus on pandas.plotting.scatter_matrix is that "seaborn does this better" (ref 1, ref 2). Nevertheless, the functionality was kept, and the changes to support this feature are a few lines of code.

The quality of the plots can improve significantly. Here's an example with scatter:

# Copy of example from scatter_matrix docs page, but increase data frame rows from 1k to 10k:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(1_0_000, 4), columns=['A','B','C','D'])

image

Same example with hexbin:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions