Creating Charts and Graphs with Python Kivy

In this Kivy tutorial we want to learn about Creating Charts and Graphs with Python Kivy, so Kivy is an open source Python library for creating multi touch applications and user interfaces. it provides different tools for building interactive applications, including the ability to create charts and graphs. in this article we want to cover how to use Kivy to create different types of charts and graphs.

 

 

 

Creating Charts and Graphs with Python Kivy

For creating charts and graphs in Kivy, first of all we need to install Kivy and you can use pip for that.

 

 

 

For creating basic chart with Kivy, we can use Kivy Garden Graph module. Garden is a collection of Kivy widgets and tools that can be installed separately. to install Garden Graph module run this command:

 

 

 

So now let’s create our basic charts or graphs using Kivy, this is simple code for a sin chart in Kivy.

In the above code we have imported the necessary modules. after that we creates BoxLayout widget, which will contain the graph. and than we creates a Graph widget which represents the graph. we set x and y labels, tick marks and grid lines for the graph.

After that we creates MeshLinePlot which represents plot line on the graph. we set color of the plot line and set the points attribute to list of (x, y) coordinates. in this example we have used sin function from the math module to generate y values for the plot. and lastly we add plot to the graph using add_plot method, after that we add the graph to the layout. we return the layout which is then displayed by the app.

 

 

 

Run the complete code and this will be the result

Creating Charts and Graphs with Python Kivy
Creating Charts and Graphs with Python Kivy

 

 

 

 

We can also create a bar chart with Kivy. 

 

 

 

 

Run the complete code and this will be the result

Kivy Bar Chart
Kivy Bar Chart

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×