Plotting a simple sales graph
In this recipe, we'll see how to draw a sales graph by drawing bars proportional to sales in different periods.
Getting ready
We can install matplotlib in our virtual environment using the following commands:
$ echo "matplotlib==3.2.1" >> requirements.txt
$ pip install -r requirements.txt
In some OSes, this may require us to install additional packages; for example, in Ubuntu, it may require us to run apt-get install python3-tk. Check the matplolib documentation for details.
If you are using macOS, it's possible that you'll get an error like this: RuntimeError: Python is not installed as a framework. Refer to 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:
>>> DATA = ( ... ...