Skip to content

Commit

Permalink
Add very basic example notebook.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Oct 19, 2023
1 parent c373ca5 commit 8b4e39f
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Viewers
This package contains two experimental Plotly-powered viewers which can be used with glue-jupyter - a
scatter viewer and a histogram viewer. More viewers to come in the future!

`This notebook <https://github.com/glue-viz/glue-plotly/blob/main/doc/PlotlyViewerExample.ipynb>`_ demonstrates
basic usage of the these viewers, such as importing and viewer creation.


=================
Package Structure
Expand Down
96 changes: 96 additions & 0 deletions doc/PlotlyViewerExample.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "75a31f1b-a32a-42ba-a016-f324faa9f3a7",
"metadata": {},
"outputs": [],
"source": [
"from glue.core import Data\n",
"from glue_jupyter import jglue\n",
"from glue_plotly.viewers.histogram.viewer import PlotlyHistogramView\n",
"from glue_plotly.viewers.scatter.viewer import PlotlyScatterView"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0746adc6-dbe1-4f85-8690-da24458667c0",
"metadata": {},
"outputs": [],
"source": [
"app = jglue()\n",
"session = app.session\n",
"dc = app.session.data_collection"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "95d749da-73c8-432a-9a23-85d37e1b6fb5",
"metadata": {},
"outputs": [],
"source": [
"from random import randint\n",
"x = [randint(0, 100) for _ in range(100)]\n",
"y = [randint(300, 400) for _ in range(100)]\n",
"data = Data(label='data', x=x, y=y)\n",
"dc.append(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cf42768e-6d31-4375-90ee-facd8d19800a",
"metadata": {},
"outputs": [],
"source": [
"viewer = app.new_data_viewer(PlotlyScatterView, data=data)\n",
"layer = viewer.layers[0]\n",
"layer.state.color = \"#ff0000\"\n",
"layer.state.size = 4"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e66be74-929f-4cfa-910c-9d3b65b4ac91",
"metadata": {},
"outputs": [],
"source": [
"viewer = app.new_data_viewer(PlotlyHistogramView, data=data)\n",
"layer = viewer.layers[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f9d9ffe-ec2e-4d7f-aa8b-8b2a7524b9c2",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 8b4e39f

Please sign in to comment.