{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "historic-minority", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lets_plot import *\n", "import pandas as pd\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "id": "specialized-peoples", "metadata": {}, "outputs": [], "source": [ "df = {\n", " 'x' : [1, 1, 2, 2, 1.5],\n", " 'y' : [1, 2, 1, 2, 1.5],\n", " 'text': [\"bottom-left\", \"top-left\", \"bottom-right\", \"top-right\", \"center\"]\n", "}\n", "\n", "w, h = 400, 250\n", "\n", "p = ggplot(df, aes('x', 'y')) + geom_point(size=3) + ggsize(w,h) + theme_classic() \n" ] }, { "cell_type": "code", "execution_count": 3, "id": "worth-eagle", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geom_text(aes(label = 'text'), size=8, hjust = 'inward', angle=0)" ] }, { "cell_type": "code", "execution_count": 4, "id": "optical-spokesman", "metadata": {}, "outputs": [], "source": [ "angles = [0,45,90,135,180,225,270,315]\n", "\n", "def justificationWithAngles(hjust=None, vjust=None):\n", " bunch = GGBunch()\n", " for i in range(len(angles)):\n", " angle = angles[i]\n", " \n", " row = int(i / 2)\n", " column = i % 2\n", " \n", " pp = p + geom_text(aes(label = 'text'), size=8, hjust = hjust, vjust = vjust, angle=angle) +\\\n", " ggtitle(\"Angle: \" + str(angle))\n", " \n", " bunch.add_plot(pp, column * w, row * h, w, h)\n", " \n", " return bunch.show() \n", " " ] }, { "cell_type": "code", "execution_count": 5, "id": "published-designation", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "justificationWithAngles(hjust='inward')" ] }, { "cell_type": "code", "execution_count": 6, "id": "filled-surrey", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "justificationWithAngles(hjust='outward')" ] }, { "cell_type": "code", "execution_count": 7, "id": "meaningful-wrestling", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "justificationWithAngles(vjust='inward')" ] }, { "cell_type": "code", "execution_count": 8, "id": "short-necessity", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "justificationWithAngles(vjust='outward')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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": 5 }