From df7d4c2a4f0819736e6a70e1be859f3d771fa3fb Mon Sep 17 00:00:00 2001 From: Zhangyixue1537 Date: Tue, 11 Jun 2024 13:46:47 +0000 Subject: [PATCH] #8 update grouped bar example --- sphinx/source/examples/grouped_bar/README.txt | 1 + .../grouped_bar/plot_multi_stacked_bar.py | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 sphinx/source/examples/grouped_bar/plot_multi_stacked_bar.py diff --git a/sphinx/source/examples/grouped_bar/README.txt b/sphinx/source/examples/grouped_bar/README.txt index 973d21b..64a8d51 100644 --- a/sphinx/source/examples/grouped_bar/README.txt +++ b/sphinx/source/examples/grouped_bar/README.txt @@ -6,4 +6,5 @@ Below is a gallery of grouped bar charts. - RICK Vertical Grouped Bar Chart: derives from the RICK package with source code in `rick.py`. - RICK Horizontal Grouped Bar Chart: derives from the RICK package with source code in `rick.py`. +- RICK Multi Stacked Bar Chart: derives from the RICK package with source code in `rick.py`. diff --git a/sphinx/source/examples/grouped_bar/plot_multi_stacked_bar.py b/sphinx/source/examples/grouped_bar/plot_multi_stacked_bar.py new file mode 100644 index 0000000..50ab252 --- /dev/null +++ b/sphinx/source/examples/grouped_bar/plot_multi_stacked_bar.py @@ -0,0 +1,52 @@ +""" +RICK Multi Stacked Bar Chart +======================= + +Example of a horizontal grouped bar chart. +""" +import os +import os.path as osp +import sys +sys.path.append(osp.dirname(osp.dirname(osp.dirname(osp.dirname(osp.dirname(osp.abspath(__file__))))))) + +from sqlalchemy import create_engine +import matplotlib.pyplot as plt +import matplotlib as mpl +import pandas as pd +import configparser +from psycopg2 import connect +import psycopg2.sql as pg +import pandas.io.sql as pandasql +import numpy as np +import datetime +import math +import rick +import geopandas as gpd +import os +import shapely +from shapely.geometry import Point +####os.environ["PROJ_LIB"]=r"C:\Users\rliu4\AppData\Local\Continuum\anaconda3\Library\share" +import importlib +import matplotlib.ticker as ticker +import matplotlib.font_manager as font_manager + + +################################ +#multi_stacked_bar_chart +#-------------------------- +# +#This Section uses the revised multi_stacked_bar_chart function with a customized dataframe. + +np.random.seed(42) +data1 = { + 'Location': ['Scarborough', 'Etobicoke York', 'North York', 'East York'], + '2016': [58640, 57210, 59490, 63090], + '2018': [93810, 90690, 84720, 93550], + '2020': [81538, 77456, 80235, 73692] +} + +df = pd.DataFrame(data1) +##df = df.set_index('Category') + +fig, ax = rick.charts.multi_stacked_bar_chart(df, xlab = 'Trips', lab1 = '2016', lab2 = '2018', lab3 = '2020', xmax= 250000) +fig.tight_layout() \ No newline at end of file