0

Using seaborn, I created two Facetgrid (seaborn.axisgrid.FacetGrid) plots as follows:

#load dataset
import pandas as pd
iris=pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')

#plotting
import matplotlib.pyplot as plt
import seaborn as sns

g1 = sns.FacetGrid(pd.melt(iris.loc[:,['sepal_length','sepal_width','species']], id_vars='species'), col='variable')
g1.map(sns.boxplot, 'species','value',order=['setosa','versicolor','virginia'])
g2 = sns.FacetGrid(iris, col="species")
g2.map(plt.scatter, "sepal_length", "sepal_width")

Two separate plots were generated:

enter image description here

and

enter image description here

I would like to have them in a single figure (and save as a single pdf file). However, I could not find any way to concatenate the plots (through python). I can always use Illustrator/Inkscape or bash commands to concatenate separate plots. However I want to avoid that and do all the steps in python alone.

I tried fig.axes.append (fig.axes.append(g1.axes.flatten()[0])), but the subplots ended up overlapping each other.

enter image description here

Question: Is it possible to concatenate two seaborn-Facegrid plots?

  • 1
    It's possible to get several seaborn FacetGrids in the same figure, but it's not the intended usage of FacetGrid. A solution is shown in [How to plot multiple Seaborn Jointplot in Subplot](https://stackoverflow.com/questions/35042255/how-to-plot-multiple-seaborn-jointplot-in-subplot). – ImportanceOfBeingErnest May 27 '18 at 18:52
  • That solved my question. You could have *answered* the question rather than commenting. –  May 30 '18 at 15:09
  • If the answer to a question is given in another question, one does not answer this question, but instead mark it as duplicate. – ImportanceOfBeingErnest May 30 '18 at 15:15

1 Answers1

0

Personally when I need to have multiple figures displayed together I will have an html output with embedded references to each of the plots I want to display. That way you can review the analysis all in one place on a browser.

kpie
  • 9,588
  • 5
  • 28
  • 50
  • I am trying to make multi-panel plots in python, similar to [`patchwork` module of R](https://github.com/thomasp85/patchwork). –  May 27 '18 at 18:48