Exporting as svg with group assignments

Hi there! I am often showing plots in a staggered fashion in presentations, for example, showing a couple of points first, then showing a regression line, or showing subplots one by one. For simple plots that isn’t an issue and often you can just block parts of the plot with a white box. However, for more complex plots (say multiple overlapping histograms/density plots, etc.), it is extremely tedious and error-prone to edit the figures afterward in illustrator/Inkscape. Is there a way to generate grouped collections of elements in the figure? Ideally, there would be a way to assign names for groups of plot elements (similar to the “label” keyword) that then get assigned in the svg/pdf as elements. Any suggestions? Is there a better workflow that I am missing?

Maybe that’s possible but I’d just save a few versions of the figure, keeping the same size.

Matplotlib artists accept a gid parameter that might do what you are looking for.

1 Like

Thank you! That’s what I was missing!
Here’s a minimal example:

import matplotlib.pyplot as plt
import numpy as np

f, ax = plt.subplots()
ax.scatter(np.random.randn(100), np.random.randn(100), gid="scatter")
ax.axhline(0.5, c="k", gid="hline")

exports the scatterplot and hline within a SVG group element!