{ "cells": [ { "cell_type": "markdown", "id": "a1b2c3d4-0001-0001-0001-000000000001", "metadata": {}, "source": [ "# Issue #1489: scale_color_gradient(): guide='legend' should render a colorbar" ] }, { "cell_type": "code", "execution_count": null, "id": "a1b2c3d4-0002-0002-0002-000000000002", "metadata": {}, "outputs": [], "source": [ "from lets_plot import *\n", "\n", "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "id": "a1b2c3d4-0003-0003-0003-000000000003", "metadata": {}, "source": [ "## Reproduction - guide='legend' on a continuous scale\n", "\n", "A continuous color scale with `guide='legend'` should render discrete legend keys instead of a colorbar." ] }, { "cell_type": "code", "execution_count": null, "id": "a1b2c3d4-0004-0004-0004-000000000004", "metadata": {}, "outputs": [], "source": [ "data = {'x': [1, 2, 3, 4, 5], 'y': [2, 4, 1, 5, 3], 'v': [10, 20, 30, 40, 50]}\n", "\n", "(\n", " ggplot(data, aes('x', 'y', color='v'))\n", " + geom_point(size=5)\n", " + scale_color_gradient(low='blue', high='red', guide='legend')\n", " + ggtitle(\"guide='legend' on a continuous color scale - should show legend keys\")\n", ")" ] }, { "cell_type": "markdown", "id": "a1b2c3d4-0005-0005-0005-000000000005", "metadata": {}, "source": [ "## Comparison - default behavior still shows a colorbar\n", "\n", "Without an explicit guide, the continuous color scale should keep its default colorbar." ] }, { "cell_type": "code", "execution_count": null, "id": "a1b2c3d4-0006-0006-0006-000000000006", "metadata": {}, "outputs": [], "source": [ "(\n", " ggplot(data, aes('x', 'y', color='v'))\n", " + geom_point(size=5)\n", " + scale_color_gradient(low='blue', high='red')\n", " + ggtitle('No guide parameter - the default colorbar should still appear')\n", ")" ] }, { "cell_type": "markdown", "id": "a1b2c3d4-0007-0007-0007-000000000007", "metadata": {}, "source": [ "## Regression test - guide='colorbar' still works\n", "\n", "An explicit colorbar guide should continue to render as a colorbar." ] }, { "cell_type": "code", "execution_count": null, "id": "a1b2c3d4-0008-0008-0008-000000000008", "metadata": {}, "outputs": [], "source": [ "(\n", " ggplot(data, aes('x', 'y', color='v'))\n", " + geom_point(size=5)\n", " + scale_color_gradient(low='blue', high='red', guide='colorbar')\n", " + ggtitle(\"Explicit guide='colorbar' - should still show a colorbar\")\n", ")" ] }, { "cell_type": "markdown", "id": "a1b2c3d4-0009-0009-0009-000000000009", "metadata": {}, "source": [ "## Regression test - guide='none' still works\n", "\n", "Suppressing the guide should continue to hide it completely." ] }, { "cell_type": "code", "execution_count": null, "id": "a1b2c3d4-0010-0010-0010-000000000010", "metadata": {}, "outputs": [], "source": [ "(\n", " ggplot(data, aes('x', 'y', color='v'))\n", " + geom_point(size=5)\n", " + scale_color_gradient(low='blue', high='red', guide='none')\n", " + ggtitle(\"guide='none' - no guide should appear\")\n", ")" ] }, { "cell_type": "markdown", "id": "a1b2c3d4-0011-0011-0011-000000000011", "metadata": {}, "source": [ "## Regression test - scale_fill_gradient with guide='legend'\n", "\n", "The same guide behavior should apply to continuous fill scales." ] }, { "cell_type": "code", "execution_count": null, "id": "a1b2c3d4-0012-0012-0012-000000000012", "metadata": {}, "outputs": [], "source": [ "tile_data = {\n", " 'x': [1, 2, 3, 1, 2, 3],\n", " 'y': [1, 1, 1, 2, 2, 2],\n", " 'v': [10, 20, 30, 40, 50, 60]\n", "}\n", "\n", "(\n", " ggplot(tile_data, aes('x', 'y', fill='v'))\n", " + geom_tile()\n", " + scale_fill_gradient(low='white', high='darkblue', guide='legend')\n", " + ggtitle(\"scale_fill_gradient guide='legend' - fill scale should respect guide='legend'\")\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.13.13" } }, "nbformat": 4, "nbformat_minor": 5 }