{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "82b7c886-1bde-4c5f-90c6-5555a83f8cf1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The geodata is provided by © OpenStreetMap contributors and is made available here under the Open Database License (ODbL).\n" ] } ], "source": [ "from lets_plot import *\n", "from lets_plot.geo_data import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "a380f598-83e9-4fac-98ca-478b88cb8a96", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "7ca1b790-936a-4206-a339-118d8ef01bfd", "metadata": {}, "outputs": [], "source": [ "state_gcoder = geocode_states('us-48').inc_res()\n", "state_centroids = state_gcoder.get_centroids()" ] }, { "cell_type": "code", "execution_count": 4, "id": "498b44b0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_text(aes(label='state'), data=state_centroids)" ] }, { "cell_type": "code", "execution_count": 5, "id": "0cced45a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_text(aes(label='state'), data=state_centroids, check_overlap=True)" ] }, { "cell_type": "code", "execution_count": 6, "id": "10956a9d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Rotate labels\n", "\n", "gggrid([\n", " ggplot() + geom_text(aes(label='state'), data=state_centroids, angle=45),\n", " ggplot() + geom_text(aes(label='state'), data=state_centroids, angle=45, check_overlap=True)\n", "])" ] }, { "cell_type": "code", "execution_count": 7, "id": "363a1f2b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = ggplot() + \\\n", " geom_polygon(aes(fill='state'), \n", " data=state_gcoder.get_boundaries(), \n", " show_legend=False, \n", " color='black',\n", " size=0.2) + \\\n", " scale_fill_brewer(palette=\"Pastel2\") + \\\n", " coord_map() + \\\n", " theme_void() + \\\n", " ggsize(800, 400)\n", "\n", "p + geom_label(aes(label='state'), data=state_centroids)" ] }, { "cell_type": "code", "execution_count": 8, "id": "ad03c913", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geom_label(aes(label='state'), data=state_centroids, check_overlap=True)" ] }, { "cell_type": "code", "execution_count": 9, "id": "3bb2c7f8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from lets_plot import tilesets\n", "\n", "# ToDo livemap\n", "\n", "ggplot() + \\\n", " geom_livemap(tiles=tilesets.CARTO_POSITRON_NO_LABELS) + \\\n", " geom_label(aes(label='state'), data=state_centroids, check_overlap=True) + \\\n", " theme_void()" ] } ], "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.8.18" } }, "nbformat": 4, "nbformat_minor": 5 }