https://github.com/andrewtavis/pltviz
Standardized plots and visualizations in Python
https://github.com/andrewtavis/pltviz
gini open-source plotting plotting-in-python plotting-variations python python3 visualization
Last synced: 2 months ago
JSON representation
Standardized plots and visualizations in Python
- Host: GitHub
- URL: https://github.com/andrewtavis/pltviz
- Owner: andrewtavis
- License: bsd-3-clause
- Created: 2020-12-08T15:46:57.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-24T20:03:14.000Z (over 1 year ago)
- Last Synced: 2025-03-24T11:41:43.720Z (3 months ago)
- Topics: gini, open-source, plotting, plotting-in-python, plotting-variations, python, python3, visualization
- Language: Python
- Homepage:
- Size: 2.43 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](http://pltviz.readthedocs.io/en/latest/)
[](https://github.com/andrewtavis/pltviz/actions?query=workflow%3ACI)
[](https://codecov.io/gh/andrewtavis/pltviz)
[](https://pypi.org/project/pltviz/)
[](https://pypi.org/project/pltviz/)
[](https://pypi.org/project/pltviz/)
[](https://github.com/andrewtavis/pltviz/blob/main/LICENSE.txt)
[](https://github.com/andrewtavis/pltviz/blob/main/.github/CODE_OF_CONDUCT.md)
[](https://github.com/psf/black)
[](https://colab.research.google.com/github/andrewtavis/pltviz)## 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](#installation)
- [plot](#plot)
- [To-Do](#to-do)# Installation [`⇧`](#contents)
pltviz can be downloaded from PyPI via pip or sourced directly from this repository:
```bash
pip install pltviz
``````bash
git clone https://github.com/andrewtavis/pltviz.git
cd pltviz
python setup.py install
``````python
import pltviz
```# plot [`⇧`](#contents)
Plotting methods within [pltviz](https://github.com/andrewtavis/pltviz/tree/main/src/pltviz) are tailored to provide quick results for staples of data visualization.
See [examples/plot](https://github.com/andrewtavis/pltviz/blob/main/examples/plot.ipynb) for all plotting styles that seamlessly combine graphing functions of seaborn, matplotlib, and pandas.
```python
import matplotlib.pyplot as plt
import pltviz
```Examples of routine plotting techniques made easy are:
```python
# 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](https://github.com/andrewtavis/pltviz/blob/main/src/pltviz/bar.py) that allows all common options to be selected as binaries:
```python
# 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](https://github.com/andrewtavis/pltviz/blob/main/src/pltviz/semipie.py) via matplotlib artists for cases where a simple and condensed plot is needed:
```python
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](https://github.com/andrewtavis/pltviz/blob/main/src/pltviz/gini.py) to visualize [gini coefficients](https://en.wikipedia.org/wiki/Gini_coefficient) of inequality:
```python
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 [`⇧`](#contents)
Please see the [contribution guidelines](https://github.com/andrewtavis/pltviz/blob/main/.github/CONTRIBUTING.md) 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)](https://github.com/andrewtavis/pltviz/issues/12)
- Finishing the coloration on the outer ring of [pltviz.pie](https://github.com/andrewtavis/pltviz/blob/main/src/pltviz/pie.py)
- Improving [tests](https://github.com/andrewtavis/pltviz/tree/main/tests) for greater [code coverage](https://codecov.io/gh/andrewtavis/pltviz)
- Improving [code quality](https://app.codacy.com/gh/andrewtavis/pltviz/dashboard) by refactoring large functions and checking conventions
- Allowing all plotting variations to be seamlessly plotted from either lists or dataframe columns where applicable