patchworklib icon indicating copy to clipboard operation
patchworklib copied to clipboard

How to load a matplotlib / seaborn plot that was already created

Open ThomVett opened this issue 1 year ago • 0 comments

Hello,

Thanks for this cool library - super helpful!

I'm creating plots in multiple notebooks / python scripts and save them to pickle. Than from a central notebook I combine them in the final figure using patchworklib. to do this i am trying it in two different ways:

  • Exporting bricks object to pickle and loading the pickle object somewhere else
import seaborn as sns
import patchworklib as pw
ax = pw.Brick(figsize=(3, 2))
sns.lineplot(melted_dilution, x="VAF %", y="Metric Value", hue="Metric", ax=ax)
dump_to_pickle(ax)

and than in another notebook

ax = load_pickle(path_to_file)
ax.savefid()
  • Exporting the matplotlib figure object, loading it in the other notebook and putting the ax in the Bricks object
import seaborn as sns
ax=sns.lineplot(melted_dilution, x="VAF %", y="Metric Value", hue="Metric")
dump_to_pickle(ax.get_figure())

and than in another notebook

fig = load_pickle(path_to_file)
brick =pw.Brick(ax=fig.axes[0])

the problem i have is that in both of these ways:

  • the bricks object contains the figure and the axes (i.e brick.figure returns the plot)
  • but if i do brick.savefig("test.png") or just brick in the notebook there is only a blank canvas.

any advice on how to do this?

Thanks a lot!

ThomVett avatar Jul 10 '24 15:07 ThomVett