Original: https://blog.datawrapper.de/weekly-ridgeline-plot/
import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
def dataset_array_to_dataframe(dataset_array):
df = pd.DataFrame.from_records([
(j, i, a)
for i, r in enumerate(dataset_array)
for j, a in enumerate(r)
], columns=["x", "y", "h"])
df.h = df.h + abs(df.h.min())
return df
raw_data_array = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/pulsar.csv", header=None).to_numpy()
df = dataset_array_to_dataframe(raw_data_array)
print(df.shape)
df.head()
(24000, 3)
x | y | h | |
---|---|---|---|
0 | 0 | 0 | 5.24 |
1 | 1 | 0 | 5.14 |
2 | 2 | 0 | 4.96 |
3 | 3 | 0 | 5.05 |
4 | 4 | 0 | 5.46 |
ggplot(df) + \
geom_area_ridges(aes("x", "y", height="h"), \
stat='identity', scale=.25, \
color="white", fill="black",
sampling=sampling_pick(df.shape[0])) + \
scale_y_continuous(trans='reverse') + \
ggsize(600, 600) + \
theme_minimal() + theme(axis='blank', panel_grid='blank') + \
flavor_high_contrast_dark()