| 1 | Graph |
| 2 | ====== |
| 3 | |
| 4 | The `Graph` widget is a widget for displaying plots. It supports |
| 5 | drawing multiple plot with different colors on the Graph. It also supports |
| 6 | a title, ticks, labeled ticks, grids and a log or linear representation on |
| 7 | both the x and y axis, independently. |
| 8 | |
| 9 | To display a plot. First create a graph which will function as a "canvas" for |
| 10 | the plots. Then create plot objects e.g. MeshLinePlot and add them to the |
| 11 | graph. |
| 12 | |
| 13 | To create a graph with x-axis between 0-100, y-axis between -1 to 1, x and y |
| 14 | labels of and X and Y, respectively, x major and minor ticks every 25, 5 units, |
| 15 | respectively, y major ticks every 1 units, full x and y grids and with |
| 16 | a red line plot containing a sin wave on this range:: |
| 17 | |
| 18 | from kivy.garden.graph import Graph, MeshLinePlot |
| 19 | graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, |
| 20 | x_ticks_major=25, y_ticks_major=1, |
| 21 | y_grid_label=True, x_grid_label=True, padding=5, |
| 22 | x_grid=True, y_grid=True, xmin=-0, xmax=100, ymin=-1, ymax=1) |
| 23 | plot = MeshLinePlot(color=[1, 0, 0, 1]) |
| 24 | plot.points = [(x, sin(x / 10.)) for x in xrange(0, 101)] |
| 25 | graph.add_plot(plot) |
| 26 | |
| 27 | The `MeshLinePlot` plot is a particular plot which draws a set of points using |
| 28 | a mesh object. The points are given as a list of tuples, with each tuple |
| 29 | being a (x, y) coordinate in the graph's units. |
| 30 | |
| 31 | You can create different types of plots other than `MeshLinePlot` by inheriting |
| 32 | from the `Plot` class and implementing the required functions. The `Graph` object |
| 33 | provides a "canvas" to which a Plot's instructions are added. The plot object |
| 34 | is responsible for updating these instructions to show within the bounding |
| 35 | box of the graph the proper plot. The Graph notifies the Plot when it needs |
| 36 | to be redrawn due to changes. See the `MeshLinePlot` class for how it is done. |