{ "cells": [ { "cell_type": "markdown", "id": "7652c120-54fa-4c12-bbb2-8dd7a8aeb9b9", "metadata": {}, "source": [ "# Unemployment in the US since 1967" ] }, { "cell_type": "code", "execution_count": 1, "id": "7b8e17a3-5669-4609-b8eb-22fe78fc96fc", "metadata": { "execution": { "iopub.execute_input": "2025-07-17T17:08:29.628584Z", "iopub.status.busy": "2025-07-17T17:08:29.628504Z", "iopub.status.idle": "2025-07-17T17:08:29.631301Z", "shell.execute_reply": "2025-07-17T17:08:29.631119Z" } }, "outputs": [], "source": [ "from datetime import datetime\n", "\n", "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "e5a21782-05b6-4072-83dd-142980bc0916", "metadata": { "execution": { "iopub.execute_input": "2025-07-17T17:08:29.632418Z", "iopub.status.busy": "2025-07-17T17:08:29.632346Z", "iopub.status.idle": "2025-07-17T17:08:29.634099Z", "shell.execute_reply": "2025-07-17T17:08:29.633937Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "672f2175-e227-4950-b444-946211dd557e", "metadata": { "execution": { "iopub.execute_input": "2025-07-17T17:08:29.635071Z", "iopub.status.busy": "2025-07-17T17:08:29.635002Z", "iopub.status.idle": "2025-07-17T17:08:30.807310Z", "shell.execute_reply": "2025-07-17T17:08:30.806986Z" } }, "outputs": [], "source": [ "presidential_df = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/presidential.csv\", parse_dates=[\"start\", \"end\"])\n", "economics_df = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/economics.csv\", parse_dates=[\"date\"])" ] }, { "cell_type": "code", "execution_count": 4, "id": "50a763a1-3244-4e3e-9743-dc9a0674914d", "metadata": { "execution": { "iopub.execute_input": "2025-07-17T17:08:30.808725Z", "iopub.status.busy": "2025-07-17T17:08:30.808648Z", "iopub.status.idle": "2025-07-17T17:08:30.847043Z", "shell.execute_reply": "2025-07-17T17:08:30.846579Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "breaks = [2.5, 5, 10]\n", "\n", "ggplot() + \\\n", " geom_band(aes(xmin=\"start\", xmax=\"end\", fill=\"party\"), data=presidential_df, \\\n", " size=0, alpha=.4) + \\\n", " geom_label(aes(\"start\", label=\"name\", color=\"party\"), \n", " data=presidential_df, \n", " y=4000, alpha=0.6, \n", " angle=90,\n", " vjust=1, show_legend=False) + \\\n", " geom_line(aes(\"date\", \"unemploy\"), data=economics_df) + \\\n", " scale_y_continuous(\"Unemployment (x\\(10^3\\))\", trans='log10', \\\n", " breaks=[b*10**3 for b in breaks], labels=[str(b) for b in breaks]) + \\\n", " scale_fill_discrete(name=\"\") + \\\n", " coord_cartesian(xlim=[datetime(1966, 1, 1), datetime(2016, 1, 1)]) + \\\n", " xlab(\"Year\") + \\\n", " guides(fill=guide_legend(override_aes={'alpha': 0.4, 'color': 'paper'})) + \\\n", " ggsize(1000, 400) + \\\n", " ggtitle(\"Unemployment in the US\", \"1967 to 2015\") + \\\n", " theme(legend_position='top', plot_title=element_text(size=18, face='bold'))" ] } ], "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.10.13" } }, "nbformat": 4, "nbformat_minor": 5 }