Add ggsave (or save) method to PlotSpec class
Add a save convenience method to the PlotSpec class.
Now we have the ggsave(plot, ...) method.
For convencience it would be great if we would add a ggsave() or save() method to class itself.
Sometimes in a notebook you don't want to assign your plot to a variable and use it like
(ggplot(...) + geom_bar(...) + ggtitle(...)).show()
If you are then satisfied with your plot you could change .show() to .save(filename=...)
(Rough) Solution:
def save(self, filename, path, iframe):
ggsave(self, filename, path, iframe)
Maybe the same could be done for GGBunch.
On another note: What is the reasoning behind the distinction between path and filename? Usually you could enter the whole absolute or relative path to a filename argument and save it there.
Sure, we can add such method to the class.
But did you consider a different workflow: without show(). If "plot expression" is the last one in cell, then after execution of the cell the result (plot object) is stored (by the Python interpreter) in a variable named "_".
Then you can write ggsave(_, "myplot.svg")
Seems like this takes even less efforts than using show() and then replacing .show() to .save(filename=...).
What do you think?
What is the reasoning behind the distinction between path and filename?
This idea was taken from from ggplot2 (R). We're always trying to preserve the similarity to the ggplot2 API where possible.
Sure, we can add such method to the class. But did you consider a different workflow: without
show(). If "plot expression" is the last one in cell, then after execution of the cell the result (plot object) is stored (by the Python interpreter) in a variable named "_". Then you can writeggsave(_, "myplot.svg")Seems like this takes even less efforts than usingshow()and then replacing.show()to.save(filename=...). What do you think?
Thank you for the tip, I will try it.
Hi, added in v4.2.0 : example notebook.