Skip to content

Commit

Permalink
Split cell in Chord reference notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Feb 13, 2018
1 parent bb29ba0 commit 1c1b5b2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 36 deletions.
52 changes: 35 additions & 17 deletions examples/reference/elements/bokeh/Chord.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,22 @@
"outputs": [],
"source": [
"links = pd.DataFrame(data['links'])\n",
"print(links.head(3))\n",
"print(links.head(3))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the simplest case we can construct the ``Chord`` by passing it just the edges"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"hv.Chord(links)"
]
},
Expand All @@ -58,7 +73,24 @@
"source": [
"The plot automatically adds hover and tap support, letting us reveal the connections of each node.\n",
"\n",
"By adding additional columns of data we can increase the information shown when hovering. Additionally we can now color the nodes and edges by their index and add some labels. The ``label_index``, ``color_index`` and ``edge_color_index`` allow specifying columns to color by. "
"To add node labels and other information we can construct a ``Dataset`` with a key dimension of node indices."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nodes = hv.Dataset(pd.DataFrame(data['nodes']), 'index')\n",
"nodes.data.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Additionally we can now color the nodes and edges by their index and add some labels. The ``label_index``, ``color_index`` and ``edge_color_index`` allow specifying columns to color by."
]
},
{
Expand All @@ -69,28 +101,14 @@
"source": [
"%%opts Chord [label_index='name' color_index='index' edge_color_index='source'] \n",
"%%opts Chord (cmap='Category20' edge_cmap='Category20')\n",
"nodes = hv.Dataset(pd.DataFrame(data['nodes']).reset_index(), 'index')\n",
"hv.Chord((links, nodes)).select(value=(5, None))"
]
}
],
"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.3"
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
Expand Down
55 changes: 36 additions & 19 deletions examples/reference/elements/matplotlib/Chord.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"\n",
"If the weight values are integers, they define the number of chords to be drawn between the source and target nodes directly. If the weights are floating point values, they are normalized to a default of 500 chords, which are divided up among the edges. Any non-zero weight will be assigned at least one chord.\n",
"\n",
"The ``Chord`` element is a type of ``Graph`` element and shares the same constructor."
"The ``Chord`` element is a type of ``Graph`` element and shares the same constructor. The most basic constructor accepts a columnar dataset of the source and target nodes and an optional value. Here we supply a dataframe containing the number of dialogues between characters of the *Les Misérables* musical. The data contains ``source`` and ``target`` node indices and an associated ``value`` column:"
]
},
{
Expand All @@ -48,16 +48,47 @@
"outputs": [],
"source": [
"links = pd.DataFrame(data['links'])\n",
"print(links.head(3))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the simplest case we can construct the ``Chord`` by passing it just the edges:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"hv.Chord(links)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The plot automatically adds hover and tap support, letting us reveal the connections of each node.\n",
"\n",
"By adding additional columns of data, we can increase the information shown when hovering. Additionally we can now color the nodes and edges by their index and add some labels. The ``label_index``, ``color_index`` and ``edge_color_index`` allow specifying columns to color by. "
"To add node labels and other information we can construct a ``Dataset`` with a key dimension of node indices."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nodes = hv.Dataset(pd.DataFrame(data['nodes']), 'index')\n",
"nodes.data.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Additionally we can now color the nodes and edges by their index and add some labels. The ``label_index``, ``color_index`` and ``edge_color_index`` allow specifying columns to color by. "
]
},
{
Expand All @@ -68,28 +99,14 @@
"source": [
"%%opts Chord [label_index='name' color_index='index' edge_color_index='source'] \n",
"%%opts Chord (cmap='Category20' edge_cmap='Category20')\n",
"nodes = hv.Dataset(pd.DataFrame(data['nodes']).reset_index(), 'index')\n",
"hv.Chord((links, nodes)).select(value=(5, None))"
]
}
],
"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.3"
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 1c1b5b2

Please sign in to comment.