I'm looking to implement this MWE:
https://stackoverflow.com/a/44922317/6924364
But with Gnuplot, similar to this:
https://stackoverflow.com/a/21633082/6924364
How can I pass the Gnuplot output to the Kivy app, and display the image without having to save it locally?
Edit 1: Here is a MWE that just requires some code to add the image object to a custom widget, but I'm not sure how to accomplish that.
from subprocess import Popen, PIPE
from StringIO import StringIO
from io import BytesIO
from os import linesep as nl
from PIL import Image as Image
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.widget import Widget
from kivy.core.image import Image as CoreImage
def gnuplot(commands, data):
""" drive gnuplot, expects lists, returns stdout as string """
dfile = StringIO()
for line in data:
dfile.write(str(line) + nl)
args = ["gnuplot", "-e", (";".join([str(c) for c in commands]))]
p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
dfile.seek(0)
return p.communicate(dfile.read())[0]
def gnuplot_GifTest():
commands = [\
"set datafile separator ','",\
"set terminal png",\
"set output",\
"plot '-' using 1:2 with linespoints, '' using 1:2 with linespoints",\
]
data = [\
"1,1",\
"2,2",\
"3,5",\
"4,2",\
"5,1",\
"e",\
"1,5",\
"2,4",\
"3,1",\
"4,4",\
"5,5",\
"e",\
]
return (commands, data)
class Plot(Widget):
(commands, data) = gnuplot_GifTest()
img = BytesIO(gnuplot(commands,data))
anImg = CoreImage(img,ext="png")
def __init__(self,**kwargs):
super(Plot,self).__init__(**kwargs)
# HMM, how to display self.anImg??
print self.anImg
class MyApp(App):
def build(self):
box = BoxLayout(orientation="vertical")
box.add_widget(Plot())
return box
MyApp().run()