【发布时间】:2018-09-22 14:39:07
【问题描述】:
我想绘制数据中所有特征组合之间的散点图。为此,我使用了以下代码,但我得到了重叠的图表。
#importing the important libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import svm
from sklearn.cross_validation import train_test_split
from sklearn import metrics
from sklearn import datasets
wine_data = datasets.load_wine()
#exploring the ralationship between the data by visualizing it.
i = 1
plt.figure(figsize=(15,15))
for feature_x_pos,feature_x in enumerate(wine_data.feature_names):
for feature_y_pos,feature_y in enumerate(wine_data.feature_names):
if feature_x_pos != feature_y_pos:
plt.subplot(60,3,i)
plt.scatter(wine_data.data[:,feature_x_pos],wine_data.data[:,feature_y_pos],c = wine_data.target, cmap = 'jet')
plt.xlabel(feature_x)
plt.ylabel(feature_y)
i=i+1
葡萄酒数据包含 13 个特征。我想绘制所有特征对之间的散点图。 上述代码的输出如下所示:
我在 google colab 上做代码。
请帮助避免图表重叠。
【问题讨论】:
-
所以你想要一个 15x15 英寸的图形上的 180 个子图,每个子图都有标签,你不希望任何东西重叠?我认为这不太可行。
-
感谢@ThomasKühn 您的评论让我解决了这个问题。我只是增加了情节的长度( plt.figure(figsize=(15,190)) )。这是我犯的一个非常愚蠢的错误。再次感谢。
标签: python matplotlib scikit-learn