{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## `Free` scales on faceted plot" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
miles per gallonnumber of cylindersengine displacement (cu. inches)engine horsepowervehicle weight (lbs.)time to accelerate (sec.)model yearorigin of carvehicle name
018.08307.0130350412.070USchevrolet chevelle malibu
115.08350.0165369311.570USbuick skylark 320
218.08318.0150343611.070USplymouth satellite
\n", "
" ], "text/plain": [ " miles per gallon number of cylinders engine displacement (cu. inches) \\\n", "0 18.0 8 307.0 \n", "1 15.0 8 350.0 \n", "2 18.0 8 318.0 \n", "\n", " engine horsepower vehicle weight (lbs.) time to accelerate (sec.) \\\n", "0 130 3504 12.0 \n", "1 165 3693 11.5 \n", "2 150 3436 11.0 \n", "\n", " model year origin of car vehicle name \n", "0 70 US chevrolet chevelle malibu \n", "1 70 US buick skylark 320 \n", "2 70 US plymouth satellite " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg2.csv')\n", "data.head(3)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = (ggplot(data, aes(x=\"engine horsepower\", y=\"engine displacement (cu. inches)\")) + \n", " geom_point(aes(color=\"origin of car\")) + theme_grey())\n", "p + ggsize(800, 350)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Faceted plot" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "fp = p + ggsize(800, 500)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### `facet_grid()` with `fixed` scales (the default)\n", "\n", "Scales are constant across all panels." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fp + facet_grid(y='origin of car')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### `facet_grid()` with `free` Y-scales" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fp + facet_grid(y='origin of car', scales='free_y')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### `facet_wrap()` with `fixed` scales (the default)\n", "\n", "Scales are constant across all panels." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fp + facet_wrap(facets=\"number of cylinders\", order=1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### `facet_wrap()` with `free` scales along both axis" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fp + facet_wrap(facets=\"number of cylinders\", order=1, scales='free')" ] } ], "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 }