{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f2a9d691", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from lets_plot import *\n", "\n", "def dump_plot(plot, display=None):\n", " import json\n", "\n", " try:\n", " import clipboard\n", " except:\n", " clipboard = None\n", " \n", " from lets_plot._type_utils import standardize_dict\n", " \n", " plot_dict = standardize_dict(plot.as_dict())\n", " plot_json = json.dumps(plot_dict, indent=2)\n", " \n", " if clipboard:\n", " clipboard.copy('')\n", " clipboard.copy(str(plot_json))\n", " else:\n", " if display is None:\n", " display = True\n", " \n", " if display:\n", " print(plot_json)\n", "\n", " return plot\n", " " ] }, { "cell_type": "code", "execution_count": 2, "id": "632b5308", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "57d71b80", "metadata": {}, "outputs": [], "source": [ "plot_data = pd.DataFrame.from_records([\n", " (\"pet\", \"cat\", 5, \"carnivore\"),\n", " (\"pet\", \"dog\", 10, \"carnivore\"),\n", " (\"pet\", \"rabbit\", 2, \"herbivore\"),\n", " (\"pet\", \"hamster\", 1, \"herbivore\"),\n", "\n", " (\"farm_animal\", \"cow\", 500, \"herbivore\"),\n", " (\"farm_animal\", \"pig\", 100, \"carnivore\"),\n", " (\"farm_animal\", \"horse\", 700, \"herbivore\"),\n", "])\n", "plot_data.columns = (\"animal_type\", \"animal\", \"weight\", \"diet\")\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "c2b38e6c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "