Giter Site home page Giter Site logo

garden.graph's Introduction

Graph

The Graph widget is a widget for displaying plots. It supports drawing multiple plot with different colors on the Graph. It also supports a title, ticks, labeled ticks, grids and a log or linear representation on both the x and y axis, independently.

Screenshot

To display a plot. First create a graph which will function as a "canvas" for the plots. Then create plot objects e.g. MeshLinePlot and add them to the graph.

To create a graph with x-axis between 0-100, y-axis between -1 to 1, x and y labels of and X and Y, respectively, x major and minor ticks every 25, 5 units, respectively, y major ticks every 1 units, full x and y grids and with a red line plot containing a sin wave on this range::

from math import sin
from kivy.garden.graph import Graph, MeshLinePlot
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=-1, ymax=1)
plot = MeshLinePlot(color=[1, 0, 0, 1])
plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
graph.add_plot(plot)

The MeshLinePlot plot is a particular plot which draws a set of points using a mesh object. The points are given as a list of tuples, with each tuple being a (x, y) coordinate in the graph's units.

You can create different types of plots other than MeshLinePlot by inheriting from the Plot class and implementing the required functions. The Graph object provides a "canvas" to which a Plot's instructions are added. The plot object is responsible for updating these instructions to show within the bounding box of the graph the proper plot. The Graph notifies the Plot when it needs to be redrawn due to changes. See the MeshLinePlot class for how it is done.

garden.graph's People

Contributors

brentpicasso avatar dessant avatar dirkjot avatar drmoriarty avatar fallrisk avatar inclement avatar kronopt avatar lobocv avatar matham avatar matsjoyce avatar sirpercival avatar tito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

garden.graph's Issues

"Exception: Shader didnt link, check info log" while trying to instantiate the widget not in build method

See traceback

File "/home/sergey/projects/kivy_relayr/graph/__init__.py", line 153, in __init__
     self._fbo = Fbo(size=self.size, with_stencilbuffer=False)
   File "kivy/graphics/fbo.pyx", line 148, in kivy.graphics.fbo.Fbo.__init__ (kivy/graphics/fbo.c:2895)
   File "kivy/graphics/instructions.pyx", line 750, in kivy.graphics.instructions.RenderContext.__init__ (kivy/graphics/instructions.c:10606)
   File "kivy/graphics/shader.pyx", line 184, in kivy.graphics.shader.Shader.__init__ (kivy/graphics/shader.c:3832)
   File "kivy/graphics/shader.pyx", line 687, in kivy.graphics.shader.Shader.vs.__set__ (kivy/graphics/shader.c:10883)
   File "kivy/graphics/shader.pyx", line 549, in kivy.graphics.shader.Shader.build_vertex (kivy/graphics/shader.c:8766)
   File "kivy/graphics/shader.pyx", line 579, in kivy.graphics.shader.Shader.link_program (kivy/graphics/shader.c:9205)

some kv parameters are not taken into account

Some kv parameters like

Graph:
    background_color: r,g,b,a

are not taken into account. This is because when this assignation occurs:

class Graph(Widget):
    def __init__(self, **kwargs):
        self._background_color = Color(*self.background_color)

the self.background_color value is not yet initialized by kv language string (Why ?)

A patch suggestion is to defer the assignation later in _redraw_size:

class Graph(Widget):
    def _redraw_size(self, *args):
        self._background_color.rgba = self.background_color

Other parameters are probably not taken into account.

This issue needs to be solve in order to solve issue #8.

can i zoom with mouse wheel

Hello, i search a solution for plot data in graph with kivy
But, i would like to be able to zoom (with mouse wheel or +/- button...) and move in the graph (with mouse)

like in matplotlib

it's possible with kivy and this widget ?

Adding ticks to one, of more than one Graphs aligned in a layout, mis-aligns them

And the magnitude of the mis-alignment increases with the length of the tick labels: the attached screenshots are of a simplified (only two graphs in a vertical box layout that typically contains at least 7 or 8) version of a "multi-graph" app I'm writing for work. You'll see that when there are no ticks, the right edges of the graphs are aligned, which is the desired final state. However, merely adding ticks causes the right edges to be mis-aligned. Moreover, as the further screenshots illustrate, as the length of the tick labels increases, so does the magnitude of the mis-alignment. This makes the multi-graph unpresentable in a professional context, and thus, IMO, constitutes a serious shortcoming, if not an out-and-out "bug."

Environment:
Windows 7 Pro SP1 64-bit
Kivy 1.8.0, KivyPy3_3

integratorwoticks
integratord10
integratorm10
integratorm1000

Graph does not work with Python 3.4

Itertools has changed in py3: http://stackoverflow.com/a/5237664
After fixing that, it complained about GRADIENT_DATA not being a bytestring and a different error:
Line 988: TypeError: Expected bytes, got builtin_function_or_method
Line 346, 372: ValueError: Label.pos must be a list or a tuple

I have converted GRADIENT_DATA to bytes and just commented out the problem lines regarding Label.pos and i was finally able to run it, but the green line is not like the one from the screenshot, maybe because I have fiddled with GRADIENT_DATA.
Some refactoring needs to be done for Python 3 compatibility.

Click on the image to see it in full resolution.
untitled-1

Plots are not visible in Screen, ScrollView and Carousel

When I'm trying to add a graph as a widget to a Screen of a ScreenManager, Ticks and plots will not be visible.

This is the example code:

class MyScreen(Screen):
    def __init__(self, **kwargs):
        super(MyScreen, self).__init__(**kwargs)

        self.add_widget(Graph(
            y_ticks_major=10,
            y_grid=True,
            xlabel='X',
            ylabel='Y',
        ))

sm = ScreenManager()
sm.add_widget(MyScreen())

runTouchApp(sm)

no module named kivy.garden.graph

Hey i've install this module using pip and it seems to install correctly in my .kivy folder but when i try running the example it says no module named kivy.garden.graph. I use the send to method with kivy.

Cannot blit with a different colorfmt than the created texture

Resize the window to trigger the exception.

from kivy.app import App
from kivy.uix.anchorlayout import AnchorLayout
from kivy.garden.graph import Graph


class Test(AnchorLayout):
    def __init__(self, *args, **kwargs):
        super(Test, self).__init__(*args, **kwargs)
        graph = Graph(
            x_ticks_major=1,
            y_ticks_major=10,
            y_grid_label=True,
            x_grid_label=True,
        )
        self.add_widget(graph)


class TestApp(App):
    def build(self):
        return Test()

if __name__ == '__main__':
    TestApp().run()
 Exception ignored in: 'kivy.graphics.texture.Texture._reload_propagate'
 Traceback (most recent call last):
   File "C:\dev\python\lib\site-packages\kivy\core\text\__init__.py", line 546, in _texture_refresh
     self.refresh()
   File "C:\dev\python\lib\site-packages\kivy\core\text\__init__.py", line 565, in refresh
     self.texture = self.texture_1px
   File "C:\dev\python\lib\site-packages\kivy\core\text\__init__.py", line 607, in texture_1px
     tex.blit_buffer(b'\x00\x00\x00\x00')
   File "texture.pyx", line 886, in kivy.graphics.texture.Texture.blit_buffer (C:\Users\user\AppData\Local\Temp\pip-oq3o650a-build\kivy\graphics\texture.c:10200)
 Exception: GLES LIMIT: Cannot blit with a different colorfmt than the created texture. (texture has rgba, you passed rgb)
 Exception ignored in: 'kivy.graphics.texture.Texture._reload_propagate'
 Traceback (most recent call last):
   File "C:\dev\python\lib\site-packages\kivy\core\text\__init__.py", line 546, in _texture_refresh
     self.refresh()
   File "C:\dev\python\lib\site-packages\kivy\core\text\__init__.py", line 565, in refresh
     self.texture = self.texture_1px
   File "C:\dev\python\lib\site-packages\kivy\core\text\__init__.py", line 607, in texture_1px
     tex.blit_buffer(b'\x00\x00\x00\x00')
   File "texture.pyx", line 886, in kivy.graphics.texture.Texture.blit_buffer (C:\Users\user\AppData\Local\Temp\pip-oq3o650a-build\kivy\graphics\texture.c:10200)
 Exception: GLES LIMIT: Cannot blit with a different colorfmt than the created texture. (texture has rgba, you passed rgb)

Aviod joining two strokes of drawing

Hi, I am plotting a graph reading a file with x, y positions. These drawings are in form of letters(y, c etc).
In actual drawing there is a gap (visually) in the strokes of letters, but when i am making a graph using kivy garden. It is somehow joining the two strokes with a line.

In the attached pic, you can see there are two strokes of y, one is small (first one) and second is remaining full y. Both two strokes are attached by a straight line (approx pos: 600, -80).

How can I avoid this?

Thanks in advance! Quiet new in kivy!

mis1

create a new line and erase the old one

Dear all,
I am not able to move only a line in my graph. I try to explain me better.
I have crated an app to plot a graph with garden in kivy.
After that I plot a line to select a range linked to a slider.
The Problem is that when I create a new line I am not able to erase the old one.
In the attachment there is my new code. After press the button "load data", It create a plot where I can move two vertical line with a scroll bar.
According to a friend of mine (ZenCode) this issue must be to do with the plot instructions not being properly removed.

Thanks a lot

These are my code:

import kivy
kivy.require('1.7.1')

from kivy.app import App

from kivy.properties import OptionProperty, NumericProperty, ListProperty, \

BooleanProperty

from kivy.properties import ObjectProperty

from kivy.uix.boxlayout import BoxLayout
from kivy.garden.graph import Graph, MeshLinePlot
from math import sin

class SayThis(BoxLayout):

def compute(self):

print dir(self.the_graph)

def load_data(self):
    print 'load data'
    self.the_line_m = MeshLinePlot(color=[1, 0, 1, 1])
    self.the_line_M = MeshLinePlot(color=[1, 0, 0, 1])

    self.the_plot = MeshLinePlot(color=[0, 1, 1, 1])

    self.the_plot.points = [(x / 10., sin(x / 50.)) for x in range(-1, 1)]
    self.the_graph.add_plot(self.the_plot)


def adjust_line_m(self, val):
    self.the_graph.remove_plot(self.the_line_m.points)
    val=self.min_slider.value      
    self.the_line_m.points = [(val, -1.), (val,1.)]
    self.the_graph.add_plot(self.the_line_m)



def adjust_line_M(self, val):
    self.the_graph.remove_plot(self.the_line_M)
    val=self.max_slider.value      
    self.the_line_M.points = [(val, -1.), (val,1.)]
    self.the_graph.add_plot(self.the_line_M)

class SayThisApp(App):
def build(self):
return SayThis()

if name == 'main':
SayThisApp().run()

:kivy 1.7.1

:
orientation: 'vertical'
button_font_size: '20sp'
padding: root.width * 0.01, root.width * 0.01
canvas:
min_slider:min_slider
max_slider:max_slider
saywhat_text: saywhat_text
the_graph:the_graph
#
#
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.2
TextInput:
id: saywhat_text
text: 'max value ='+str(max_slider.value)+'\n'+'min value='+str(min_slider.value)
#font_size: str(min_slider.value)+'sp'
TextInput:
id: txt_flow
text: 'prova'
#font_size: str(min_slider.value)+'sp'
#
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.2
height: compute_button.height
Button:
id: compute_button
text: 'Load data'
font_size: root.button_font_size
size_hint: 1, None
height: self.texture_size[1]
on_press: root.load_data()
Button:
text: 'Compute'
font_size: root.button_font_size
size_hint: 1, None
height: self.texture_size[1]
on_press: root.compute()
Graph:
id: the_graph
xlabel: 'X'
ylabel: 'Y'
x_ticks_minor: 5
x_ticks_major: 0.2
y_ticks_minor: 5
y_ticks_major: 0.2
x_grid_label: True
y_grid_label: True
xlog: False
ylog: False
x_grid: True
y_grid: True
xmin: -1
xmax: 1
ymin: -1
ymax: 1
label_options: {'bold': True}
size_hint: 1, 0.6
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.2
Label:
text:'min time'
size_hint: 0.1, None
Slider:
id: min_slider
orientation: 'horizontal'
size_hint: 0.9, None
min: -1
max: 1
value: min_slider.min
on_value: root.adjust_line_m(self.value)
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.2
Label:
text:'max time'
size_hint: 0.1, None
Slider:
id: max_slider
orientation: 'horizontal'
min: -1
max: 1
value: max_slider.max
size_hint: 0.9, None
on_value: root.adjust_line_M(self.value)

