ticoneva / pystata-kernel

Jupyter kernel for Stata based on pystata
GNU General Public License v3.0
13 stars 6 forks source link

Cells containing more than one graph command only return the last graph unless graphs are named #8

Closed ideabucket closed 2 years ago

ideabucket commented 2 years ago

If you do this in one cell:

sysuse auto
scatter weight mpg
scatter length mpg

You will only get one graph back---the one for scatter length mpg. The echo back from the kernel shows both graph commands run, but it looks like the graphs clobber each other.

Fairly straightforward to work around using graph combine or just putting the commands in separate cells, though.

ideabucket commented 2 years ago

I realised that this is the result of not naming the graphs. This:

sysuse auto
scatter weight mpg, name(weight_mpg)
scatter length mpg, name(length_mpg)

…outputs both graphs. The only caveat is that the graphs are appended to the end of the stata output rather than being inserted after the command that generated them. So if you do something that returns textual output after the graphs, the graphs will follow the output of the command that was run later, e.g.:

sysuse auto
scatter weight mpg, name(weight_mpg)
scatter length mpg, name(length_mpg)
tab foreign rep78

…will return the following sequence of output:

. sysuse auto
(1978 automobile data)

. scatter weight mpg, name(weight_mpg)

. scatter length mpg, name(length_mpg)

. tab foreign rep78
[output of 'tab foreign rep78']
[graph 'weight_mpg']
[graph 'length_mpg']
ticoneva commented 2 years ago

I just checked and the issue lies with pystata itself:

Screenshot 2022-08-27 11 08 46