Plotting pie charts
Pie charts! A Business 101 favorite, and a common way of presenting percentages. We'll see in this recipe how to plot a pie chart, with different slices representing proportions.
Getting ready
We need to install matplotlib in our virtual environment using the following commands:
$ 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. This represents several lines of products:
        >>> DATA = ( ... ('Common', 100), ... ('Premium', 75), ... ('Luxurious', 50), ... ('Extravagant', 20), ... )...
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                