0

So I have this function that returns a regression plot (Axes object) using seaborn, and I want to place it in a pyplot figure where there are 4 axes spaces:

    def plot_reg(self, cal_dict):
        '''Function to plot the polynomial regression curve'''
    
        regression_plot = sns.regplot(data = cal_dict,
                             x = cal_dict['x'], 
                             y = cal_dict['y'], 
                             ci = None,
                             line_kws = {"color" : 'red'},
                             order = 2
                            )
    
        regression_plot.set_xlabel("x")
        regression_plot.set_ylabel("y")
        regression_plot.set_title(f'StackOverFlow')
        
        return regression_plot

fig, ax = plt.subplots(2, 2)
ax[0][0] = plot_reg(cal_dict)
ax[0][1] = plot_reg(cal_dict2)
...

Is this possible?

LoloTheKid
  • 21
  • 3
  • 1
    No, you can't move an already created plot. The way to go is to create the plot on the desired ax from the start. So, adding a parameter `ax` to `plot_reg`, then calling `sns.regplot(...., ax=ax)` and call `plot_reg(..., ax=ax[0, 0])`. – JohanC Dec 10 '20 at 08:39
  • Halleluyah this worked!! Thanks a lot :) – LoloTheKid Dec 10 '20 at 08:54

0 Answers0