{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from lets_plot import *\n", "import numpy as np\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def f(x, y):\n", " return x * y\n", "\n", "x = np.arange(1, 11, 1)\n", "y = np.arange(1, 11, 1)\n", "X, Y = np.meshgrid(x, y)\n", "\n", "df = dict(\n", " x = X.reshape(-1),\n", " y = Y.reshape(-1),\n", " value = f(X, Y).reshape(-1)\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p1 = ggplot(df, aes('x', 'y')) + geom_tile(aes(fill = 'value'))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Basic form\n", "\n", "p1 + scale_fill_continuous(guide = \"colorbar\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p1 + scale_fill_continuous(guide = guide_colorbar())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p1 + guides(fill = guide_colorbar())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Remove guide\n", "\n", "p1 + scale_fill_continuous(guide = 'none')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p1 + guides(fill = 'none')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Control styles\n", "\n", "p1 + scale_fill_continuous(guide = guide_colorbar(barwidth = 10))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p1 + guides(fill = guide_colorbar(barwidth = 10))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p1 + scale_fill_continuous(limits = [0,20], breaks = [0, 5, 10, 15, 20], guide = guide_colorbar(nbin=5))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p2 = p1 + geom_point(aes(size = 'value'))\n", "p2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p2 + guides(size = guide_legend(nrow=3), fill = guide_colorbar(nbin = 8))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# independent guides control\n", "(\n", " p2 \n", " + scale_size(guide = guide_legend(nrow=3))\n", " + scale_fill_continuous(guide = guide_colorbar(nbin = 8)) \n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(\n", " p2 \n", " + scale_size(guide = guide_legend(nrow=3))\n", " + guides(fill = guide_colorbar(nbin = 8))\n", ")" ] } ], "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.7.10" } }, "nbformat": 4, "nbformat_minor": 4 }