How do I control where an R plot is displayed, using python and rpy2?
I'm writing a program in Python. The first thing that happens is a window is displayed (I'm using wxPython) that has some buttons and text. When the user performs some actions, a plot is displayed in its own window. This plot is made with R, using rpy2. The problem is that the plot usually pops up on top of the main window, so the user has to move the plot to see the main window again. This is a big pr开发者_如何学Coblem for the user, because he's lazy and good-for-nothing. He wants the plot to simply appear somewhere else, so he can see the main window and the plot at the same time, without having to lift a finger.
Two potential solutions to my problem are:
(1) display the plot within a wxPython frame (which I think I could control the location of), or (2) be able to specify where on the screen the plot window appears.I can't figure out how to do either.
Plot to a graphics file using jpeg()
, png()
or another device, then display that file on your wxWidget.
There are few lines about this in the documentation: http://rpy.sourceforge.net/rpy2/doc-2.2/html/graphics.html
By default R plots to the "interactive" plotting device (X11). Specifying a non-interactive file-based device (jpeg, png, pdf - pdf being probably easier if rescaling or zooming is wished).
There is a very experimental feature in rpy2-2.2.0dev that would let one implement relatively easily new devices (e.g., plot into matplotlib canvases, or wxWindows panels), but unfortunately this is not complete, not documented, and probably not fully working.
精彩评论