{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "defacae4-2a0b-4a9f-8b57-01bb469350c5", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "from datetime import datetime\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "d33a1c37-0dfe-4a4f-8fd2-76eff43e35eb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "id": "45a22b24-da0c-449b-a851-efb9b70de14c", "metadata": {}, "source": [ "# Multiline axis labels" ] }, { "cell_type": "code", "execution_count": 3, "id": "1d6c6d8e-66d6-472c-b817-d55441fd7fd6", "metadata": {}, "outputs": [], "source": [ "data = {\n", " \"x\": [\"Single\", \"2\\nlines\", \"Multiline\\nlabel\", \"Label\\n#4\\n(of 4)\"],\n", " \"y\": [500, 1000, 500, 0],\n", " \"z\": [\"a\", \"b\", \"c\", \"d\"]\n", "}" ] }, { "cell_type": "code", "execution_count": 4, "id": "46a9ea97-abcf-4cb9-9553-f7732dcbf686", "metadata": {}, "outputs": [], "source": [ "justifications = [1.0, 0.5, 0.0]\n", "angles=[0, 30, 90]" ] }, { "cell_type": "code", "execution_count": 5, "id": "776fd525-2402-480d-889e-40908bd6ee14", "metadata": {}, "outputs": [], "source": [ "def create_plot(position, angle, hjust, vjust):\n", " if position == 'top' or position == 'bottom':\n", " theme_element = theme(axis_text_x=element_text(angle=angle, hjust=hjust, vjust=vjust), axis_title=\"blank\") + \\\n", " scale_x_discrete(position = f'{position}')\n", " x_data = \"x\"\n", " else:\n", " theme_element = theme(axis_text_y=element_text(angle=angle, hjust=hjust, vjust=vjust), axis_title=\"blank\") + \\\n", " scale_y_discrete(position = f'{position}') \n", " x_data = \"z\"\n", " return (\n", " ggplot(data) + \n", " geom_point(aes(x=x_data, y=\"y\"), size=5) + \n", " theme_classic() + \n", " ggtitle(f\"h{hjust}, v{vjust}\") +\n", " theme_element\n", " )\n", "\n", " \n", "def generate_all_plots(position, angle):\n", " return [create_plot(position=position, angle=angle, hjust=hjust, vjust=vjust)\n", " for hjust in justifications\n", " for vjust in justifications]\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "b4687e37-7b06-4319-908d-57161734dac4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "