Skip to content

Commit

Permalink
doc: update colab notebooks, replace generator objects with Plot.plot()
Browse files Browse the repository at this point in the history
  • Loading branch information
juba committed Sep 10, 2024
1 parent 902934b commit 08c14e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 100 deletions.
20 changes: 9 additions & 11 deletions examples/interactivity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,24 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Then we load the needed modules and data and initialize a plot generator object:\n"
"Then we load the needed modules and data:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import polars as pl\n",
"from IPython.display import display\n",
"from ipywidgets import IntSlider\n",
"\n",
"from pyobsplot import Obsplot, Plot\n",
"from pyobsplot import Plot\n",
"\n",
"penguins = pl.read_csv(\n",
" \"https://github.com/juba/pyobsplot/raw/main/doc/data/penguins.csv\"\n",
")\n",
"\n",
"op = Obsplot()"
")"
]
},
{
Expand All @@ -65,7 +63,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -85,7 +83,7 @@
" }\n",
"\n",
"\n",
"plot = op(generate_plot_spec(1))"
"plot = Plot.plot(generate_plot_spec(1))"
]
},
{
Expand All @@ -98,13 +96,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def update_plot(change):\n",
" new = change[\"new\"]\n",
" plot.spec = generate_plot_spec(new / 100)\n",
" plot.spec = generate_plot_spec(new / 100) # type: ignore\n",
"\n",
"\n",
"w = IntSlider(value=100, min=0, max=100)\n",
Expand Down Expand Up @@ -146,7 +144,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.11.9"
},
"orig_nbformat": 4
},
Expand Down
92 changes: 3 additions & 89 deletions examples/introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,75 +108,6 @@
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Generator object\n",
"\n",
"Using `Plot.plot()` allows to create plots with the default settings. To go a bit further we can create a _plot generator object_ by importing the `Obsplot` class and calling it:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pyobsplot import Obsplot, Plot\n",
"\n",
"op = Obsplot()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"To produce plots with this generator object, we pass it a specification like we did with `Plot.plot()`:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"op(\n",
" {\n",
" \"color\": {\"legend\": True},\n",
" \"marginLeft\": 80,\n",
" \"marginRight\": 80,\n",
" \"x\": {\"inset\": 20},\n",
" \"grid\": True,\n",
" \"marks\": [\n",
" Plot.boxX(\n",
" penguins,\n",
" {\"x\": \"body_mass_g\", \"fill\": \"island\", \"y\": \"island\", \"fy\": \"species\"},\n",
" )\n",
" ],\n",
" }\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"A generator object allows, for example, to directly call a mark function:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"op(Plot.auto(penguins, {\"x\": \"body_mass_g\"}))"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down Expand Up @@ -226,24 +157,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Then, when creating a new plot generator object, we can specify an output `format`:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"op_jsdom = Obsplot(format=\"png\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"The plots generated with this object will be created directly as PNG images.\n"
"Then, when creating a new plot, we can specify an output `format`:\n"
]
},
{
Expand All @@ -254,7 +168,7 @@
"source": [
"ca55 = pl.read_csv(\"https://github.com/juba/pyobsplot/raw/main/doc/data/ca55-south.csv\")\n",
"\n",
"op_jsdom(\n",
"Plot.plot(\n",
" {\n",
" \"x\": {\"axis\": None},\n",
" \"y\": {\"axis\": None},\n",
Expand Down Expand Up @@ -301,7 +215,7 @@
").filter(pl.col(\"date\") > datetime(1991, 1, 1))\n",
"\n",
"\n",
"op_jsdom(\n",
"Plot.plot(\n",
" {\n",
" \"insetRight\": 10,\n",
" \"height\": 600,\n",
Expand Down

0 comments on commit 08c14e8

Please sign in to comment.