{ "cells": [ { "cell_type": "markdown", "id": "b0cb8f8e-adbd-4122-99ed-08ffcf793d12", "metadata": {}, "source": [ "# Combining Discrete and Continuous Layers\n", "\n", "This notebook demonstrates how to position continuous elements like background bands (`geom_band`) and annotations (`geom_text`) relative to discrete elements like bars.\n", "\n", "When positioning continuous elements, keep in mind numeric equivalents of the discrete positions: in this example `0.0` for 'Outback' through `7.0` for 'Pacer'." ] }, { "cell_type": "code", "execution_count": 1, "id": "2c9f4f70-9667-42ae-93a3-013dafab2ea9", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "010e706b-afcd-4e03-8c80-383747b69353", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "7ad25b3a-0b53-4e6c-8b2b-ce46169ec5bb", "metadata": {}, "outputs": [], "source": [ "np.random.seed(69)\n", "\n", "cars = pd.DataFrame({\n", " 'Models': ['Outback', 'Impresa', 'BRZ', 'Jetta', 'Passat', 'Matador', 'Rambler', 'Pacer'],\n", " 'Val': np.random.uniform(0,100, size=8),\n", "})\n", "\n", "# Data to use in `geom_band` and `geom_text` layers\n", "cars_band = pd.DataFrame({\n", " 'Brand': ['Subaru', 'Volkswagen', 'AMC'],\n", " 'pos_minx': [-0.5, 2.5, 4.5],\n", " 'pos_maxx':[2.5, 4.5, 7.5],\n", " 'M':['#41DC8E', '#E0FFFF','#90D5FF']\n", "})" ] }, { "cell_type": "code", "execution_count": 4, "id": "189eb2df-56d8-4cae-ab2f-19c2c60e7719", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ], "text/plain": [ "