Skip to content

Commit

Permalink
adding ability to stack lines in plot grid
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewm4894 committed May 14, 2020
1 parent 6362ac6 commit c40c165
Showing 1 changed file with 241 additions and 0 deletions.
241 changes: 241 additions & 0 deletions examples/grid_with_stacked.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1342, 10)\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>col0</th>\n",
" <th>col1</th>\n",
" <th>col2</th>\n",
" <th>col3</th>\n",
" <th>col4</th>\n",
" <th>col5</th>\n",
" <th>col6</th>\n",
" <th>col7</th>\n",
" <th>col8</th>\n",
" <th>col9</th>\n",
" </tr>\n",
" <tr>\n",
" <th>time</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2019-01-01 01:39:00</th>\n",
" <td>0.094637</td>\n",
" <td>-0.026028</td>\n",
" <td>0.009788</td>\n",
" <td>-0.086360</td>\n",
" <td>0.094658</td>\n",
" <td>-0.159012</td>\n",
" <td>0.010536</td>\n",
" <td>0.185730</td>\n",
" <td>0.032680</td>\n",
" <td>-0.134111</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2019-01-01 01:40:00</th>\n",
" <td>0.104604</td>\n",
" <td>-0.039314</td>\n",
" <td>0.027469</td>\n",
" <td>-0.067474</td>\n",
" <td>0.087105</td>\n",
" <td>-0.177999</td>\n",
" <td>0.022651</td>\n",
" <td>0.192941</td>\n",
" <td>0.003287</td>\n",
" <td>-0.139535</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2019-01-01 01:41:00</th>\n",
" <td>0.100678</td>\n",
" <td>-0.044442</td>\n",
" <td>0.046895</td>\n",
" <td>-0.057979</td>\n",
" <td>0.076181</td>\n",
" <td>-0.158387</td>\n",
" <td>0.058565</td>\n",
" <td>0.210894</td>\n",
" <td>-0.010311</td>\n",
" <td>-0.137450</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2019-01-01 01:42:00</th>\n",
" <td>0.107746</td>\n",
" <td>-0.033967</td>\n",
" <td>0.036937</td>\n",
" <td>-0.066239</td>\n",
" <td>0.077228</td>\n",
" <td>-0.161417</td>\n",
" <td>0.063570</td>\n",
" <td>0.241090</td>\n",
" <td>-0.000201</td>\n",
" <td>-0.134333</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2019-01-01 01:43:00</th>\n",
" <td>0.115666</td>\n",
" <td>-0.045064</td>\n",
" <td>0.036631</td>\n",
" <td>-0.079569</td>\n",
" <td>0.080599</td>\n",
" <td>-0.158196</td>\n",
" <td>0.074238</td>\n",
" <td>0.245309</td>\n",
" <td>0.021545</td>\n",
" <td>-0.114378</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" col0 col1 col2 col3 col4 \\\n",
"time \n",
"2019-01-01 01:39:00 0.094637 -0.026028 0.009788 -0.086360 0.094658 \n",
"2019-01-01 01:40:00 0.104604 -0.039314 0.027469 -0.067474 0.087105 \n",
"2019-01-01 01:41:00 0.100678 -0.044442 0.046895 -0.057979 0.076181 \n",
"2019-01-01 01:42:00 0.107746 -0.033967 0.036937 -0.066239 0.077228 \n",
"2019-01-01 01:43:00 0.115666 -0.045064 0.036631 -0.079569 0.080599 \n",
"\n",
" col5 col6 col7 col8 col9 \n",
"time \n",
"2019-01-01 01:39:00 -0.159012 0.010536 0.185730 0.032680 -0.134111 \n",
"2019-01-01 01:40:00 -0.177999 0.022651 0.192941 0.003287 -0.139535 \n",
"2019-01-01 01:41:00 -0.158387 0.058565 0.210894 -0.010311 -0.137450 \n",
"2019-01-01 01:42:00 -0.161417 0.063570 0.241090 -0.000201 -0.134333 \n",
"2019-01-01 01:43:00 -0.158196 0.074238 0.245309 0.021545 -0.114378 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from am4894pd.utils import df_dummy_ts # used to generate some dummy data\n",
"from am4894plots.plots import plot_lines, plot_lines_grid\n",
"from am4894plots.lines.bokeh import plot_lines as plot_lines_bokeh\n",
"from am4894plots.lines.bokeh import plot_lines_grid as plot_lines_grid_bk\n",
"\n",
"# generate some dummy time series data\n",
"df = df_dummy_ts(n_cols=10, freq='1min')\n",
"print(df.shape)\n",
"display(df.head())"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[(Timestamp('2019-01-01 19:01:00'), Timestamp('2019-01-01 22:20:00'), 'lightblue'), (Timestamp('2019-01-01 22:21:00'), Timestamp('2019-01-02 00:00:00'), 'yellow')]\n"
]
}
],
"source": [
"# make shaded region\n",
"shade_regions = [\n",
" (df.index[-300:].min(), df.index[-101], 'lightblue'),\n",
" (df.index[-100:].min(), df.index.max(), 'yellow')\n",
"]\n",
"print(shade_regions)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"subplot_titles = ['col0 & col1', 'col2', 'col3']"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"plot_cols = [['col0','col1'], 'col2', 'col3']"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# plot each time series on single plot as a line\n",
"plot_lines_grid(\n",
" df, plot_cols, subplot_titles=subplot_titles, return_p=False, show_p=False, out_path='dev/dev.html', h_each=200, \n",
" w=1200, legend=False, yaxes_visible=False, shade_regions=shade_regions, text_position='bottom right', \n",
" xaxes_visible=False\n",
")"
]
}
],
"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.8.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit c40c165

Please sign in to comment.