如何使用 python 和 rpy2 控制 R 图的显示位置?
我正在用 Python 编写一个程序。首先发生的事情是显示一个窗口(我使用的是 wxPython),其中有一些按钮和文本。当用户执行某些操作时,绘图会显示在其自己的窗口中。该图是使用 R 使用 rpy2 绘制的。问题是绘图通常会在主窗口顶部弹出,因此用户必须移动绘图才能再次看到主窗口。这对于用户来说是个大问题,因为他又懒又没出息。他希望情节简单地出现在其他地方,这样他就可以同时看到主窗口和情节,而无需费力。
我的问题的两个可能的解决方案是:
(1) 在 wxPython 框架内显示绘图(我认为我可以控制其位置),或者
(2) 能够指定绘图窗口在屏幕上出现的位置。
我也不知道该怎么办。
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 problem 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
jpeg()
、png()
或其他设备绘制到图形文件,然后在wxWidget上显示该文件。Plot to a graphics file using
jpeg()
,png()
or another device, then display that file on your wxWidget.文档中对此有几行内容:
http://rpy.sourceforge.net/rpy2/doc-2.2/html /graphics.html
默认情况下,R 绘制到“交互式”绘图设备 (X11)。指定基于非交互式文件的设备(jpeg、png、pdf - 如果需要重新缩放或缩放,pdf 可能更容易)。
rpy2-2.2.0dev 中有一个非常实验性的功能,可以让人们相对容易地实现新设备(例如,绘制到 matplotlib 画布或 wxWindows 面板中),但不幸的是,这并不完整,没有记录,并且可能无法完全工作。
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.