Bar charts where human silhouettes vary in fatness and height to represent data values
Project description
dfmp
A matplotlib-based library that generates bar charts where human silhouettes are horizontally scaled (wider/thinner) and vertically scaled (taller/shorter) to represent data values.
How it works
Each silhouette is generated by interpolating between pre-computed body profiles stored in silhouette_data.npz. The data values are min-max normalized to determine both the "fatness" (horizontal width) and height of each figure. The silhouettes are rendered as matplotlib.patches.PathPatch objects, so they integrate naturally with the rest of the matplotlib ecosystem.
Installation
Requires Python 3.9+.
pip install git+https://github.com/djemec/dfmp.git
Or install locally for development:
git clone https://github.com/djemec/dfmp.git
cd dfmp
pip install -e ".[dev]"
Dependencies
- matplotlib >= 3.5
- numpy >= 1.21
- scipy >= 1.9
Quick start
from dfmp import plot
plot(['A', 'B', 'C', 'D', 'E'], [12, 35, 28, 50, 19])
The API is designed to mirror plt.bar() -- if you know how to make a bar chart, you know how to make a dfmp plot.
API
plot(x, height, *, color=None, alpha=None, tick_label=None,
label=None, show_values=True, value_format=None,
ax=None, **kwargs)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
x |
array-like | (required) | String labels or numeric positions. Strings are used as tick labels automatically. |
height |
array-like | (required) | Data values that drive both fatness and vertical scaling of each silhouette. |
color |
str or list | '#5B9A8B' |
Single color for all figures, or a list of colors (one per figure). |
alpha |
float | None |
Opacity (0--1) applied to every silhouette. |
tick_label |
list of str | None |
Override x-axis labels when x is numeric. |
label |
str | None |
Legend label for this set of silhouettes. |
show_values |
bool | True |
Annotate each silhouette with its data value. |
value_format |
str or callable | None |
Format string (e.g. '{:.1f}%') or callable f(val) -> str for value annotations. |
ax |
Axes | None |
Target matplotlib axes. Creates a new figure if None. |
**kwargs |
Passed through to matplotlib.patches.PathPatch. |
Returns
matplotlib.axes.Axes -- the axes containing the chart (following the seaborn convention).
Examples
from dfmp import plot
import matplotlib.pyplot as plt
ax = plot(
['A', 'B', 'C'],
[10, 50, 100],
color=['#E76F51', '#2A9D8F', '#264653'], #optional
value_format='{:.1f}' # optional
)
#matplotlib config examples
plt.title('My chart')
plt.xlabel('Categories')
plt.show()
# save to a file
ax.figure.savefig('chart.png', dpi=150, bbox_inches='tight', facecolor='white')
Drawing on an existing axes
Pass an ax to draw on a pre-existing figure, just like seaborn or matplotlib.
import matplotlib.pyplot as plt
from dfmp import plot
fig, ax = plt.subplots(figsize=(10, 6))
plot(['A', 'B', 'C'], [10, 20, 30], ax=ax)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dfmp-0.1.0.tar.gz.
File metadata
- Download URL: dfmp-0.1.0.tar.gz
- Upload date:
- Size: 86.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28857eab8238ae6b101b8f644815cacb6283b92ae98cb8b413d735b5e582b70d
|
|
| MD5 |
e2e8809cb21aeedb4f400f8cd954f4c3
|
|
| BLAKE2b-256 |
0909cef1eb724c8298c4d1d1f821ee477023caeab193a0cc6de2ba732e2e1c7f
|
File details
Details for the file dfmp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dfmp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 82.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5d90c9f862aa30abb13595a1d881dc3f35e7241ea60fa97c626354ea0b6f470
|
|
| MD5 |
2264195211895435b4e8c0d6c851a776
|
|
| BLAKE2b-256 |
5ede47e81ad95f82675305dc5dc9609120faa2fa73844d8cbaa99635d2785226
|