The MRE has numerous errors before you even get to the 'no luck' block. I was able to fix some but maybe lost the idea of the desired layout?
import numpy as np
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
label=['hc','svppa','nfvppa','lvppa']
test_df_data ={"id":list(range(1,21,1)), "label": list(np.repeat(label, 5)), "col1":list(np.random.normal(100,10,size=20)), "col2":list(np.random.normal(100,10,size=20)), "col3":list(np.random.normal(100,10,size=20)),
"col4":list(np.random.normal(100,10,size=20)), "col5":list(np.random.normal(100,10,size=20)), "col6":list(np.random.normal(100,10,size=20)), "col7":list(np.random.normal(100,10,size=20))}
df = pd.DataFrame(test_df_data)
df
id | label | col1 | col2 | col3 | col4 | col5 | col6 | col7 | |
---|---|---|---|---|---|---|---|---|---|
0 | 1 | hc | 97.587739 | 101.874805 | 103.457598 | 82.941673 | 106.842303 | 103.345810 | 70.455917 |
1 | 2 | hc | 115.564636 | 109.755277 | 82.617395 | 85.282335 | 106.780071 | 107.735767 | 95.819053 |
2 | 3 | hc | 106.419750 | 103.359737 | 108.847862 | 103.445402 | 89.641199 | 102.482684 | 100.178844 |
3 | 4 | hc | 102.087488 | 88.761079 | 102.509562 | 94.669953 | 107.727890 | 98.574327 | 111.697648 |
4 | 5 | hc | 117.493780 | 101.749875 | 105.918971 | 98.286336 | 96.209939 | 104.127130 | 108.542257 |
5 | 6 | svppa | 102.080954 | 109.853685 | 96.593493 | 97.682346 | 99.303039 | 99.676664 | 106.347990 |
6 | 7 | svppa | 108.295776 | 98.012991 | 89.360831 | 106.793674 | 87.214201 | 102.991513 | 99.355703 |
7 | 8 | svppa | 115.131664 | 98.662261 | 116.982811 | 91.280657 | 77.633909 | 90.398508 | 107.661131 |
8 | 9 | svppa | 95.000068 | 99.235797 | 97.030538 | 105.077247 | 118.084141 | 114.922799 | 86.693918 |
9 | 10 | svppa | 100.420936 | 88.488289 | 102.012507 | 110.186484 | 86.205137 | 112.081470 | 102.873938 |
10 | 11 | nfvppa | 104.561738 | 97.394611 | 96.559459 | 110.780437 | 94.784928 | 99.688330 | 86.172906 |
11 | 12 | nfvppa | 99.343361 | 82.743137 | 89.437864 | 103.287516 | 114.686480 | 103.833313 | 95.549801 |
12 | 13 | nfvppa | 89.400168 | 110.943866 | 88.298805 | 92.537603 | 101.024211 | 91.719686 | 106.978458 |
13 | 14 | nfvppa | 106.260450 | 97.058619 | 93.221451 | 90.912102 | 94.855483 | 106.528832 | 107.713324 |
14 | 15 | nfvppa | 107.289824 | 99.131076 | 114.171180 | 107.517890 | 98.019672 | 111.565300 | 115.646669 |
15 | 16 | lvppa | 108.183931 | 96.396276 | 87.411387 | 101.703906 | 103.529008 | 86.452628 | 106.701789 |
16 | 17 | lvppa | 120.152256 | 114.944839 | 95.997684 | 97.334895 | 103.696473 | 84.900775 | 92.512917 |
17 | 18 | lvppa | 105.746615 | 84.793394 | 96.136802 | 96.433625 | 103.912430 | 99.632061 | 95.786131 |
18 | 19 | lvppa | 103.607184 | 103.031657 | 100.594585 | 97.168775 | 95.783785 | 90.396765 | 90.186467 |
19 | 20 | lvppa | 101.846578 | 109.826204 | 112.105245 | 100.937288 | 112.402979 | 96.840076 | 97.675947 |
# What OP had, I think
labels = set(df.label.to_list())
columns = df.columns[2:].to_list()
for col in columns:
for label in labels:
stats.probplot(df[df['label']==label][col], dist='norm', plot=plt)
plt.title("Probability plot " + col + " - " + label)
plt.show()
# based on https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.probplot.html
# and method 2 at https://engineeringfordatascience.com/posts/matplotlib_subplots/
plt.figure(figsize=(45, 12))
plt.subplots_adjust(hspace=0.5)
for n, label in enumerate(labels):
for m,col in enumerate(columns):
ax = plt.subplot(len(labels), len(columns), ((len(columns)-1)*n)+(m+(n+1)))
b = stats.probplot(df[df['label']==label][col], dist='norm', plot=ax)
plt.title("Probability plot " + col + " - " + label)
plt.subplots_adjust(top=1.15) # based on https://www.statology.org/matplotlib-subplot-spacing/ to fix title of subplot overlapping with x-axes label
plt.savefig('test_save.png', bbox_inches="tight") # based on https://stackoverflow.com/a/47956856/8508004
Double click on the file test_save.png
in the file navigator pane to view the plots in their full glory if you are using JupyterLab.