I have a question that is very similar but not exactly the same as this and this questions.
I have 2 pyplot.subplots()
generating fig
and ax
objects, and I would like to add the last one to the last position of the first fig
.
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame({'a' :['one','one','two','two','one','two','one','one','one','two'], 'b': [1,2,1,2,1,2,1,2,1,1], 'c': [1,2,3,4,6,1,2,3,4,6]})
fig, ax = plt.subplots(ncols=3)
ax=ax.flatten()
for i in [0,1,2]:
if(i<2):
myvar=["b","c"][i]
sns.boxplot( data=df,
x='a', y=myvar, ax=ax[i])
### some other fig
fig2,ax2 = plt.subplots(figsize=(4,5))
g=sns.scatterplot(data=df, x='b', y='c')
### I have tried the following, but both of which return only the last figure generated
fig.axes.append(ax2) #
# or:
ax[2]=ax2
# I have also tried the following, but this returns an error:
#fig.add_axes(ax2)
plt.show()
Edit: Further, would it be possible to do this appending should the last figure have multiple rows or columns?