{ "cells": [ { "cell_type": "code", "execution_count": 43, "id": "4a015e87-cf20-47b0-b271-a9dc1c38f2b3", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ], "text/plain": [ "alt.LayerChart(...)" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import altair as alt\n", "from vega_datasets import data\n", "\n", "source = data.stocks()\n", "source = source[source[\"date\"] > \"2005-01-01\"]\n", "\n", "lines = (\n", " alt.Chart(source)\n", " .mark_line()\n", " .encode(x=\"date\", y=\"price\", color=\"symbol\")\n", ")\n", "\n", "xrule = (\n", " alt.Chart()\n", " .mark_rule(color=\"black\", strokeWidth=1)\n", " .encode(x=alt.datum(alt.DateTime(year=2007, month=\"June\")))\n", ")\n", "\n", "label = (\n", " alt.Chart()\n", " .mark_text(color=\"black\", dx=-45, dy=-130)\n", " .encode(\n", " x=alt.datum(alt.DateTime(year=2007, month=\"June\")),\n", " text=alt.datum(\"iPhone Released\"),\n", " )\n", ")\n", "\n", "xrule2 = (\n", " alt.Chart()\n", " .mark_text(color=\"black\", dx=45, dy=60)\n", " .encode(x=alt.datum(alt.DateTime(year=2008, month=\"November\")),\n", " text=alt.datum(\"2008 Financial Crisis\"),\n", " )\n", "\n", ")\n", "\n", "label2 = (\n", " alt.Chart()\n", " .mark_rect(color=\"#cccccc33\")\n", " .encode(\n", " x=alt.datum(alt.DateTime(year=2008, month=\"January\")),\n", " x2=alt.datum(alt.DateTime(year=2009, month=\"January\")),\n", " text=alt.datum(\"2008 Financial Crisis\"),\n", " )\n", ")\n", "\n", "\n", "lines + label + xrule + xrule2 + label2" ] }, { "cell_type": "code", "execution_count": 53, "id": "44096965-f500-4ebf-81c5-c1e8df9d4ea1", "metadata": {}, "outputs": [], "source": [ "import math\n", "import polars as pl" ] }, { "cell_type": "code", "execution_count": 58, "id": "f652c1e0-ed86-45cd-b299-4ab662f2437d", "metadata": {}, "outputs": [], "source": [ "rows = []\n", "for pt in range(100):\n", " rows.append({\"percentage\": pt, \"theta\":pt / 100 * 2 * math.pi, \"area\": (pt / 100 * 100**2) / (100**2)})\n", "area_df = pl.DataFrame(rows)" ] }, { "cell_type": "code", "execution_count": 59, "id": "813f6626-9ff4-4d9f-ad60-6a2bf508490a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "" ], "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alt.Chart(area_df).mark_point().encode(x=\"percentage\", y=\"area\")" ] }, { "cell_type": "code", "execution_count": null, "id": "abf756b4-3ccd-4ea3-972b-ac36926a39b3", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "b4c75d21-2a82-4326-87b0-8f4b788a3d38", "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.10.15" } }, "nbformat": 4, "nbformat_minor": 5 }