kivy-garden / graph

Displays plots on a graph.
MIT License
50 stars 18 forks source link

low performance if use grid and memory Overflow Error #12

Open ryzenX opened 6 years ago

ryzenX commented 6 years ago

Hello i have big problem with kivy, i want to plot 10 point, my values range from -100000 to 100000

the problem, when i change ymin=-100000 and ymax=100000, kivy is very very slow but if i define ymin=-1 and ymax=1 i have good performance

in this example i denife ymin=-1000 and ymax=1000 and i have already slow performance, if you try with -100000 to 100000 my window make five minute to load...

but i have only 10 point to print....

from math import sin
from kivy.garden.graph import Graph, MeshLinePlot
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import NumericProperty

class RootWidget(BoxLayout):
    _touch_count = NumericProperty(0)

    def __init__(self, **kwargs):
        super(RootWidget, self).__init__(**kwargs)

        self.graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5,
                           x_ticks_major=25, y_ticks_major=1,
                           y_grid_label=True, x_grid_label=True, padding=5,
                           x_grid=True, y_grid=True, xmin=-0, xmax=100, ymin=-1000, ymax=1000)

        plot = MeshLinePlot(color=[1, 0, 0, 1])
        plot.points = [(x*100, sin(x)*100000) for x in range(0, 10)]
        self.graph.add_plot(plot)
        self.add_widget(self.graph)

class GraphDemo(App):

    def build(self):
        return RootWidget()

if __name__ == "__main__":
    GraphDemo().run()

i solved my problem, i must to hide y grid for have good performance but i found new error with memory :

from math import sin
from kivy.garden.graph import Graph, MeshLinePlot
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import NumericProperty

class RootWidget(BoxLayout):
    _touch_count = NumericProperty(0)

    def __init__(self, **kwargs):
        super(RootWidget, self).__init__(**kwargs)

        self.graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5,
                           x_ticks_major=25, y_ticks_major=1,
                           y_grid_label=False, x_grid_label=True, padding=5,
                           x_grid=True, y_grid=False, xmin=-0, xmax=100, ymin=-10000, ymax=30000)

        plot = MeshLinePlot(color=[1, 0, 0, 1])
        plot.points = [(x*1000, sin(x)*100000) for x in range(0, 10)]
        self.graph.add_plot(plot)
        self.add_widget(self.graph)

class GraphDemo(App):

    def build(self):
        return RootWidget()

if __name__ == "__main__":
    GraphDemo().run()

if i have a interval > 32767 i have this error :

   File "kivy\graphics\memory.pxi", line 72, in kivy.graphics.vertex_instruction
s._ensure_ushort_view (kivy\graphics\vertex_instructions.c:6404)
 OverflowError: value too large to convert to unsigned short
dsball commented 5 years ago

This error is coming from the ticks settings. Your y axis is 40,000 units and you are attempting to place a tick for every unit. The value you showed is 2^15-1, i.e. the maximum value for a signed short. I suspect it's related. If you change your axis to, say, 100,000 but have your y_ticks_major at a reasonable value, e.g. 1000 rather than 1, it would work fine.

I suggest choosing a reasonable interval for your y ticks, or possibly inheriting this module and adding the check to the inherited class.