

Therefore, the hack is to make two jointplots ( JG1 JG2), then make a new figure, then migrate the axes objects from JG1 JG2 to the new figure created.įinally, we adjust the sizes and the positions of subplots in the new figure we just created. jointplot calls JointGrid method, which in turn creates a new figure object every time it is called. It can not be easily done without hacking. Note that there might be several drawbacks from copying axes and the above is not (yet) tested thoroughly. G3 = sns.jointplot("sepal_width", "petal_length", data=iris, G2.map(plt.scatter, "total_bill", "tip", edgecolor="w") G2 = sns.FacetGrid(tips, col="time", hue="smoker") G0 = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips, The usage of this class would look like this: import matplotlib.pyplot as plt Self.sg.fig.set_size_inches(_size_inches()) Self._moveaxes(self.sg.ax_marg_y, self.subgrid)Īx.set_position(gs.get_position(self.fig)) Self._moveaxes(self.sg.ax_marg_x, self.subgrid) Self._moveaxes(self.sg.ax_joint, self.subgrid)

Self.subgrid = gridspec.GridSpecFromSubplotSpec(r+1,r+1, subplot_spec=self.subplot) H2= self.sg.ax_marg_x.get_position().height H= self.sg.ax_joint.get_position().height Self._moveaxes(self.sg.axes, self.subgrid) Self.subgrid = gridspec.GridSpecFromSubplotSpec(n,m, subplot_spec=self.subplot) Isinstance(self.sg, ):Įlif isinstance(self.sg, ): import matplotlib.pyplot as pltĭef _init_(self, seaborngrid, fig, subplot_spec): Note: This is a proof of concept, it may work for most easy cases, but I would not recommend using it in production code. The following is a class SeabornFig2Grid that can be called with a seaborn grid instance (the return of any of the above commands), a matplotlib figure and a subplot_spec, which is a position of a gridspec grid. The implementation is a bit more complicated that I had initially expected. The principle of this is shown in this answer and could be extended to Searborn plots. Note that this is currently restricted to be used with matplotlib 2.1 (possibly 2.0 as well).Īn alternative could be to create a seaborn figure and copy the axes to another figure. To use this, you would need to copy the axisgrid.py from the fork to the seaborn folder. There is a seaborn fork available which would allow to supply a subplot grid to the respective classes such that the plot is created in a preexisting figure. Those are PairGrid, FacetGrid, JointGrid, pairplot, jointplot and lmplot. This is hardcoded into the seaborn code, so there is currently no way to produce such plots in existing figures. The below is working with the current version of matplotlib.Īs has been pointed out at several places ( this question, also this issue) several of the seaborn commands create their own figure automatically. Moving axes in matplotlib is not as easy as it used to be in previous versions.
