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"])
return df
raw_data_array = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/new_zealand.csv", header=None).to_numpy()
df = dataset_array_to_dataframe(raw_data_array)
df = df[df.h > 0]
print(df.shape)
df.head()
(1095, 3)
x | y | h | |
---|---|---|---|
505 | 105 | 2 | 130.991302 |
507 | 107 | 2 | 19.021566 |
910 | 110 | 4 | 39.025543 |
914 | 114 | 4 | 4.319343 |
915 | 115 | 4 | 41.220718 |
ggplot(df) + \
geom_area_ridges(aes("x", "y", height="h"), \
stat='identity', scale=.002, \
color="#08519c", fill="#bdd7e7",
sampling=sampling_pick(df.shape[0]), \
tooltips='none') + \
geom_text(x=140, y=65, label="New Zealand", size=20, family="Cinzel") + \
scale_y_continuous(trans='reverse') + \
ggsize(600, 600) + \
theme_minimal() + theme(axis='blank', panel_grid='blank', \
plot_background=element_rect(color='black', fill='#e6e6e6', size=1))