Last active
October 31, 2018 23:05
-
-
Save johncant/d076a8e3824a6c66031281a49c960601 to your computer and use it in GitHub Desktop.
Broken Holoviews example 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# This notebook reproduces a bug in Holoviews\n", | |
"\n", | |
"Unable to alter range of VLine or empty overlay or any combination" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd\n", | |
"import numpy as np\n", | |
"%matplotlib inline" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import holoviews as hv\n", | |
"from bokeh.io import output_notebook\n", | |
"import param\n", | |
"import parambokeh\n", | |
"from holoviews.streams import Stream, Pipe, ParamValues, Tap, PointerX\n", | |
"\n", | |
"hv.notebook_extension('bokeh')\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"x = np.linspace(-2, 2, 100)\n", | |
"x2 = x**2\n", | |
"x3 = x**3\n", | |
"x4 = x**4" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Show the data using a library that isn't the \"system under test\"\n", | |
"df = pd.DataFrame({\"x\": x, \"x2\": x2, \"x3\": x3, \"x4\": x4})\n", | |
"df.plot(x='x')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"df1 = df.set_index('x').stack().reset_index()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"df1 = df1.rename(columns={\"level_0\": \"x\", \"level_1\": \"w\", 0: \"y\"})" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"overlay = hv.Table(df1).to(hv.Curve, 'x', 'y', groupby='w').overlay()\n", | |
"overlay" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Setting range on hv.Overlay works\n", | |
"\n", | |
"overlay.redim.range(x=(-1, 1))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"empty_overlay = hv.Table(df1[:0]).to(hv.Curve, 'x', 'y', groupby='w').overlay()\n", | |
"empty_overlay" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Setting range on an empty NdOverlay is broken\n", | |
"\n", | |
"empty_overlay.redim.range(x=(-1,1)).range('x')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Setting range on a VLine is broken\n", | |
"\n", | |
"hv.VLine(x=1.0).redim.range(x=(-1,1))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Setting range on (empty NdOverlay)*VLine broken\n", | |
"(hv.VLine(x=1.0)*empty_overlay).redim.range(x=(-1,1))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Setting range on an empty Curve is fine\n", | |
"hv.Curve([]).redim.range(x=(-1, 1))" | |
] | |
} | |
], | |
"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.6.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment