Skip to main content

Some lightweight helper functions which add readability/functionality to Spotify's chartify library

Project description

chartify-helpers

Some lightweight helper functions which add readability/functionality to Spotify's chartify library

Installation:

via pip:

pip install chartify-helpers

via github:

git clone https://github.com/KristofPusztai/chartify-helpers.git

navigate to cloned directory and run setup.py

sudo python setup.py install

Usage:

Custom Callouts:

Method:

custom_callouts(chart, custom_callout, xs, ys, 
	        labels, colors, legend=True, label_text=False,
		sizes=None, alphas=None, text_offset=0.0005)
from chartify_helpers import custom_callouts

# Generate example data
data = chartify.examples.example_data()

# Sum price grouped by date
price_by_date = (
    data.groupby('date')['total_price'].sum()
    .reset_index()  # Move 'date' from index to column
    )
# Plot the data
ch = chartify.Chart(blank_labels=True, x_axis_type='datetime')
ch.set_title("Line charts")
ch.set_subtitle("Custom Callouts")
ch.plot.line(
    # Data must be sorted by x column
    data_frame=price_by_date.sort_values('date'),
    x_column='date',
    y_column='total_price')

# Diamond Callout
custom_callouts(ch, ch.figure.diamond, 
                [[price_by_date['date'][54]]], [[price_by_date['total_price'][54]]], 
                ['diamond callout'], ['orange'], 
                legend=True, label_text=True, sizes=[10],alphas=[1], text_offset=0.3)
# Circular Callout
custom_callouts(ch, ch.figure.circle, 
                [[price_by_date['date'][103]]], [[price_by_date['total_price'][103]]], 
                ['circular callout'], ['green'], 
                legend=True, label_text=True, sizes=[10],alphas=[1], text_offset=0.3)
# Square Callout
custom_callouts(ch, ch.figure.square, 
                [[price_by_date['date'][146]]], [[price_by_date['total_price'][146]]], 
                ['square callout'], ['red'], 
                legend=True, label_text=True, sizes=[10],alphas=[1], text_offset=0.3)

alt text

More callout styles found here

Stacked Bar Chart Top Labels:

Method:

add_stacked_label(chart, categories, labels, y , colors=None, sizes='10pt')
from chartify_helpers import add_stacked_label

# Generate example data
data = chartify.examples.example_data()

quantity_by_fruit_and_country = (data.groupby(
    ['fruit', 'country'])['quantity'].sum().reset_index())

# Plot the data
ch = chartify.Chart(blank_labels=True,
                x_axis_type='categorical')
ch.set_title("Stacked bar chart")
ch.set_subtitle("Stack columns by a categorical factor, with top labels")
ch.plot.bar_stacked(
     data_frame=quantity_by_fruit_and_country,
     categorical_columns=['fruit'],
     numeric_column='quantity',
     stack_column='country',
     normalize=False)
ch.set_legend_location('top_right')

# Adding numerical labels above each bar
add_stacked_label(ch,data.groupby('fruit').sum()['quantity'].index,
data.groupby('fruit').sum()['quantity'].values, 
data.groupby('fruit').sum()['quantity'].values)

ch.show('png')

alt text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chartify_helpers-1.2.2.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

chartify_helpers-1.2.2-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file chartify_helpers-1.2.2.tar.gz.

File metadata

  • Download URL: chartify_helpers-1.2.2.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for chartify_helpers-1.2.2.tar.gz
Algorithm Hash digest
SHA256 b9aea12874cc9cf56d1e20de1189ca440419930356927c8ee71f14abf6f7d827
MD5 6e166b4965af29673d0c7735dc108f5a
BLAKE2b-256 00712174c290e9c73dcca300e898d6077321b3e7ee4ed9b1316f09e497c3aa06

See more details on using hashes here.

File details

Details for the file chartify_helpers-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for chartify_helpers-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 84c5259edf16bf2f0e351034a9efc9db18d019d737f03159f28feb3bda34bd46
MD5 e26f85a3744370e967463c5086712028
BLAKE2b-256 ae85b1f1f0e3b9c2a62b9b9899feabb923b518462888893bb24423c017767f01

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page