Beautiful ridgeline plots in python
Project description
ridgeplot: beautiful ridgeline plots in Python
ridgeplot
is a Python package that provides a simple interface for plotting beautiful and interactive ridgeline plots within the extensive Plotly ecosystem.
Installation
ridgeplot
can be installed and updated from PyPi using pip:
pip install -U ridgeplot
For more information, see the installation guide.
Getting started
Take a look at the getting started guide, which provides a quick introduction to the ridgeplot
library.
The full official documentation can be found at: https://ridgeplot.readthedocs.io/en/stable/
Basic example
For those in a hurry, here's a very basic example on how to quickly get started with ridgeplot() function.
import numpy as np
from ridgeplot import ridgeplot
my_samples = [np.random.normal(n / 1.2, size=600) for n in range(7, 0, -1)]
fig = ridgeplot(samples=my_samples)
fig.show()
Flexible configuration
In this example, we will try to replicate the first ridgeline plot in this from Data to Viz post. The example in the post was created using the "Perception of Probability Words" dataset and the popular ggridges R package. In the end, we will see how the ridgeplot
Python library can be used to create a (nearly) identical plot, thanks to its extensive configuration options.
import numpy as np
from ridgeplot import ridgeplot
from ridgeplot.datasets import load_probly
# Load the probly dataset
df = load_probly()
# Let's grab the subset of columns used in the example
column_names = [
"Almost Certainly",
"Very Good Chance",
"We Believe",
"Likely",
"About Even",
"Little Chance",
"Chances Are Slight",
"Almost No Chance",
]
df = df[column_names]
# Not only does 'ridgeplot(...)' come configured with sensible defaults
# but is also fully configurable to your own style and preference!
fig = ridgeplot(
samples=df.to_numpy().T,
bandwidth=4,
kde_points=np.linspace(-12.5, 112.5, 500),
colorscale="viridis",
colormode="row-index",
opacity=0.6,
labels=column_names,
spacing=5 / 9,
)
# And you can still update and extend the final
# Plotly Figure using standard Plotly methods
fig.update_layout(
height=560,
width=800,
font_size=16,
plot_bgcolor="white",
xaxis_tickvals=[-12.5, 0, 12.5, 25, 37.5, 50, 62.5, 75, 87.5, 100, 112.5],
xaxis_ticktext=["", "0", "", "25", "", "50", "", "75", "", "100", ""],
xaxis_gridcolor="rgba(0, 0, 0, 0.1)",
yaxis_gridcolor="rgba(0, 0, 0, 0.1)",
yaxis_title=dict(text="Assigned Probability (%)", font_size=13),
showlegend=False,
)
# Show us the work!
fig.show()
More examples
For more examples, take a look at the getting started guide. For instance, this example demonstrates how you can also draw multiple traces per row in your ridgeline plot:
import numpy as np
from ridgeplot import ridgeplot
from ridgeplot.datasets import load_lincoln_weather
# Load test data
df = load_lincoln_weather()
# Transform the data into a 3D (ragged) array format of
# daily min and max temperature samples per month
months = df.index.month_name().unique()
samples = [
[
df[df.index.month_name() == month]["Min Temperature [F]"],
df[df.index.month_name() == month]["Max Temperature [F]"],
]
for month in months
]
# And finish by styling it up to your liking!
fig = ridgeplot(
samples=samples,
labels=months,
colorscale="Inferno",
bandwidth=4,
kde_points=np.linspace(-40, 110, 400),
spacing=0.3,
)
fig.update_layout(
title="Minimum and maximum daily temperatures in Lincoln, NE (2016)",
height=600,
width=800,
font_size=14,
plot_bgcolor="rgb(245, 245, 245)",
xaxis_gridcolor="white",
yaxis_gridcolor="white",
xaxis_gridwidth=2,
yaxis_title="Month",
xaxis_title="Temperature [F]",
showlegend=False,
)
fig.show()
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
File details
Details for the file ridgeplot-0.2.0.tar.gz
.
File metadata
- Download URL: ridgeplot-0.2.0.tar.gz
- Upload date:
- Size: 2.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ce1467a2fbe3610710f33ee08f0e0595f7984053758b6805f8894b6c72b3205 |
|
MD5 | e0d926e20adab1fca54d86fb734ba8d0 |
|
BLAKE2b-256 | 260d80d4eefb9328cd41516738c86c212d83af2be5ffa9a7241fe66e9bad0838 |
Provenance
The following attestation bundles were made for ridgeplot-0.2.0.tar.gz
:
Publisher:
release.yml
on tpvasconcelos/ridgeplot
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
ridgeplot-0.2.0.tar.gz
- Subject digest:
7ce1467a2fbe3610710f33ee08f0e0595f7984053758b6805f8894b6c72b3205
- Sigstore transparency entry: 151077398
- Sigstore integration time:
- Predicate type:
File details
Details for the file ridgeplot-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: ridgeplot-0.2.0-py3-none-any.whl
- Upload date:
- Size: 52.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea5bad360f1abb75b63af4c5e80c61e0faa166ca01d204b038ecc041863c7d53 |
|
MD5 | 567eee05a3c8196ba664a17aeb939668 |
|
BLAKE2b-256 | 9540ffb654990230e9a72bbaafa1d0dcce2e5e0396f97e9f02532cee68daf225 |
Provenance
The following attestation bundles were made for ridgeplot-0.2.0-py3-none-any.whl
:
Publisher:
release.yml
on tpvasconcelos/ridgeplot
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
ridgeplot-0.2.0-py3-none-any.whl
- Subject digest:
ea5bad360f1abb75b63af4c5e80c61e0faa166ca01d204b038ecc041863c7d53
- Sigstore transparency entry: 151077399
- Sigstore integration time:
- Predicate type: