bindings/jupyter/notebooks/stacked-calendar.ipynb (125 lines of code) (raw):
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Stacked Calendar\n",
"\n",
"The Stacked Calendar component aggregates hourly-stamped values and visualizes the results in the form of a calendar.\n",
"\n",
"The columns and rows are corresponding to the day_of_week and hour_of_day, respectively.\n",
"The data values of each cell (hour) are aggregated, percentiled, and mapped to color gradients to reveal the value distributions.\n",
"\n",
"## Usage"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "39dff501adc7437caa3c408879aacadb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"StackedCalendar(props='{\"data\": [{\"hour_of_week\": 0, \"value\": \"0.443316065\"}, {\"hour_of_week\": 0, \"value\": \"0.…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from mlvis import StackedCalendar\n",
"from IPython.display import display\n",
"import pandas as pd\n",
"\n",
"PREFIX = 'https://d1a3f4spazzrp4.cloudfront.net/mlvis/'\n",
"data_frame = pd.read_csv(PREFIX + 'jupyter/stacked-calendar-sample.csv')\n",
"data = data_frame.to_dict('records')\n",
"\n",
"calendar = StackedCalendar(props={\"data\": data, \"valueRange\": [0, 1.5]})\n",
"display(calendar)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data Format"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" hour_of_week value\n",
"10000 66 0.272818888\n",
"10001 66 0.645657585\n",
"10002 66 0.243684833\n",
"10003 66 0.237157524\n",
"10004 66 0.238575395\n",
"10005 66 0.175796772\n",
"10006 66 0.226707148\n",
"10007 66 0.221181026\n",
"10008 66 0.263068202\n",
"10009 66 0.140494919\n"
]
}
],
"source": [
"print(pd.DataFrame(data)[10000:10010])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Properties\n",
"\n",
"#### `data` (List, required)\n",
"\n",
"- Default: []\n",
"\n",
"The input data list, each datum should at least two attributes: _hour_of_week_ (range: [0, 167]) and _value_.\n",
"\n",
"#### `valueRange` (List, optional)\n",
"\n",
"- Default: [0, 1]\n",
"\n",
"The value range used for the color mapping. If data is not specified, valueRange is default to [0, 1]. Otherwise, it will be derived as the [min, max] of the values."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}