Ich versuche, dieses Bild mit sklearn.datasets.load_iris
und seaborn
zu erstellen. Ich mag die Idee, fig, ax = plt.subplots()
und dann seaborn
's ax=ax
Attribut zu tun. Ich kann nicht herausfinden, wie diese Handlung zu erstellen: Seaborn Histogramm mit 4 Panels (2 x 2) in Python
ich auf Stackoverflow geprüft und fanden diese aber überlagert sie How To Plot Multiple Histograms On Same Plot With Seaborn
Hier ist mein Code und Grundstück:
# Iris Dataset
from sklearn.datasets import load_iris
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
%matplotlib inline
DF_data = pd.DataFrame(load_iris().data,
columns = load_iris().feature_names,
index = ["iris_%d" % i for i in range(load_iris().data.shape[0])])
Se_targets = pd.Series(load_iris().target,
index = ["iris_%d" % i for i in range(load_iris().data.shape[0])],
name = "Targets")
#Visualizing Iris Data
D_targets = {0: 'Iris-Setosa',
1: 'Iris-Versicolor',
2: 'Iris-Virgnica'}
D_features = {0: 'sepal length [cm]',
1: 'sepal width [cm]',
2: 'petal length [cm]',
3: 'petal width [cm]'}
fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(8, 6))
idx_feature = 0
#Plot on 2 x 2 ax object
for i in range(ax.shape[0]):
for j in range(0, ax.shape[1]):
for idx_target, label_target in list(D_targets.items()):
sns.distplot(DF_data.as_matrix()[Se_targets==idx_target, idx_feature],
label=D_features[idx_feature],
kde=False,
bins=10,
ax=ax[i][j])
idx_feature += 1
plt.legend(loc='upper right', fancybox=True, fontsize=8)
plt.tight_layout()
plt.show()
Mein Grundstück sucht ziemlich schlecht:
UPDAT E:
Als Reaktion auf @Cel Antwort, habe ich dieses Diagramm erreicht, aber ich war nicht in der Lage, die Etiketten zu beheben und die Linien um die Plots zu verdunkeln.
Hey danke für die Antwort tun. Ich habe immer noch Probleme mit meinen Etiketten. Ich habe meine neue Handlung hinzugefügt. Ich habe das Wörterbuch mit den Etiketten überprüft, und die Etiketten werden an dieser Stelle korrekt gedruckt. –
'label = D_targets [idx_target]' behebt die Beschriftungen –