Kivy.garden.graph draw real-time graph. (Problems SOLVED by setting graph background_color)

2,750 views
Skip to first unread message

BJ

unread,
Apr 19, 2014, 11:07:17 AM4/19/14
to kivy-...@googlegroups.com
Hi, I tried to use kivy.garden.graph to draw a real time graph, the data of which is received through a sensor.
I expect the graph to scale (in x-axis) automatically as the time goes by.

I thought it would be just as simple as adding more points to Graph().plot.points, but I always had this one problem: the old plot history stays on the canvass. Issue is shown in pictures below.

I've been looking it up all over the Internet to find the solution to this issue(like spending 2 days...it's killing me). 

As it turns out, I just need to set a background_color for the graph. THAT'S IT. Now here is what I expect the result to be after I click "Receive Data" button (simulating the process that receives data from sensors).

so all u need to do is set the background_color of the graph, by graph themes.

Now here is my pseudocode,

graph_theme = {'background_color'::'f8f8f2')}

graph = Graph(...,xmax=100, **graph_theme)

plot = MeshLinePlot(color=[1, 0, 0, 1])


append points to plot when u receive more data:plot.points.append((x,y))

when u want scale the graph in x-axis,say 200: graph.xmax =  200


This will draw a real time graph. 

And could anyone explain to me why the background_color attribute affects my issue here?





Shruti Chandra

unread,
Feb 28, 2016, 8:21:30 AM2/28/16
to Kivy users support
Hi,

I am also trying to make real time graph but could not succeed yet. As you said in your post for real time, I need to append points.

My program is here, where I already have some points and I want to plot these points one by one.

Here its my code.

http://paste.ofcode.org/VgnPK3yRLS8E48v8dM4e8W

kv file:

http://paste.ofcode.org/y4ikZf8Q6qLBPYm6xdUfdX


If you could tell me, what should I change in my draw method to make the graph real, It would be great help.

Thanks in advance.
Reply all
Reply to author
Forward
0 new messages