I am new to python/coding and apologize if my question is too basic to have an answer available online as i am having a hard time finding the solution to my problem. I want to append multiple BytesIO() objects together and later write them as a single pdf file. Below is the code that i have managed so far. The tmp3 object bytes are equal to sum of tmp and tmp2 objects, however when i write tmp3 to disk, i get a single page pdf file with only the tmp2 figure. Please let me how can i manage to get a pdf with both the figures and on separate pages. Any suggestions involving a totally different approach are also welcomed.
cols = data.columns.values
col = cols.tolist()
g = sns.PairGrid(data[col])
g.map_diag(sns.histplot) #, hue=data['tar'], color='.9'
g.map_upper(sns.scatterplot) #, hue=data['tar']
g.map_lower(sns.kdeplot,cmap="Set2")
tmp = BytesIO()
plt.savefig(tmp, format='pdf')
t=tmp.tell()
tmp.seek(0)
tmp2 = BytesIO()
fig, ax = plt.subplots(figsize=(20,15))
sns.heatmap(data.corr(),cmap='coolwarm', annot=True, fmt=".1f", ax=ax)
plt.savefig(tmp2,format='pdf')
p=tmp2.tell()
tmp2.seek(0)
tmp3 = BytesIO()
s = tmp3.tell()
tmp3.write(tmp.getvalue())
tmp3.write(tmp2.getvalue())
ss = tmp3.tell()
tmp3.seek(0)
temporarylocation="pairgrid.pdf"
with open(temporarylocation,'wb') as out:
out.write(tmp3.read())