{ "cells": [ { "cell_type": "markdown", "id": "164c2e63-9297-42a3-986c-b425ad43b329", "metadata": {}, "source": [ "# New Scale Transformations: `log2` and `symlog`" ] }, { "cell_type": "code", "execution_count": 1, "id": "e0ff2eb4-9550-41fb-9f6c-04ca30b7d7ea", "metadata": {}, "outputs": [], "source": [ "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "b05b5aa0-7a28-40f5-bacc-281a4520d77f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "d68a87df-c123-46aa-a6de-82f0e38b8236", "metadata": {}, "outputs": [], "source": [ "def get_data(n):\n", " import numpy as np\n", " import pandas as pd\n", "\n", " x = np.arange(-n, n + 1).astype(float)\n", " y = np.where(x >= 0, np.where(x == 0, x, np.power(np.e, x)), -np.power(np.e, -x))\n", "\n", " return pd.DataFrame({'x': x, 'y': y})" ] }, { "cell_type": "code", "execution_count": 4, "id": "db6ca357-1bb3-42ce-bfee-0fb1e3a1b202", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
xy
166.0403.428793
177.01096.633158
188.02980.957987
199.08103.083928
2010.022026.465795
\n", "
" ], "text/plain": [ " x y\n", "16 6.0 403.428793\n", "17 7.0 1096.633158\n", "18 8.0 2980.957987\n", "19 9.0 8103.083928\n", "20 10.0 22026.465795" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = get_data(10)\n", "df.tail()" ] }, { "cell_type": "code", "execution_count": 5, "id": "dc3668ad-045d-421f-9663-05c75ecb5f2a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = ggplot(df, aes('x', 'y')) + geom_point()\n", "\n", "gggrid([\n", " p + ggtitle(\"Default\"),\n", " p + scale_y_continuous(trans='symlog') + ggtitle(\"trans='symlog'\"),\n", " p + scale_y_continuous(trans='log10') + ggtitle(\"trans='log10'\"),\n", " p + scale_y_continuous(trans='log2') + ggtitle(\"trans='log2'\"),\n", "], ncol=2)" ] } ], "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.18" } }, "nbformat": 4, "nbformat_minor": 5 }