簡體   English   中英

如何使用wxpython和rpy2顯示圖像?

[英]How to display an image using wxpython and rpy2?

所以我試圖在使用wxpython和rpy2時顯示R生成的圖像...

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

因此,在程序中,用戶會到達一個由lst_view生成的窗口的位置,該窗口具有兩個按鈕“確定”和“可視化”。 按下Visualize后,將執行此代碼。

    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(); 商業!

再次感謝,恩圖布。 現在,我將使用wx完全渲染它!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM