Standardized plots and visualizations in Python

Overview

rtd ci codecov pyversions pypi pypistatus license coc codestyle colab

Standardized plots and visualizations in Python

pltviz is a Python package for standardized visualization. Routine and novel plotting approaches are formatted to allow for easy variation while providing quick and exact results. Coloration functions are also included for precise colors across plots and to assure that all functions can be ran with color hexes.

Contents

Installation

pltviz can be downloaded from PyPI via pip or sourced directly from this repository:

pip install pltviz
git clone https://github.com/andrewtavis/pltviz.git
cd pltviz
python setup.py install
import pltviz

plot

Plotting methods within pltviz are tailored to provide quick results for staples of data visualization.

See examples/plot for all plotting styles that seamlessly combine graphing functions of seaborn, matplotlib, and pandas.

import matplotlib.pyplot as plt
import pltviz

Examples of routine plotting techniques made easy are:

# The following will be used for the remaining examples

# German political parties
parties = ['CDU/CSU', 'FDP', 'Greens', 'Die Linke', 'SPD', 'AfD']
party_colors = ['#000000', '#ffed00', '#64a12d', '#be3075', '#eb001f', '#009ee0']

# Hypothetical seat allocations to the Bundestag (German parliament)
seat_allocations = [26, 9, 37, 12, 23, 5]

The following shows pltviz.bar that allows all common options to be selected as binaries:

# Bar plot options such as stacked and label bars are booleans
ax = pltviz.bar(
    counts=seat_allocations,
    labels=parties,
    colors=party_colors,
    horizontal=False,
    stacked=False,
    label_bars=True,
)

# Initialize empty handles and labels
handles, labels = pltviz.legend.gen_elements()

# Add a majority line
ax.axhline(int(sum(seat_allocations) / 2) + 1, ls="--", color="black")
handles.insert(0, Line2D([0], [0], linestyle="--", color="black"))
labels.insert(0, "Majority: {} seats".format(int(sum(seat_allocations) / 2) + 1))

ax.legend(
    handles=handles,
    labels=labels,
    title="Bundestag: {} seats".format(sum(seat_allocations)),
    loc="upper left",
    bbox_to_anchor=(0, 0.9),
    title_fontsize=20,
    fontsize=15,
    frameon=True,
    facecolor="#FFFFFF",
    framealpha=1,
)

ax.set_ylabel("Seats", fontsize=15)
ax.set_xlabel("Party", fontsize=15)

Also included is a pltviz.semipie via matplotlib artists for cases where a simple and condensed plot is needed:

ax = pltviz.semipie(counts=seat_allocations, colors=party_colors, donut_ratio=0.5)

handles, labels = pltviz.legend.gen_elements(
    counts=seat_allocations,
    labels=parties,
    colors=party_colors,
)

ax.legend(
    handles=handles,
    labels=labels,
    title="Bundestag: {} seats".format(sum(seat_allocations)),
    title_fontsize=20,
    fontsize=14,
    ncol=2,
    loc="center",
    bbox_to_anchor=(0.5, 0.17),
    frameon=False,
    facecolor="#FFFFFF",
    framealpha=1,
)

plt.show()

pltviz also includes specialized plots such as pltviz.gini to visualize gini coefficients of inequality:

global_gdp_deciles = [0.49, 0.59, 0.69, 0.79, 1.89, 2.55, 5.0, 10.0, 18.0, 60.0]

ax, gini_coeff = pltviz.gini(shares=global_gdp_deciles)

handles, labels = pltviz.legend.gen_elements(labels=["Lorenz Curve", "Perfect Equality"])

ax.legend(
    handles=handles,
    labels=labels,
    loc='upper left',
    bbox_to_anchor=(0, 0.9),
    fontsize=20,
    frameon=True,
    facecolor='#FFFFFF',
    framealpha=1)

ax.set_title(f'Gini: {gini_coeff}', fontsize=20)
ax.set_ylabel('Cuumlative Share of Global GDP', fontsize=15)
ax.set_xlabel('Income Deciles', fontsize=15)

plt.show()

To-Do

Please see the contribution guidelines if you are interested in contributing to this project. Work that is in progress or could be implemented includes:

  • Adding standardized examples of further plots and visualizations (see issue)

  • Finishing the coloration on the outer ring of pltviz.pie

  • Improving tests for greater code coverage

  • Improving code quality by refactoring large functions and checking conventions

  • Allowing all plotting variations to be seamlessly plotted from either lists or dataframe columns where applicable

You might also like...
Painlessly create beautiful matplotlib plots.
Painlessly create beautiful matplotlib plots.

Announcement Thank you to everyone who has used prettyplotlib and made it what it is today! Unfortunately, I no longer have the bandwidth to maintain

Example scripts for generating plots of Bohemian matrices
Example scripts for generating plots of Bohemian matrices

Bohemian Eigenvalue Plotting Examples This repository contains examples of generating plots of Bohemian eigenvalues. The examples in this repository a

Moscow DEG 2021 elections plots
Moscow DEG 2021 elections plots

Построение графиков на основе публичных данных о ДЭГ в Москве в 2021г. Описание Скрипты в данном репозитории позволяют собственноручно построить графи

This plugin plots the time you spent on a tag as a histogram.
This plugin plots the time you spent on a tag as a histogram.

This plugin plots the time you spent on a tag as a histogram.

Generate
Generate "Jupiter" plots for circular genomes

jupiter Generate "Jupiter" plots for circular genomes Description Python scripts to generate plots from ViennaRNA output. Written in "pidgin" python w

YOPO is an interactive dashboard which generates various standard plots.
YOPO is an interactive dashboard which generates various standard plots.

YOPO is an interactive dashboard which generates various standard plots.you can create various graphs and charts with a click of a button. This tool uses Dash and Flask in backend.

The plottify package is makes matplotlib plots more legible
The plottify package is makes matplotlib plots more legible

plottify The plottify package is makes matplotlib plots more legible. It's a thin wrapper around matplotlib that automatically adjusts font sizes, sca

This component provides a wrapper to display SHAP plots in Streamlit.
This component provides a wrapper to display SHAP plots in Streamlit.

streamlit-shap This component provides a wrapper to display SHAP plots in Streamlit.

Shaded 😎 quantile plots
Shaded 😎 quantile plots

shadyquant 😎 This python package allows you to quantile and plot lines where you have multiple samples, typically for visualizing uncertainty. Your d

Comments
  • Bump urllib3 from 1.26.3 to 1.26.4

    Bump urllib3 from 1.26.3 to 1.26.4

    Bumps urllib3 from 1.26.3 to 1.26.4.

    Release notes

    Sourced from urllib3's releases.

    1.26.4

    :warning: IMPORTANT: urllib3 v2.0 will drop support for Python 2: Read more in the v2.0 Roadmap

    • Changed behavior of the default SSLContext when connecting to HTTPS proxy during HTTPS requests. The default SSLContext now sets check_hostname=True.

    If you or your organization rely on urllib3 consider supporting us via GitHub Sponsors

    Changelog

    Sourced from urllib3's changelog.

    1.26.4 (2021-03-15)

    • Changed behavior of the default SSLContext when connecting to HTTPS proxy during HTTPS requests. The default SSLContext now sets check_hostname=True.
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 2
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced by 37% 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /resources/pltviz_logo.png | 115.97kb | 51.43kb | 55.65% | | /resources/pltviz_logo_transparent.png | 119.64kb | 60.41kb | 49.50% | | /resources/gh_images/semipie.png | 79.69kb | 58.81kb | 26.20% | | /resources/gh_images/bar.png | 53.07kb | 41.96kb | 20.93% | | /resources/gh_images/gini.png | 83.64kb | 70.88kb | 15.25% | | | | | | | Total : | 452.00kb | 283.50kb | 37.28% |


    Black Lives Matter | 💰 donate | 🎓 learn | ✍🏾 sign

    📝 docs | :octocat: repo | 🙋🏾 issues | 🏅 swag | 🏪 marketplace

    opened by imgbot[bot] 1
  • Create concise requirement and env files

    Create concise requirement and env files

    This issue is for creating concise versions of requirements.txt and environment.yml for pltviz. It would be great if these files were created by hand with specific version numbers or generated in a way so that sub-dependencies don't always need to be updated.

    As of now both files are being created with the following commands in the package's conda virtual environment:

    pip list --format=freeze > requirements.txt  
    conda env export --no-builds | grep -v "^prefix: " > environment.yml
    

    pltviz and other obviously unneeded packages are then removed from these files before being uploaded.

    Any insights or help would be much appreciated!

    help wanted good first issue question 
    opened by andrewtavis 0
  • New plots and visualizations

    New plots and visualizations

    Please use this issue to suggest further plots and visualizations that could be added to pltviz. Potential inclusions should meet some of the following criteria:

    • Not have a valid implementation in another package
    • Simplify the plot or visualization's options
    • Enhance the ability of the plot or visualization to present their inputs

    Suggestions would then be converted over to good first issues, with direct pull requests also being accepted once a method is checked :)

    Thanks for your interest in contributing!

    good first issue question 
    opened by andrewtavis 0
