bernardodionisi / differences

difference-in-differences in Python
https://bernardodionisi.github.io/differences/latest/
GNU General Public License v3.0
93 stars 21 forks source link

Exporting plots to jpeg programatically #7

Closed achinmay17 closed 1 year ago

achinmay17 commented 1 year ago

Is there a way to export plots programatically? Alternatively, is there a way plots can be plotted as matplotlib plots (which will have matplotlib functionalities including exporting)?

bernardodionisi commented 1 year ago

Hi,

if you are using the built-in .plot() method you can save a chart as an html file using the save_fname parameter passing a string for the path/file name. You can find all the parameters that can be passed to the plot method here; so, for example, you would write att_gt.plot("event", save_fname="my plot"). From the html you can then download as you would for Altair charts.

The plot method currently returns an Altair HConcatChart so you could use Altair-related functionality to save the chart, without relying onsave_fname.

The .fit() and .aggregate() methods return Pandas DataFrames so you could use matplotlib's errorbar to plot the estimates and confidence bands; there is currently no built-in support to facilitate using matplotlib.

achinmay17 commented 1 year ago

Thanks a lot for the quick response! Really appreciate it!

Also, thanks a lot for creating great package. I will close the issue.

bernardodionisi commented 1 year ago

Just as a note (unrelated to exporting), see this issue for the disaggregated plot (ATTgt plot with no aggregation), there is a temporary solution there.