CHARTS AND GRAPHS WITH DATA FROM SQLITE3
Listing 5.27 displays the content of rainfall_multiple.py that shows you how to generate multiple charts and graphs from data that is extracted from a sqlite3 database.
LISTING 5.27: rainfall_multiple.py
import sqlite3
import pandas as pd
import matplotlib.pyplot as plt
sql = """
SELECT
cast(centimeters/5.00 as int)*5 as cent_floor,
count(*) as count
FROM rainfall
GROUP by 1
ORDER by 1;
"""
con = sqlite3.connect("mytools.db")
df = pd.read_sql_query(sql, con)
con.close()
####################################
# generate 7 types of charts/graphs
# and save them as PNG or TIFF files
####################################
df.hist(column='count', bins=14, grid=False, rwidth=.8, color='red')
plt.savefig("rainfall_histogram.tiff")
df.plot.pie(y='count',figsize=(8,6))
plt.savefig("rainfall_pie.png")
df.plot.line(y='count',figsize=(8,6))
plt.savefig...