{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Getting started\n",
"\n",
"*Please see the **Guides** tab to find more thorough examples.*\n",
"\n",
"---\n",
"\n",
"After installing `cowpatch`, you can combine your plot objects together in different arrangements with different combinations of `cow.patch` and `cow.layout`.\n",
"\n",
"## Creating plots to combine\n",
"\n",
"Before we start arranging, we load common `python` packages we use to create some basic plots."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2022-03-04T05:43:01.163469Z",
"start_time": "2022-03-04T05:42:58.916131Z"
}
},
"outputs": [],
"source": [
"import cowpatch as cow"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2022-03-04T05:43:01.299774Z",
"start_time": "2022-03-04T05:43:01.165793Z"
}
},
"outputs": [],
"source": [
"import plotnine as p9\n",
"import plotnine.data as p9_data\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2022-03-04T05:43:01.313241Z",
"start_time": "2022-03-04T05:43:01.301650Z"
}
},
"outputs": [],
"source": [
"# creation of some some ggplot objects\n",
"g0 = p9.ggplot(p9_data.mpg) +\\\n",
" p9.geom_bar(p9.aes(x=\"hwy\")) +\\\n",
" p9.labs(title = 'Plot 0')\n",
"\n",
"g1 = p9.ggplot(p9_data.mpg) +\\\n",
" p9.geom_point(p9.aes(x=\"hwy\", y = \"displ\")) +\\\n",
" p9.labs(title = 'Plot 1')\n",
"\n",
"g2 = p9.ggplot(p9_data.mpg) +\\\n",
" p9.geom_point(p9.aes(x=\"hwy\", y = \"displ\", color=\"class\")) +\\\n",
" p9.labs(title = 'Plot 2')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Arranging plots\n",
"\n",
"To arrange these plots into a single patchwork, we first group the plots together with `cow.patch` and define a `cow.layout` that will define the layout of the plots."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2022-03-04T05:43:01.319027Z",
"start_time": "2022-03-04T05:43:01.315859Z"
}
},
"outputs": [],
"source": [
"vis_patch = cow.patch(g0,g1,g2)\n",
"vis_patch += cow.layout(design = np.array([[0,0,0,1,1,1], \n",
" [0,0,0,2,2,2],\n",
" [0,0,0,2,2,2]]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Displaying the image\n",
"\n",
"Finally, we can display the arrangement using the `.show` method[^1]. To save the arrangement on can use the `.save` method.\n",
"\n",
"\n",
"[^1]: The `.show` method works slightly different inside `jupyter notebooks` versus from the command line. Inside `jupyter notebook` the image is displayed as an `svg` object. From the command line we present a `png` representation of the object using `matplotlib.pyplot`'s standard graphic presenter. **Note** the command line approach doesn't update the image when the sizing of the display is changed(."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2022-03-04T05:43:04.884265Z",
"start_time": "2022-03-04T05:43:01.320263Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/benjaminleroy/Documents/CMU/research/cowpatch/src/cowpatch/svg_utils.py:438: CowpatchWarning: Showing 11 x 7 inch image.\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"vis_patch.show(width = 11, height = 7)"
]
}
],
"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.12"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}