Tutorial for first year computer science students

Back to Tutorials

Data Visualisation - Working with matplotlib

Learning Objectives

We are going to learn:

  1. How to import and use the math library.
  2. How to plot figures using matplotlib.
  3. How to display these figures using MediaLib.

Plotting Figures

MediaLib can be used in conjunction with other Python libraries. For example, you can also plot and change the colors, sizes, line types, fonts, etc. of charts using matplotlib. See the official documentation for more details https://matplotlib.org/stable/contents.html

Exercises

Download the Medialib ex3 files from the gallery and complete the program in ex3.py to display four plots at once. It is not necessary to use the same design (type of graphs, colors, labeling, ...) as the example.

In lines 14 to 22, as shown below, we have defined a function to load the data from data.csv.

  1. Define a function to plot the figures using matplotlib with the following arguments: data, colour, title, labels, file_name. Hint: use pyplot.clf() to clear the figure before drawing the next one.


  2. Use the draw() function of MediaLib to load and draw the figures created in step 1 on the window as shown in the figure below.
Medialib Exercise




Creative Commons Licence
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.