so I have a canvas with a figure in matplotlib and I would like to add the plot output of a seaborn facetgrid object to it. the seaborn catplot function (which I need) returns me a facetgrid but how can I add the ax to the matplotlib.pyplot.figure ? It would be also fine if I could specify the figure_id (=num) for facetgrid.fig. (normally I would just call sns.swarmplot() and the figure is added)
thanks in advance !!
example code with approaches I tried:
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
### example data
test_data = {'sample': ['id_1', 'id_2', 'id_1','id_2'],
'val': [1, 2, 3, 2],
'cond':['cond_1','cond_1','cond_2','cond_2']}
df = pd.DataFrame(data = test_data)
figure_id = 17
fig = plt.figure(num=figure_id)
fg = sns.catplot(x="cond", y="val", hue="sample", kind="point", data = df) # returns facetgrid
### draw fg.ax on figure with num 17
### tried out different ways to copy it into the subplot or ax object
# fig, ax = plt.subplots(1,1, num=figure_id)
# ax = fg.ax # => shows coordinates but no data
# fig.axes.append(fg.ax) # also do not work
# fig.add_subplot(fg.subplots)