Line charts

Python Courses

Line chart
You can use Matplotlib to create a line chart with Python. Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension numpy.  This takes only a few lines:

In the first two lines we include the numpy and matplotlib library. This contains logical functions to create line charts amongst others. We define a list named x with a few random numbers and we set the x and y label. Finally we call the function show() which will display the line chart. If you do not call the show() function, nothing will be shown on the screen.


by changing the plot function call to:

we create a red graph with dots, where the r in ‘ro-‘ indicates red. Changing this to ‘bo-‘ would create a blue dotted line. If you only want to display the dots, use ‘ro’ or ‘bo’ instead.

Next Post


  • Lena Khanpour says:

    how can I install matplotlib? I have the same problem as Ayush!

  • Ayush khanduri says:

    it gives me an error
    import matplotlib.pyplot as plt
    ImportError: No module named matplotlib.pyplot

    would it be because i have multiple versions of python installed in my linux.?

    • CodeNinja says:

      Multiple python versions is not a problem, install matplotlib: pip install matplotlib

Leave a Reply