Seaborn-style utility to plot spider charts
Project description
spider-chart
Create 2D spider charts using seaborn.
A spider chart is a type of relatinal plot. The implementation is based on seaborn's lineplot() using a polar coordinate system.
Installation
The package can be installed via pip:
pip install spiderplot
Use the following commands for a quick verification of the installation.
python -c "import spiderplot; print(spiderplot.__version__)"
python -c "import spiderplot; spiderplot.demo_pair()"
Usage
Similar to seaborn functions, spiderplot accepts different data formats:
- array mode: x, y and other parameters are np.arrays
- long-form mode: x, y, hue, size, extent can be keys of data
- wide-form mode: only argument data is required, where x: row indices; and y: table values (data.values), with the columns representing different categories.
See this about data structures in seaborn.
To print the help text of the function:
python -c "import spiderplot as sp; help(sp.spiderplot)"
python -c "import spiderplot as sp; help(sp.spiderplot_facet)"
See the examples for further usage information.
### Basic example
import seaborn as sns
import spiderplot as sp
import matplotlib.pyplot as plt
sns.set_style("whitegrid")
# Load some demo data.
df = sp.demo.generate_data(mode="long-form", d=1)
# Create spider plot.
ax = sp.spiderplot(x="x", y="value", hue="dataset", legend=False,
data=df, palette="husl", rref=0)
# Adjust limits in radial direction.
ax.set_rlim([-1.4,1.4])
plt.show()
### Multiple plots
df = sp.demo.generate_data_pair(mode="long-form")
sns.set_style("whitegrid")
ax = sp.spiderplot(x="x", y="value", hue="dataset", style="dataset",
data=df, dashes=False, palette="husl", rref=0)
ax.set_rlim([-1.4,1.4])
ax.legend(loc="upper right",
bbox_to_anchor=(1.4, 1.),
borderaxespad=0.)
plt.tight_layout()
plt.show()
Data aggregation
df = sp.demo.generate_data(mode="long-form", n=24, d=10)
means = df.groupby("x")["value"].mean()
stds = df.groupby("x")["value"].std()
sns.set_style("whitegrid")
ax = sp.spiderplot(y=means, extent=stds, color="red", fillcolor="gray",
fill=False, rref=0, label="mean ± std")
ax.set_rlim([-1.4,1.4])
ax.legend(loc="upper right",
bbox_to_anchor=(1.4, 1.),
borderaxespad=0.)
plt.tight_layout()
plt.show()
Requirements
Python>=3.6
numpy
pandas>=0.22
matplotlib>=3.0
seaborn>=0.9
Project setup
git clone https://github.com/hirsch-lab/spider-chart.git
cd spider-chart
pip install -r requirements.txt
# Run examples
./examples/run_all.py
# Build package
python setup.py sdist bdist_wheel
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
spiderplot-0.1.0.tar.gz
(15.0 kB
view hashes)
Built Distribution
spiderplot-0.1.0-py3-none-any.whl
(10.0 kB
view hashes)
Close
Hashes for spiderplot-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0843207724292c7446fcfb2088503a4347cd0c5a063495b1432056ab36110d0a |
|
MD5 | e3dacdb2c7b9ed18b4a2645c7f37bf76 |
|
BLAKE2b-256 | 96159891510007d497f05e5670f8570b68fb8e1c04e4e824b01fab0330dc1dc0 |