[Plot I need to make look better](https://i.sstatic.net/oTasaBzA.png)
This is the first question I am writing, sorry if something is not correct.
I’am trying to plot several subplots in same figure:
1)They can’t be plotted in a squared grid because each row rapresent a certain combination of measured value and i need to keep them like that
2)Each row contains different number of columns in function of the plotting combination which unable me to use fig.tight_layout() (I get the following error–> UserWarning: tight_layout not applied: number of columns in subplot specifications must be multiples of one another.)
3) Each subplot has the same x value common for all subplots in all figures for all the folders.
Maybe there is a way to do apply something similar to fig.tight_layout (maybe not on the figure but on the image after saving it as png)?
Also it would be great to have a legend but there is no space to place it so if you have any idea on how to generate a visible legend that would be great. Right now I prefered to have a dataframe or file which acts as legend.
def gen_figAx(dic, lvl_1, i_, folder_results_path):
x_val = 'Time_min'
for k1, v1 in dic.items():
fig = plt.figure(figsize = choose_size, clear=True)
if len(v1) == 0:
nosubgroups(k1, lvl_1, x_val, folder_results_path, fig)
continue
else:
n_rows = len(v1.keys())
c = 0
this_is_the_row_number = 0
remember_me = 0
for k2, v2 in v1.items():
n_cols = len(v2)
for k3, v3 in v2.items():
skip_me = False
for _finally in v3:
if _finally not in lvl_1.columns:
skip_me = True
break
if skip_me:
continue
if remember_me != v2:
grid = np.arange(1,n_rows*n_cols+1).reshape(n_rows, n_cols)
c = grid[this_is_the_row_number][0]
this_is_the_row_number += 1
ax = fig.add_subplot(n_rows, n_cols, c)
for _finally in v3:
ax.plot(lvl_1[x_val], lvl_1[_finally], label = _finally)
ax.set_title(k2+' '+k3, fontweight="bold")
#ax.legend()
c += 1
remember_me = v2
fig.suptitle(k1, fontsize = 15)
dir_ = os.path.abspath(os.path.join(folder_results_path, k1 +'.png'))
plt.subplot_tool()
plt.savefig(dir_)
plt.close(fig)
What didnt work:
plt.rcParams['figure.constrained_layout.use'] = True
fig.tight_layout
Right now I am using plt.subplot_tool(), adjusting each figure manually (I have 7 figures to manually adjust) exporting the results and then insert them in plt.subplot_adjust(top, bottom, left,right,hspace,wspace).
Gregorio Casagrande is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.