分散矩阵中的多个数据 [英] Multiple data in scatter matrix
问题描述
是否可以将多个数据添加到pandas.tools.plotting.scatter_matrix
并为每组数据分配颜色?
Is it possible to add multiple data to a pandas.tools.plotting.scatter_matrix
and assigning a color to each group of data?
我想在同一散布矩阵中以绿色显示一组数据的散点图,假设一组数据以红色显示.对角线上的密度图也应如此.
我知道可以通过使用matplotlib的scatter
函数来做到这一点,但这并不能为我提供分散矩阵.
I'd like to show the scatter plots with data points for one group of data, let's say, in green and the other group in red in the very same scatter matrix. The same should apply for the density plots on the diagonal.
I know that this is possible by using matplotlib's scatter
function, but that does not give me a scatter matrix.
关于熊猫的文献很少.
推荐答案
简短的答案是确定散点图中每个点的颜色,将其作用于数组中并将其作为color
参数传递.
The short answer is determine the color of each dot in the scatter plot, role it into an array and pass it as the color
argument.
示例:
from pandas.tools.plotting import scatter_matrix
import pandas as pd
from sklearn import datasets
iris = datasets.load_iris()
iris_data = pd.DataFrame(data=iris['data'],columns=iris['feature_names'])
iris_data["target"] = iris['target']
color_wheel = {1: "#0392cf",
2: "#7bc043",
3: "#ee4035"}
colors = iris_data["target"].map(lambda x: color_wheel.get(x + 1))
ax = scatter_matrix(iris_data, color=colors, alpha=0.6, figsize=(15, 15), diagonal='hist')
这篇关于分散矩阵中的多个数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!