{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "111dc129-dc78-4b1e-b993-af69824b2d57", "metadata": {}, "outputs": [], "source": [ "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "1a3e1ab5-2f1c-4d92-8213-1b2cd6891666", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "c52e31ea-3f5a-4a27-941b-d0c5446a6b8f", "metadata": {}, "outputs": [], "source": [ "def_min_exp, def_max_exp = -7, 7\n", "values = [3.14 * 10**d for d in range(def_min_exp, def_max_exp)]" ] }, { "cell_type": "code", "execution_count": 4, "id": "a7d265ff-5a6b-4b5c-bd49-6091ce559732", "metadata": {}, "outputs": [], "source": [ "def plot(f=None):\n", " t = layer_tooltips().line(\"@v\")\n", " if f is not None:\n", " t = t.format(\"@v\", f)\n", " return ggplot({'v': values}, aes(y='v')) + \\\n", " geom_point(x=0, tooltips=t) + \\\n", " geom_text(aes(label='v'), x=1, label_format=f) + \\\n", " scale_x_continuous(limits=[-.5, 2]) + \\\n", " scale_y_log10(limits=[10**def_min_exp, 10**def_max_exp], format=f) + \\\n", " ggsize(400, 600) + \\\n", " ggtitle(\"Default format\" if f is None else 'format=\"{0}\"'.format(f))" ] }, { "cell_type": "markdown", "id": "dc2c7f65-8b6c-4eb7-ae4a-4a3315919e51", "metadata": {}, "source": [ "## Without `theme()`" ] }, { "cell_type": "code", "execution_count": 11, "id": "a62a3836-c0b4-49d2-8037-b8396248b315", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "(plot()+ggtb()).show()\n", "plot(\"g\").show()" ] }, { "cell_type": "markdown", "id": "5c70d2f2-48c0-4675-b9cc-ee6e411b6368", "metadata": {}, "source": [ "## With `theme(exponent_format=('pow', -2, 3))`" ] }, { "cell_type": "code", "execution_count": 6, "id": "87cc822f-60e6-423c-b19c-8ae1793470d1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "(plot() + theme(exponent_format=('pow', -2, 3))).show()\n", "(plot(\"g\") + theme(exponent_format=('pow', -2, 3))).show()" ] } ], "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.8.19" } }, "nbformat": 4, "nbformat_minor": 5 }