Skip to content
Related Articles

Related Articles

How to add Matplotlib graph in Kivy ?

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Hard
  • Last Updated : 05 Apr, 2021

In this article, we will discuss how to add matplotlib graph in the kivy app.


  • Import matplotlib pyplot
  • Import numpy
  • Import FigureCanvas KivyAgg
  • Import kivy app
  • Import kivy builder
  • Create App class
  • Return builder string
  • Run an instance of the class

Below is the Implementation.


# importing pyplot for graph plotting
from matplotlib import pyplot as plt
# importing numpy
import numpy as np
from import FigureCanvasKivyAgg
# importing kivyapp
from import App
# importing kivy builder
from kivy.lang import Builder
# this is the main class which will 
# render the whole application
class uiApp(App):
    def build(self):
        self.str = Builder.load_string(""" 
        signal = [7, 89.6, 45.-56.34]
        signal = np.array(signal)
        # this will plot the signal on graph
        # setting x label
        # setting y label
        plt.ylabel('signal (norm)')
        plt.grid(True, color='lightgray')
        # adding plot to kivy boxlayout
        return self.str
# running the application


Note: When you run the below code this may throw the error given below

What you have to do is open the file given in the white box by clicking on file while holding ctrl key and comment line underlined by green color in that file and hit save now you will be able to run it!!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!