Python and rpy2: How to set up / clear image file at runtime?

I use rpy2 for data analysis and plotting in python. It works great, except for the fact that when I draw a plot, it freezes until the program terminates. Is there a way to clear the schedule while working? Also, if I ever resize the window, the graph disappears, but the window remains. When using R interactively, resizing the window just adjusts the size of my plot. I would like to have this functionality in python.

For example, if I ran the following code, I would be presented with a simple plot.

import rpy2.robjects as robj

xdata = [2,4,6,8,10,12]
ydata = [1,2,3,4,5,6]
Rxdata = robj.IntVector(xdata)
Rydata = robj.IntVector(ydata)

plot = robj.r.plot
plot(x=Rxdata, y=Rydata, main='title')

however, if I wanted to resize the window, the plot would disappear, and if I want my code to continue to do other things, this window would freeze. If there is a team that works in R to clear a graph that might work, but I can't find it. Any pointers would be appreciated.

+3
source share
2 answers

Yes, you can use the following commands to control the chart window:

dev.new() # opens a new window, and can control the size
dev.off() # closes the window

See the following questions for an example:

+4
source

Check out rpy2 documentation on handling interactive events

0
source

Source: https://habr.com/ru/post/1751064/


All Articles