0

I have a dictionary whose values are consisted of dataframes. Every df has the same column names: X1 and X2:

dic = {"a": df1, "b": df2, ..., "y": df25}

Now I want to draw line plots of these dataframes so that they will be in 5 rows and 5 columns. I want to get a visual as follows:

enter image description here

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
burhancigdem
  • 105
  • 3

1 Answers1

1

The basic idea using matplotlib.pyplot.subplots:

import matplotlib.pyplot as plt

fig, axes = plt.subplots(5, 5)

for ax, (key, df) in zip(axes.flat, dic.items()):
    ax.set_title(key)
    ax.plot(df["X1"], df["X2"])
Anakhand
  • 2,838
  • 1
  • 22
  • 50
  • Dear @Anakhand, what about for this example: from sklearn.cluster import KMeans for i in range(1,len(dic)+1): data = dic[i] n_clusters = range(1, 10) kmeans = [KMeans(n_clusters=j).fit(data) for j in n_clusters] SSD = [kmeans[j].inertia_ for j in range(len(kmeans))] # within-cluster sum of squares. fig, axes = plt.subplots(5, 5) axes.plot(n_clusters, SSD) – burhancigdem Sep 21 '20 at 12:19