我有一定数量的数字需要生成并组织在子图中,我希望自动找到列和行的数量以指定我的子图。目前我找到的最好方法是计算我的总子图数量的平方根,将其向上取整至整数,并自动删除空白的子图。但当子图数量增加时,这种方法并不是最好的。你知道更好的方法吗?
import numpy as np
import matplotlib.pylab as plt
percentile = np.linspace(0.1,0.9,10)
test = np.linspace(0,10,123)
nb = int(np.sqrt(len(percentile))) + 1
# the "test" variable is not important. The "percentile" dictates how many subplots I want
fig, axs = plt.subplots(nb,nb, figsize=(15, 15), facecolor='w', edgecolor='k')
count = 0
for l in range(0,nb):
for c in range(0,nb):
if count < len(percentile):
axs[l,c].plot(test*percentile[count])
else:
axs[l,c].set_visible(False)
count = count + 1