【发布时间】:2021-08-03 23:12:00
【问题描述】:
我有这样的代码,按标签分类:
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)
但是,我想要结果中的定性颜色图,例如 cmap 中的“Dark2”
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()
有没有什么方法可以实现,另外我找到了方法in other question
color_wheel = {1: "#0392cf",
2: "#7bc043",
3: "#ee4035"}
colors = iris_data["target"].map(lambda x: color_wheel.get(x + 1))
在做散点图之前加个color_wheel,但是问题是不知道颜色是不是定性的,当label个数不确定的时候...
【问题讨论】:
标签: python pandas scatter-plot