diff --git a/README.rst b/README.rst index 2c81c45..3e91d13 100644 --- a/README.rst +++ b/README.rst @@ -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 `_ demonstrates +basic usage of the these viewers, such as importing and viewer creation. + ================= Package Structure diff --git a/doc/PlotlyViewerExample.ipynb b/doc/PlotlyViewerExample.ipynb new file mode 100644 index 0000000..c43cba1 --- /dev/null +++ b/doc/PlotlyViewerExample.ipynb @@ -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 +}