Skip to content

#29 Grouped bar chart enhancements #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 150 additions & 6 deletions module_test.ipynb

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions rick/rick.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
Version 0.9.0
Version 0.9.2
"""
from psycopg import connect
import psycopg.sql as pg
Expand Down Expand Up @@ -59,8 +59,8 @@ class colour():

colours_map = {
1: purple,
2: orange,
3: grey,
2: grey,
3: orange,
4: green,
5: wisteria,
6: brown,
Expand Down Expand Up @@ -1465,7 +1465,7 @@ def horizontal_bar_annotations(df:pd.DataFrame, ax:plt.axes, bar_width:float, up
HORIZONTAL_CUTOFF = 0.2 * upper
ANNOTATION_OFFSET = 0.015 * upper
PERCENT_HRZNTL_OFFSET = 0.04
PERCENT_VRTCL_OFFSET = (0.15) if len(df.columns) == 2 else (-0.05)
PERCENT_VRTCL_OFFSET = -0.05

# Adding annotations for values of each bar
for k in range(len(df.columns)):
Expand All @@ -1485,7 +1485,8 @@ def horizontal_bar_annotations(df:pd.DataFrame, ax:plt.axes, bar_width:float, up
j = bar_width*k
for index, row in df_percent.iterrows():
ax.annotate(
('+' if row[f'percent{k}'] > 0 else '') + str(format(int(round(row[f'percent{k}'])), ',')) + '%', # Rounds percentage to closest integer
('+' if row[f'percent{k}'] > 0 else '') + (str(format(int(round(row[f'percent{k}'])), ',')) if precision < 1 else f"{format(round(row[f'percent{k}'],precision), f',.{precision}f')}") + '%',
# Rounds percentage to closest integer or round to whatever decimals parameter precision specified
xy = (row[col] + (4*PERCENT_HRZNTL_OFFSET if row[col] < HORIZONTAL_CUTOFF else PERCENT_HRZNTL_OFFSET) * upper, j + PERCENT_VRTCL_OFFSET), # Placement of percentage annotation
color = 'k',
fontname = font.normal,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='rick',
version='0.9.1',
version='0.9.2',
description='Standardized matplotlib charts and graphs',
packages=find_packages(),
install_requires=[
Expand Down