Releases(v0.1.0)
  • v0.1.0(Feb 11, 2021)

    First stable release of pltviz

    • Additions include:

    • Changing the package's name to pltviz

    • Full documentation of the package

    • Virtual environment files

    • Bug fixes

    • Extensive testing of all modules with GH Actions and Codecov

    • Code of conduct and contribution guidelines

    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(Dec 10, 2020)

    The minimum viable product of stdviz:

    • Users are able to plot in various advanced, routine, and novel styles

    • Colors are standardized across plots

    • The most common options for plots are made into booleans

    • Legend generation provides full control to the user

    • Examples have been provided to show usage cases

    Source code(tar.gz)
    Source code(zip)
Owner
Andrew Tavis McAllister
Data scientist, developer and designer. Humboldt University of Berlin (MS); University of Oregon (BA).
Andrew Tavis McAllister
This package creates clean and beautiful matplotlib plots that work on light and dark backgrounds

This package creates clean and beautiful matplotlib plots that work on light and dark backgrounds. Inspired by the work of Edward Tufte.

Nico Schlömer 205 Jan 7, 2023
A python package for animating plots build on matplotlib.

animatplot A python package for making interactive as well as animated plots with matplotlib. Requires Python >= 3.5 Matplotlib >= 2.2 (because slider

Tyler Makaro 394 Dec 18, 2022
A python package for animating plots build on matplotlib.

animatplot A python package for making interactive as well as animated plots with matplotlib. Requires Python >= 3.5 Matplotlib >= 2.2 (because slider

Tyler Makaro 356 Feb 16, 2021
Easily convert matplotlib plots from Python into interactive Leaflet web maps.

mplleaflet mplleaflet is a Python library that converts a matplotlib plot into a webpage containing a pannable, zoomable Leaflet map. It can also embe

Jacob Wasserman 502 Dec 28, 2022
A minimal Python package that produces slice plots through h5m DAGMC geometry files

A minimal Python package that produces slice plots through h5m DAGMC geometry files Installation pip install dagmc_geometry_slice_plotter Python API U

Fusion Energy 4 Dec 2, 2022
MPL Plotter is a Matplotlib based Python plotting library built with the goal of delivering publication-quality plots concisely.

MPL Plotter is a Matplotlib based Python plotting library built with the goal of delivering publication-quality plots concisely.

Antonio López Rivera 162 Nov 11, 2022
A Python function that makes flower plots.

Flower plot A Python 3.9+ function that makes flower plots. Installation This package requires at least Python 3.9. pip install

Thomas Roder 4 Jun 12, 2022
Make sankey, alluvial and sankey bump plots in ggplot

The goal of ggsankey is to make beautiful sankey, alluvial and sankey bump plots in ggplot2

David Sjoberg 156 Jan 3, 2023
Plot, scatter plots and histograms in the terminal using braille dots

Plot, scatter plots and histograms in the terminal using braille dots, with (almost) no dependancies. Plot with color or make complex figures - similar to a very small sibling to matplotlib. Or use the canvas to plot dots and lines yourself.

Tammo Ippen 207 Dec 30, 2022
A Python package for caclulations and visualizations in geological sciences.

geo_calcs A Python package for caclulations and visualizations in geological sciences. Free software: MIT license Documentation: https://geo-calcs.rea

Drew Heasman 1 Jul 12, 2022