Adding legends and annotations
When drawing graphs with dense information, a legend may be required to display relevant information to improve the understanding of the data presented, like what color is assigned to what concept. In matplotlib
, legends can be pretty rich and there are multiple ways of presenting them. Annotations to draw attention to specific points are also useful to help the reader understand the information displayed on the graph.
In this recipe, we'll create a graph with three different components and display a legend with information to better understand it, as well as annotating the most interesting points on our graph.
Getting ready
We need to install matplotlib
in our virtual environment:
$ echo "matplotlib==3.2.1" >> requirements.txt
$ pip install -r requirements.txt
If you are using macOS, you may get an error like this: RuntimeError: Python is not installed as a framework. See the matplotlib
documentation...