I have a Seaborn FacetGrid with a radio button to update the property shown.
After the radio button click I need to clear the data and replace with the selected property. I don;t want to clear the full plot.
I managed to do this, but in a very clumsy (and possibly error prone) manner by assuming that the only plotted data is stored in an object of type matplotlib.collections.PathCollection
# Clearing the data in FacetGrid fg
for ax in fg.figure.axes:
for obj in ax.findobj():
if type(obj) is matplotlib.collections.PathCollection:
obj.remove()
# Repopulate with new date
fg.map_dataframe(sns.scatterplot, x="x", y="ynew")
Is there a better way to do this?