Saving charts
Once a chart is ready, we can store it on the hard drive so it can be referenced in other documents. In this recipe, we'll see how to save charts in different formats.
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 split it into different arrays:
>>> DATA = ( ... ('Q1 2017', 100), ... ('Q2 2017', 150), ... ('Q3 2017', 125), ... ('Q4 2017', 175), ... ) >>> POS = list(range(len...