Interactive histogramming#

In this example, we have a dataset which contains information about the number of taxi ride drop-offs in New York City in the year 2015. The raw data (obtained from the Vaex documentation) has been histogrammed into three dimensions: latitude, longitude and hour-of-the-day.

The goal is to create an interactive visualization with on-the-fly histogramming and smoothing. It will contain:

  • a central 2D image that shows a longitude-latitude map of the drop-offs, for a single hour-of-the-day slice.

  • a slider above the main panel which allows to navigate the hour-of-the-day dimension, updating the 2D map.

  • a 1D figure below the 2D map, displaying the same data but summed along the latitude dimension.

  • in the 1D panel, we also want to add a gaussian smoothed version of the 1D curve.

[1]:
%matplotlib widget
import scipp as sc
import plopp as pp
from plopp import widgets
from plopp.data import examples
from scipp.scipy.ndimage import gaussian_filter
import ipywidgets as ipw

data = sc.io.load_hdf5(examples.nyc_taxi())
data
Downloading file 'nyc_taxi_data.h5' from 'https://public.esss.dk/groups/scipp/plopp/1/nyc_taxi_data.h5' to '/home/runner/.cache/plopp/1'.
[1]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (45.79 MB)
    • hour: 24
    • latitude: 500
    • longitude: 500
    • hour
      (hour [bin-edge])
      int64
      h
      0, 1, ..., 23, 24
      Values:
      array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24])
    • latitude
      (latitude [bin-edge])
      float64
      deg
      40.6, 40.601, ..., 40.899, 40.9
      Values:
      array([40.6 , 40.6006, 40.6012, 40.6018, 40.6024, 40.603 , 40.6036, 40.6042, 40.6048, 40.6054, 40.606 , 40.6066, 40.6072, 40.6078, 40.6084, 40.609 , 40.6096, 40.6102, 40.6108, 40.6114, 40.612 , 40.6126, 40.6132, 40.6138, 40.6144, 40.615 , 40.6156, 40.6162, 40.6168, 40.6174, 40.618 , 40.6186, 40.6192, 40.6198, 40.6204, 40.621 , 40.6216, 40.6222, 40.6228, 40.6234, 40.624 , 40.6246, 40.6252, 40.6258, 40.6264, 40.627 , 40.6276, 40.6282, 40.6288, 40.6294, 40.63 , 40.6306, 40.6312, 40.6318, 40.6324, 40.633 , 40.6336, 40.6342, 40.6348, 40.6354, 40.636 , 40.6366, 40.6372, 40.6378, 40.6384, 40.639 , 40.6396, 40.6402, 40.6408, 40.6414, 40.642 , 40.6426, 40.6432, 40.6438, 40.6444, 40.645 , 40.6456, 40.6462, 40.6468, 40.6474, 40.648 , 40.6486, 40.6492, 40.6498, 40.6504, 40.651 , 40.6516, 40.6522, 40.6528, 40.6534, 40.654 , 40.6546, 40.6552, 40.6558, 40.6564, 40.657 , 40.6576, 40.6582, 40.6588, 40.6594, 40.66 , 40.6606, 40.6612, 40.6618, 40.6624, 40.663 , 40.6636, 40.6642, 40.6648, 40.6654, 40.666 , 40.6666, 40.6672, 40.6678, 40.6684, 40.669 , 40.6696, 40.6702, 40.6708, 40.6714, 40.672 , 40.6726, 40.6732, 40.6738, 40.6744, 40.675 , 40.6756, 40.6762, 40.6768, 40.6774, 40.678 , 40.6786, 40.6792, 40.6798, 40.6804, 40.681 , 40.6816, 40.6822, 40.6828, 40.6834, 40.684 , 40.6846, 40.6852, 40.6858, 40.6864, 40.687 , 40.6876, 40.6882, 40.6888, 40.6894, 40.69 , 40.6906, 40.6912, 40.6918, 40.6924, 40.693 , 40.6936, 40.6942, 40.6948, 40.6954, 40.696 , 40.6966, 40.6972, 40.6978, 40.6984, 40.699 , 40.6996, 40.7002, 40.7008, 40.7014, 40.702 , 40.7026, 40.7032, 40.7038, 40.7044, 40.705 , 40.7056, 40.7062, 40.7068, 40.7074, 40.708 , 40.7086, 40.7092, 40.7098, 40.7104, 40.711 , 40.7116, 40.7122, 40.7128, 40.7134, 40.714 , 40.7146, 40.7152, 40.7158, 40.7164, 40.717 , 40.7176, 40.7182, 40.7188, 40.7194, 40.72 , 40.7206, 40.7212, 40.7218, 40.7224, 40.723 , 40.7236, 40.7242, 40.7248, 40.7254, 40.726 , 40.7266, 40.7272, 40.7278, 40.7284, 40.729 , 40.7296, 40.7302, 40.7308, 40.7314, 40.732 , 40.7326, 40.7332, 40.7338, 40.7344, 40.735 , 40.7356, 40.7362, 40.7368, 40.7374, 40.738 , 40.7386, 40.7392, 40.7398, 40.7404, 40.741 , 40.7416, 40.7422, 40.7428, 40.7434, 40.744 , 40.7446, 40.7452, 40.7458, 40.7464, 40.747 , 40.7476, 40.7482, 40.7488, 40.7494, 40.75 , 40.7506, 40.7512, 40.7518, 40.7524, 40.753 , 40.7536, 40.7542, 40.7548, 40.7554, 40.756 , 40.7566, 40.7572, 40.7578, 40.7584, 40.759 , 40.7596, 40.7602, 40.7608, 40.7614, 40.762 , 40.7626, 40.7632, 40.7638, 40.7644, 40.765 , 40.7656, 40.7662, 40.7668, 40.7674, 40.768 , 40.7686, 40.7692, 40.7698, 40.7704, 40.771 , 40.7716, 40.7722, 40.7728, 40.7734, 40.774 , 40.7746, 40.7752, 40.7758, 40.7764, 40.777 , 40.7776, 40.7782, 40.7788, 40.7794, 40.78 , 40.7806, 40.7812, 40.7818, 40.7824, 40.783 , 40.7836, 40.7842, 40.7848, 40.7854, 40.786 , 40.7866, 40.7872, 40.7878, 40.7884, 40.789 , 40.7896, 40.7902, 40.7908, 40.7914, 40.792 , 40.7926, 40.7932, 40.7938, 40.7944, 40.795 , 40.7956, 40.7962, 40.7968, 40.7974, 40.798 , 40.7986, 40.7992, 40.7998, 40.8004, 40.801 , 40.8016, 40.8022, 40.8028, 40.8034, 40.804 , 40.8046, 40.8052, 40.8058, 40.8064, 40.807 , 40.8076, 40.8082, 40.8088, 40.8094, 40.81 , 40.8106, 40.8112, 40.8118, 40.8124, 40.813 , 40.8136, 40.8142, 40.8148, 40.8154, 40.816 , 40.8166, 40.8172, 40.8178, 40.8184, 40.819 , 40.8196, 40.8202, 40.8208, 40.8214, 40.822 , 40.8226, 40.8232, 40.8238, 40.8244, 40.825 , 40.8256, 40.8262, 40.8268, 40.8274, 40.828 , 40.8286, 40.8292, 40.8298, 40.8304, 40.831 , 40.8316, 40.8322, 40.8328, 40.8334, 40.834 , 40.8346, 40.8352, 40.8358, 40.8364, 40.837 , 40.8376, 40.8382, 40.8388, 40.8394, 40.84 , 40.8406, 40.8412, 40.8418, 40.8424, 40.843 , 40.8436, 40.8442, 40.8448, 40.8454, 40.846 , 40.8466, 40.8472, 40.8478, 40.8484, 40.849 , 40.8496, 40.8502, 40.8508, 40.8514, 40.852 , 40.8526, 40.8532, 40.8538, 40.8544, 40.855 , 40.8556, 40.8562, 40.8568, 40.8574, 40.858 , 40.8586, 40.8592, 40.8598, 40.8604, 40.861 , 40.8616, 40.8622, 40.8628, 40.8634, 40.864 , 40.8646, 40.8652, 40.8658, 40.8664, 40.867 , 40.8676, 40.8682, 40.8688, 40.8694, 40.87 , 40.8706, 40.8712, 40.8718, 40.8724, 40.873 , 40.8736, 40.8742, 40.8748, 40.8754, 40.876 , 40.8766, 40.8772, 40.8778, 40.8784, 40.879 , 40.8796, 40.8802, 40.8808, 40.8814, 40.882 , 40.8826, 40.8832, 40.8838, 40.8844, 40.885 , 40.8856, 40.8862, 40.8868, 40.8874, 40.888 , 40.8886, 40.8892, 40.8898, 40.8904, 40.891 , 40.8916, 40.8922, 40.8928, 40.8934, 40.894 , 40.8946, 40.8952, 40.8958, 40.8964, 40.897 , 40.8976, 40.8982, 40.8988, 40.8994, 40.9 ])
    • longitude
      (longitude [bin-edge])
      float64
      deg
      -74.05, -74.049, ..., -73.751, -73.75
      Values:
      array([-74.05 , -74.0494, -74.0488, -74.0482, -74.0476, -74.047 , -74.0464, -74.0458, -74.0452, -74.0446, -74.044 , -74.0434, -74.0428, -74.0422, -74.0416, -74.041 , -74.0404, -74.0398, -74.0392, -74.0386, -74.038 , -74.0374, -74.0368, -74.0362, -74.0356, -74.035 , -74.0344, -74.0338, -74.0332, -74.0326, -74.032 , -74.0314, -74.0308, -74.0302, -74.0296, -74.029 , -74.0284, -74.0278, -74.0272, -74.0266, -74.026 , -74.0254, -74.0248, -74.0242, -74.0236, -74.023 , -74.0224, -74.0218, -74.0212, -74.0206, -74.02 , -74.0194, -74.0188, -74.0182, -74.0176, -74.017 , -74.0164, -74.0158, -74.0152, -74.0146, -74.014 , -74.0134, -74.0128, -74.0122, -74.0116, -74.011 , -74.0104, -74.0098, -74.0092, -74.0086, -74.008 , -74.0074, -74.0068, -74.0062, -74.0056, -74.005 , -74.0044, -74.0038, -74.0032, -74.0026, -74.002 , -74.0014, -74.0008, -74.0002, -73.9996, -73.999 , -73.9984, -73.9978, -73.9972, -73.9966, -73.996 , -73.9954, -73.9948, -73.9942, -73.9936, -73.993 , -73.9924, -73.9918, -73.9912, -73.9906, -73.99 , -73.9894, -73.9888, -73.9882, -73.9876, -73.987 , -73.9864, -73.9858, -73.9852, -73.9846, -73.984 , -73.9834, -73.9828, -73.9822, -73.9816, -73.981 , -73.9804, -73.9798, -73.9792, -73.9786, -73.978 , -73.9774, -73.9768, -73.9762, -73.9756, -73.975 , -73.9744, -73.9738, -73.9732, -73.9726, -73.972 , -73.9714, -73.9708, -73.9702, -73.9696, -73.969 , -73.9684, -73.9678, -73.9672, -73.9666, -73.966 , -73.9654, -73.9648, -73.9642, -73.9636, -73.963 , -73.9624, -73.9618, -73.9612, -73.9606, -73.96 , -73.9594, -73.9588, -73.9582, -73.9576, -73.957 , -73.9564, -73.9558, -73.9552, -73.9546, -73.954 , -73.9534, -73.9528, -73.9522, -73.9516, -73.951 , -73.9504, -73.9498, -73.9492, -73.9486, -73.948 , -73.9474, -73.9468, -73.9462, -73.9456, -73.945 , -73.9444, -73.9438, -73.9432, -73.9426, -73.942 , -73.9414, -73.9408, -73.9402, -73.9396, -73.939 , -73.9384, -73.9378, -73.9372, -73.9366, -73.936 , -73.9354, -73.9348, -73.9342, -73.9336, -73.933 , -73.9324, -73.9318, -73.9312, -73.9306, -73.93 , -73.9294, -73.9288, -73.9282, -73.9276, -73.927 , -73.9264, -73.9258, -73.9252, -73.9246, -73.924 , -73.9234, -73.9228, -73.9222, -73.9216, -73.921 , -73.9204, -73.9198, -73.9192, -73.9186, -73.918 , -73.9174, -73.9168, -73.9162, -73.9156, -73.915 , -73.9144, -73.9138, -73.9132, -73.9126, -73.912 , -73.9114, -73.9108, -73.9102, -73.9096, -73.909 , -73.9084, -73.9078, -73.9072, -73.9066, -73.906 , -73.9054, -73.9048, -73.9042, -73.9036, -73.903 , -73.9024, -73.9018, -73.9012, -73.9006, -73.9 , -73.8994, -73.8988, -73.8982, -73.8976, -73.897 , -73.8964, -73.8958, -73.8952, -73.8946, -73.894 , -73.8934, -73.8928, -73.8922, -73.8916, -73.891 , -73.8904, -73.8898, -73.8892, -73.8886, -73.888 , -73.8874, -73.8868, -73.8862, -73.8856, -73.885 , -73.8844, -73.8838, -73.8832, -73.8826, -73.882 , -73.8814, -73.8808, -73.8802, -73.8796, -73.879 , -73.8784, -73.8778, -73.8772, -73.8766, -73.876 , -73.8754, -73.8748, -73.8742, -73.8736, -73.873 , -73.8724, -73.8718, -73.8712, -73.8706, -73.87 , -73.8694, -73.8688, -73.8682, -73.8676, -73.867 , -73.8664, -73.8658, -73.8652, -73.8646, -73.864 , -73.8634, -73.8628, -73.8622, -73.8616, -73.861 , -73.8604, -73.8598, -73.8592, -73.8586, -73.858 , -73.8574, -73.8568, -73.8562, -73.8556, -73.855 , -73.8544, -73.8538, -73.8532, -73.8526, -73.852 , -73.8514, -73.8508, -73.8502, -73.8496, -73.849 , -73.8484, -73.8478, -73.8472, -73.8466, -73.846 , -73.8454, -73.8448, -73.8442, -73.8436, -73.843 , -73.8424, -73.8418, -73.8412, -73.8406, -73.84 , -73.8394, -73.8388, -73.8382, -73.8376, -73.837 , -73.8364, -73.8358, -73.8352, -73.8346, -73.834 , -73.8334, -73.8328, -73.8322, -73.8316, -73.831 , -73.8304, -73.8298, -73.8292, -73.8286, -73.828 , -73.8274, -73.8268, -73.8262, -73.8256, -73.825 , -73.8244, -73.8238, -73.8232, -73.8226, -73.822 , -73.8214, -73.8208, -73.8202, -73.8196, -73.819 , -73.8184, -73.8178, -73.8172, -73.8166, -73.816 , -73.8154, -73.8148, -73.8142, -73.8136, -73.813 , -73.8124, -73.8118, -73.8112, -73.8106, -73.81 , -73.8094, -73.8088, -73.8082, -73.8076, -73.807 , -73.8064, -73.8058, -73.8052, -73.8046, -73.804 , -73.8034, -73.8028, -73.8022, -73.8016, -73.801 , -73.8004, -73.7998, -73.7992, -73.7986, -73.798 , -73.7974, -73.7968, -73.7962, -73.7956, -73.795 , -73.7944, -73.7938, -73.7932, -73.7926, -73.792 , -73.7914, -73.7908, -73.7902, -73.7896, -73.789 , -73.7884, -73.7878, -73.7872, -73.7866, -73.786 , -73.7854, -73.7848, -73.7842, -73.7836, -73.783 , -73.7824, -73.7818, -73.7812, -73.7806, -73.78 , -73.7794, -73.7788, -73.7782, -73.7776, -73.777 , -73.7764, -73.7758, -73.7752, -73.7746, -73.774 , -73.7734, -73.7728, -73.7722, -73.7716, -73.771 , -73.7704, -73.7698, -73.7692, -73.7686, -73.768 , -73.7674, -73.7668, -73.7662, -73.7656, -73.765 , -73.7644, -73.7638, -73.7632, -73.7626, -73.762 , -73.7614, -73.7608, -73.7602, -73.7596, -73.759 , -73.7584, -73.7578, -73.7572, -73.7566, -73.756 , -73.7554, -73.7548, -73.7542, -73.7536, -73.753 , -73.7524, -73.7518, -73.7512, -73.7506, -73.75 ])
    • (hour, latitude, longitude)
      float64
      counts
      0.0, 0.0, ..., 0.0, 0.0
      Values:
      array([[[0., 0., 0., ..., 0., 1., 1.], [0., 0., 0., ..., 0., 0., 1.], [0., 0., 0., ..., 1., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]], [[0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 1.], [0., 0., 0., ..., 1., 0., 0.], ..., [0., 1., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]], [[0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 1., 0.], [0., 0., 0., ..., 1., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]], ..., [[0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 3.], [0., 0., 0., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]], [[0., 0., 0., ..., 0., 0., 2.], [0., 0., 0., ..., 0., 1., 1.], [0., 0., 0., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]], [[0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 2., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]]])
[2]:
# Slider node that provides index to slice
slider = ipw.IntSlider(description='Hour:', min=0, max=23)
slider_node = pp.widget_node(slider)

# Node that actually does the slicing
slice_node = pp.Node(lambda da, ind: da['hour', ind], da=data, ind=slider_node)

# Add a 2D figure to show the NYC map
fig2d = pp.imagefigure(slice_node, norm='log')

# Add a node after the slicing to sum along the latitude dimension
sum_lat = pp.Node(sc.sum, slice_node, dim='latitude')

# Add a node after the sum that performs as Gaussian smoothing
smooth = pp.Node(gaussian_filter, sum_lat, sigma=5)

# Add a 1D figure that will display both raw sum and smoothed data
fig1d = pp.linefigure(sum_lat, smooth, norm='log')

widgets.Box([slider, fig2d, fig1d])  # Container box
[2]:

Below is a preview of the graph of connected nodes:

[3]:
pp.show_graph(fig1d)
[3]:
../_images/gallery_nyc-taxi_4_0.svg