holoviz / holoviz/hvplot

For numeric data scatter_matrix also displays the colour column in the grid

Open
#1,109 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
124
Avg merge
1d 18h
Merged PRs (30d)
1

Description

Hi there,

I was trying to plot some pandas data as [scatter_matrix](https://hvplot.holoviz.org/reference/pandas/scattermatrix.html). However, I noticed that the colour column must be specified as a non-numeric value. If the column to be used for colouring is also a numeric value, it will be plotted as a separate variable within the grid.

This is most likely due to [line 166](https://github.com/holoviz/hvplot/blob/cfa578d0045364f66244735e41cb6e6038e83c5f/hvplot/plotting/scatter_matrix.py#L166) in the scatter_matrix file, as the grid is first plotted with all columns and then the colour is added. Unfortunately, if this line is replaced with a holoviews.dataset without the colour column, some other errors occur...

If the colour column is converted to a string, everything works fine. If this is the way to use this function, I would appreciate a small note in the documentation!
This issue is relevant when colouring with cluster labels, which are usually ints.

#### Minimal reproducible example

```
from hvplot.plotting import scatter_matrix
from sklearn.datasets import load_iris
import pandas as pd

iris = load_iris()
X = iris.data
y = iris.target
df = pd.DataFrame(X, columns = iris.feature_names)

df['color'] = y#.astype(str)
scatter_matrix(df, c='color', alpha=0.8)

```

##### Without String cast:

![without_str_cast](https://github.com/holoviz/hvplot/assets/107886611/4b7d9a77-6998-4274-ac55-7684ccecbfe9)

##### With String cast:

![with_str_cast](https://github.com/holoviz/hvplot/assets/107886611/29221621-2b49-4db1-96a6-8d94a23218a8)

##### software versions

Python implementation: CPython
Python version : 3.10.12
IPython version : 8.14.0

pandas : 1.5.3
matplotlib: 3.7.2
hvplot : 0.8.4
holoviews : 1.16.2
sklearn : 1.3.0
seaborn : 0.11.2
jupyterlab: 4.0.3

Working on macOS 13.4.1 (c) (22F770820d) in Visual Studio Code (Version: 1.80.1)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.