python - 如何使用wxpython和rpy2显示图像?

标签 python r wxpython visualization rpy2

所以我尝试在使用 wxpython 和 rpy2 时显示 R 生成的图像...

完整的 131 行代码在这里... https://gist.github.com/ACollectionOfAtoms/4286c0fc32838b03f2ea

因此,在程序中,用户会看到由 lst_view 生成的窗口,其中有两个按钮“确定”和“可视化”。一旦按下可视化按钮,就会执行这段代码。

    def graph(self,event):
    f = open('results.csv', 'wb')
    csvwriter = csv.writer(f)
    for i in self.res:
        for j in range(1,len(i)):
            row = [i[0] ,str(i[j])]
            csvwriter.writerow(row)
    f.close()


    r = robjects.r
    r('''
            source('vis.r')
    ''')
    r_main = robjects.globalenv['main']
    r_main()
    return True

在 vis.r 中我们有:

graph <- function() {
  res = read.csv("results.csv", header=FALSE)
  res = mutate(res, Percent = 100*(V2/(sum(res$V2))))
  ggplot(data=res, aes(x=V1, y=V2, fill=Percent)) + geom_bar(stat="identity") + coord_flip() + xlab('Facility') + ylab('Number Of Violations')
}
main <- function(){
  print(graph())
}

这不会立即生成图形,而是会导致出现一个新菜单,并且仅当我转到“页面设置”时才会显示图形....

有人有想法吗?!

最佳答案

好的,感谢unutbu我能够弄清楚这一点!

基本上,我最初想保存图像,然后使用 wx 将其可视化,但我在使用 dev.off() 等通过 rpy2 时遇到了问题!

但是! unutbu 提供了一个链接,给我省去了很多麻烦。 你可以使用ggsave()来完全绕过整个jpeg('this.jpg'); dev.off();生意!

再次感谢,unutbu。现在我用 wx 渲染它没问题!

关于python - 如何使用wxpython和rpy2显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29403392/

相关文章:

python - wxpython在wxpython staticbitmap中刷新图像

python - wxpython : button covers all in the frame

r - 插入符号 : undefined columns selected

r - 在 R 中查找每组的累积第二最大值

python - 如何在 StyledTextCtrl 中创建查找对话框?

python - 使用 matplotlib 在 wxpython 面板中组合按键和鼠标按钮事件

python - 如何从 python 代码中捕获嵌入式 C++ 模块中的 exit()?

python - scipy curve_fit 在拟合傅里叶函数时不产生平滑的图形

python - np.polyfit 图在 python 中具有不确定性

r - ggplot 时间序列绘图 : group by dates