Super-quick interactive data & parameter exploration
source link: https://anitagraser.com/2020/04/12/super-quick-interactive-data-parameter-exploration/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Super-quick interactive data & parameter exploration
This post introduces Holoviz Panel, a library that makes it possible to create really quick dashboards in notebook environments as well as more sophisticated custom interactive web apps and dashboards.
The following example shows how to use Panel to explore a dataset (a trajectory collection in this case) and different parameter settings (relating to trajectory generalization). All the Panel code we need is a dict that defines the parameters that we want to explore. Then we can use Panel’s interact function to automatically generate a dashboard for our custom plotting function:
import
panel as pn
kw
=
dict
(traj_id
=
(
1
,
len
(traj_collection)),
tolerance
=
(
10
,
100
,
10
),
generalizer
=
[
'douglas-peucker'
,
'min-distance'
])
pn.interact(plot_generalized,
*
*
kw)
Click to view the resulting dashboard in full resolution:
The plotting function uses the parameters to generate a Holoviews plot. First it fetches a specific trajectory from the trajectory collection. Then it generalizes the trajectory using the specified parameter settings. As you can see, we can easily combine maps and other plots to visualize different aspects of the data:
def
plot_generalized(traj_id
=
1
, tolerance
=
10
, generalizer
=
'douglas-peucker'
):
my_traj
=
traj_collection.get_trajectory(traj_id).to_crs(CRS(
4088
))
if
generalizer
=
=
'douglas-peucker'
:
generalized
=
mpd.DouglasPeuckerGeneralizer(my_traj).generalize(tolerance)
else
:
generalized
=
mpd.MinDistanceGeneralizer(my_traj).generalize(tolerance)
generalized.add_speed(overwrite
=
True
)
return
(
generalized.hvplot(
title
=
'Trajectory {} (tolerance={})'
.
format
(my_traj.
id
, tolerance),
c
=
'speed'
, cmap
=
'Viridis'
, colorbar
=
True
, clim
=
(
0
,
20
),
line_width
=
10
, width
=
500
, height
=
500
)
+
generalized.df[
'speed'
].hvplot.hist(
title
=
'Speed histogram'
, width
=
300
, height
=
500
)
)
Trajectory collections and generalization functions used in this example are part of the MovingPandas library. If you are interested in movement data analysis, you should check it out! You can find this example notebook in the MovingPandas tutorial section.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK