seaborn icon indicating copy to clipboard operation
seaborn copied to clipboard

Consider Plot.assign method for updating the global spec

Open mwaskom opened this issue 3 years ago • 1 comments

This would in principle be redundant with the information that you pass to the constructor. But the utility would be to define a common plot in terms of layer definitions and then to iterate on the variable assignments. Things to consider:

  • If data is to be a valid keyword, maybe update is a better name?
  • Would this method also allow global assignment of "extra" variables, like variables that stat transforms can handle, which are not passable to the constructor?

mwaskom avatar Jul 30 '22 20:07 mwaskom

I was in need of this functionality, and almost opened a new issue.

This would allow to do this:

p = so.Plot(df, x="x", y="y").add(so.Line())
p.update(color="z")
p.update(color="w")

instead of this:

so.Plot(df, x="x", y="y", color="z").add(so.Line())
so.Plot(df, x="x", y="y", color="w").add(so.Line())

right?

Maybe so.Plot() should not take any parameters, and all global mappings should be passed with this method. .global() would be perfect if it weren't a Python keyword. Maybe .globals()?

maurosilber avatar Oct 01 '24 15:10 maurosilber