nbstata icon indicating copy to clipboard operation
nbstata copied to clipboard

Ease setting figure dimensions in-line

Open hugetim opened this issue 2 years ago • 3 comments

Use literal "default"s for pystata.config.set_graph_size for nbstata's default. This will probably require a breaking change to the API, but it's worth it.

Discussed in https://github.com/hugetim/nbstata/discussions/24

Originally posted by friosavila May 11, 2023 Hi Tim I was wondering if there is anyway to modify how nbstata works regarding figures. I know that currently, you can change the setup if you would like to obtain larger or smaller figures to be output in jupyter notebook. However, would it be possible to use information from "xsize() and ysize()" to be used to change those settings in a more dynamic way?

Thank you!

hugetim avatar Aug 29 '23 20:08 hugetim

This change (for version 1.0) will follow pystata's API more closely, in the sense that if you only set one dimension (at a time), the other dimension is also updated, using the default aspect ratio.

In other words, %set graph_width = 3 followed by %set graph_height = 3 will give you a different result than specifying both together:

%%
set graph_width = 3
set graph_height = 3

which will be the only way to get a square aspect ratio.

hugetim avatar Aug 29 '23 21:08 hugetim

For now (version 0.x), there's a workaround:

%%set
graph_width = default
graph_height = default

Or, if you want it to not cause errors when exported to a do file:

*%%set
/*
graph_width = default
graph_height = default
*/

Or, equivalently, add these lines to the config file:

graph_width = default
graph_height = default

hugetim avatar Sep 01 '23 17:09 hugetim

Thank you! This now works like a charm!

riosavila avatar Sep 07 '23 18:09 riosavila