ERROR Trying to run the example

Hello:

I tried to run the example os sin graph you provided:

from math import sin
from kivy.garden.graph import Graph, MeshLinePlot
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=-1, ymax=1)
plot = MeshLinePlot(color=[1, 0, 0, 1])
plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
graph.add_plot(plot)

and i got:

[INFO ] [Logger ] Record log in C:\Users\nerve.kivy\logs\kivy_17-07-15_4.txt
[INFO ] [Kivy ] v1.10.0
[INFO ] [Python ] v3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)]
Traceback (most recent call last):
File "C:/Users/nerve/Diego/Programacion/Ejercicios Python/Kivy/KivyGraph.py", line 2, in
from kivy.garden.graph import Graph, MeshLinePlot
File "", line 961, in _find_and_load
File "", line 950, in _find_and_load_unlocked
File "", line 646, in _load_unlocked
File "", line 618, in _load_backward_compatible
KeyError: 'kivy.garden.graph'

What is the problem? Do i need additional packages?

Thank you

missing license file

Could you please add a license file to your project? It would make it simpler if you just copied the kivy license. Thanks.

__init_.py crashes with python 3

 C:\prs\main\graph.py:1175: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
   plot.data = data
[INFO              ] [OSC         ] using <thread> for socket
[INFO              ] [Base        ] Start application main loop
[INFO              ] [Base        ] Leaving application in progress...
 Traceback (most recent call last):
   File "C:\prs\main\graph.py", line 1188, in <module>
     TestApp().run()
   File "C:\dev\python\lib\site-packages\kivy\app.py", line 825, in run
     runTouchApp()
   File "C:\dev\python\lib\site-packages\kivy\base.py", line 484, in runTouchApp
     EventLoop.window.mainloop()
   File "C:\dev\python\lib\site-packages\kivy\core\window\window_pygame.py", line 364, in mainloop
     self._mainloop()
   File "C:\dev\python\lib\site-packages\kivy\core\window\window_pygame.py", line 268, in _mainloop
     EventLoop.idle()
   File "C:\dev\python\lib\site-packages\kivy\base.py", line 324, in idle
     Clock.tick()
   File "C:\dev\python\lib\site-packages\kivy\clock.py", line 482, in tick
     self._process_events()
   File "C:\dev\python\lib\site-packages\kivy\clock.py", line 614, in _process_events
     event.tick(self._last_tick, remove)
   File "C:\dev\python\lib\site-packages\kivy\clock.py", line 373, in tick
     ret = callback(self._dt)
   File "C:\prs\main\graph.py", line 1058, in draw
     self._texture.blit_buffer(charbuf, colorfmt='rgb', bufferfmt='ubyte')
   File "texture.pyx", line 914, in kivy.graphics.texture.Texture.blit_buffer (C:\Users\user\AppData\Local\Temp\pip-oq3o650a-build\kivy\graphics\texture.c:10423)
   File "stringsource", line 614, in View.MemoryView.memoryview_cwrapper (C:\Users\user\AppData\Local\Temp\pip-oq3o650a-build\kivy\graphics\texture.c:21186)
   File "stringsource", line 321, in View.MemoryView.memoryview.__cinit__ (C:\Users\user\AppData\Local\Temp\pip-oq3o650a-build\kivy\graphics\texture.c:17766)
 TypeError: 'str' does not support the buffer interface

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.