Combining graphs
More than one plot can be combined in the same graph. In this recipe, we'll see how to present data in the same plot, on two different axes, and how to add more plots to the same 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 on how to fix it: https://matplotlib.org/faq/osx_framework.html.
How to do it...
- Import
matplotlib
:>>> import matplotlib.pyplot as plt
- Prepare the data to be displayed on the graph and the legends that should be displayed. Each of the lines is composed of the time label, sales of
ProductA
, and sales ofProductB
. Notice howProductB
has a much higher value thanA
:>>> DATA = ( ... ('Q1...