Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

figurefirst and matplotlib figure objects #41

Open
jfear opened this issue Oct 2, 2018 · 3 comments
Open

figurefirst and matplotlib figure objects #41

jfear opened this issue Oct 2, 2018 · 3 comments

Comments

@jfear
Copy link

jfear commented Oct 2, 2018

FigureFirst looks like a very exciting project, your have identified a major pain point for many people.

I was looking through the documentation, and I was wondering if you had any suggestions for placing a separate mpl.Figure() onto a FigureFirst axis. For example, some of seaborn's more complicated plots (e.g., clustermap, FacetGrid) use gridspec under the hood to build an entire figure. There is no way to pass a mpl.Axes() to the plotting function.

The only possible solution I could think of is: create the seaborn figure, save it as SVG, and then import and add that to the FigureFirst template. Is it possible to import an separate SVG image and add that to a FigureFirst axis? If not it would be a nice feature.

Thanks again for the neat tool, I am going to start playing with it.

@psilentp
Copy link
Member

psilentp commented Oct 2, 2018

Hi @jfear glad it helps. I think there might be a solution using the figure templating function. @florisvb what do you think?

@florisvb
Copy link
Collaborator

florisvb commented Oct 2, 2018 via email

@jfear
Copy link
Author

jfear commented Oct 2, 2018

Thank you for the quick response.

Environment

# python 3.6
numpy==1.13.1
seaborn==0.9.0
matplotlib==2.2.3

I would like generate something like this:

import numpy as np
import seaborn as sns

dat = np.random.rand(100).reshape(10, 10)
g = sns.clustermap(dat)
g.fig.savefig('clustermap.svg')

I would then want to clustermap.svg and add it to a FigureFirst template. Something like:

import numpy as np
import matplotlib.pyplot as plt
from figurefirst import FigureLayout

layout = FigureLayout('hello_world_layout.svg')

# some sort of magic like this
layout.add_svg_to_axis('clustermap.svg', 'axis')

layout.insert_figures('target_layer_name')
layout.write_svg('hello_world_output.svg')

Other use cases:

  • Build subfigures using GridSpec or Subplots and then add them as a panel
  • Pre-generate figures and then compile them later, a similar workflow to svgutils.
  • If you like inception, you could import one FigureFirst template into another. Don't know if that would be useful, but would be trippy.

Thanks again for taking a look at this, it sounds like a complicated problem to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants