Search code examples
pythonpandasscatter-plot

Is there a parameter like cmp(colormaps) of scatter3D in function: pd.plotting.scatter_matrix?


I have code like that, classified by their label:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import datasets

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

pd.plotting.scatter_matrix(df, c=y)

However, I want a qualitative colormaps in the result, like the 'Dark2' in cmap

fig = plt.figure()
ax = plt.axes(projection = '3d')
ax.scatter3D(df.values[:,0], df.values[:,1], df.values[:,2], c=y, cmap = 'Dark2')
plt.show()

Is there some way can achieve it, besides, I find a way in other question

color_wheel = {1: "#0392cf", 
               2: "#7bc043", 
               3: "#ee4035"}
colors = iris_data["target"].map(lambda x: color_wheel.get(x + 1))

Adding a color_wheel before making scatterplot, but the problem is I don't know if the color is qualitative, when the number of label is not sure...


Solution

  • All unmatched **kwargs for scatter_matrix are passed to pyplot.scatter so, if specific colours don't need to be assigned to specific groups, cmap can be passed directly to scatter_matrix:

    pd.plotting.scatter_matrix(df, c=y, cmap='Dark2')
    

    plot