├── requirements.txt ├── test_data.pkl ├── prettyplots.mplstyle ├── README.md └── prettyplots.ipynb /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | ipywidgets -------------------------------------------------------------------------------- /test_data.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yobibyte/prettyplots/HEAD/test_data.pkl -------------------------------------------------------------------------------- /prettyplots.mplstyle: -------------------------------------------------------------------------------- 1 | figure.titlesize:20 2 | figure.figsize:7.0,4.0 3 | figure.dpi:200 4 | xtick.labelsize:12 5 | ytick.labelsize:12 6 | lines.linewidth:3.0 7 | axes.labelsize:15 8 | legend.fontsize:15 9 | axes.grid:False 10 | image.cmap:Accent 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # prettyplots 2 | 3 | Design your own matplotlib stylefile interactively 4 | 5 | Tired of playing with font sizes and other matplotlib parameters every time you start a new project or write a new plotting function? 6 | Want all you plots have the same style? 7 | Use [matplotlib configuration files](https://matplotlib.org/devdocs/tutorials/introductory/customizing.html)! 8 | 9 | Great! But how do I set them up? 10 | Use this repo! 11 | Start a notebook and play with the parameters, save them into a file and use it in all of your future projects! 12 | Super simple! 13 | 14 | ### How to use? 15 | 16 | Simple, start a notebook and follow the instructions. 17 | You will get a 'prettyplots.mplstyle' as a result. 18 | 19 | Add this to your code to use the stylefile: 20 | ``` 21 | plt.style.use('./prettyplots.mplstyle') 22 | ``` 23 | 24 | ### You can try this remotely using Binder 25 | 26 | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/epifanio/prettyplots/master?filepath=prettyplots.ipynb) 27 | -------------------------------------------------------------------------------- /prettyplots.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "aquatic-principle", 6 | "metadata": {}, 7 | "source": [ 8 | "# Prettyplots: design your own plots in the interactive mode" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "industrial-casino", 14 | "metadata": {}, 15 | "source": [ 16 | "### Load the libraries and mock data" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 1, 22 | "id": "substantial-underwear", 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "import pickle\n", 27 | "import numpy \n", 28 | "from matplotlib import pyplot as plt\n", 29 | "import matplotlib as mpl\n", 30 | "\n", 31 | "import numpy as np\n", 32 | "from ipywidgets import interact\n", 33 | "import ipywidgets as widgets\n", 34 | "\n", 35 | "with open('test_data.pkl', 'rb') as f:\n", 36 | " plot_data = pickle.load(f)\n", 37 | " \n", 38 | "config = {}" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "id": "collectible-guest", 44 | "metadata": {}, 45 | "source": [ 46 | "### Play with the parameters to get the look you like" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 2, 52 | "id": "spanish-designer", 53 | "metadata": { 54 | "scrolled": false 55 | }, 56 | "outputs": [ 57 | { 58 | "data": { 59 | "application/vnd.jupyter.widget-view+json": { 60 | "model_id": "88035634478045189a2df9ddc8e27e1b", 61 | "version_major": 2, 62 | "version_minor": 0 63 | }, 64 | "text/plain": [ 65 | "interactive(children=(Text(value='Performance curves', description='plot_title'), Text(value='Update steps', d…" 66 | ] 67 | }, 68 | "metadata": {}, 69 | "output_type": "display_data" 70 | } 71 | ], 72 | "source": [ 73 | "def get_config(plot_title,\n", 74 | " xlabel,\n", 75 | " ylabel,\n", 76 | " tick_fontsize=12,\n", 77 | " label_fontsize=15,\n", 78 | " legend_fontsize=15,\n", 79 | " suptitle_fontsize=20,\n", 80 | " colormap='Accent',\n", 81 | " linewidth=3, \n", 82 | " grid=False,\n", 83 | " dpi=200,\n", 84 | " figure_width=7,\n", 85 | " figure_height=4,\n", 86 | " shade_alpha=0.5,\n", 87 | " ):\n", 88 | " global config\n", 89 | " config = {\n", 90 | " \"figure.titlesize\": suptitle_fontsize,\n", 91 | " \"figure.figsize\": (float(figure_width), float(figure_height)),\n", 92 | " \"figure.dpi\": dpi,\n", 93 | " \"xtick.labelsize\": tick_fontsize,\n", 94 | " \"ytick.labelsize\": tick_fontsize,\n", 95 | " \"lines.linewidth\": linewidth,\n", 96 | " \"axes.labelsize\": label_fontsize,\n", 97 | " \"legend.fontsize\": legend_fontsize,\n", 98 | " \"axes.grid\": grid,\n", 99 | " \"image.cmap\": colormap\n", 100 | " \n", 101 | " }\n", 102 | " for k,v in config.items():\n", 103 | " mpl.rcParams[k] = v\n", 104 | " \n", 105 | " cmap = mpl.cm.get_cmap(colormap)\n", 106 | " n_curves = len(plot_data)\n", 107 | " for ctr, (k,v) in enumerate(plot_data.items()):\n", 108 | " mean = v\n", 109 | " sem = np.random.random(size=len(mean))*10 + 50\n", 110 | " if k == 'LSTM':\n", 111 | " sem=0\n", 112 | " ccolor = cmap(ctr/n_curves)\n", 113 | " plt.plot(mean, label=k, linewidth=linewidth, color=ccolor)\n", 114 | " plt.fill_between(range(len(mean)), mean - sem, mean + sem, alpha=shade_alpha, color=ccolor)\n", 115 | " plt.legend(fontsize=legend_fontsize)\n", 116 | " plt.xticks(fontsize=tick_fontsize)\n", 117 | " plt.yticks(fontsize=tick_fontsize)\n", 118 | " plt.suptitle(plot_title);\n", 119 | " plt.xlabel(xlabel);\n", 120 | " plt.ylabel(ylabel);\n", 121 | " \n", 122 | "\n", 123 | "interact(get_config,\n", 124 | " plot_title=\"Performance curves\",\n", 125 | " xlabel='Update steps',\n", 126 | " ylabel='Mean reward (+/- sem)',\n", 127 | " linewidth=(0.0, 10.0, 1.), \n", 128 | " tick_fontsize=(5, 20, 1),\n", 129 | " label_fontsize=(5, 20, 1),\n", 130 | " suptitle_fontsize=(5, 20, 1),\n", 131 | " legend_fontsize=(5, 20, 1),\n", 132 | " figure_width=(1, 20, 1),\n", 133 | " figure_height=(1,20, 1),\n", 134 | " dpi=(50, 200, 10),\n", 135 | " grid=False,\n", 136 | " shade_alpha=(0.0, 1.0, 0.1),\n", 137 | " colormap=mpl.pyplot.colormaps()\n", 138 | " );" 139 | ] 140 | }, 141 | { 142 | "cell_type": "markdown", 143 | "id": "boxed-manufacturer", 144 | "metadata": {}, 145 | "source": [ 146 | "### Save the config" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 3, 152 | "id": "ongoing-wiring", 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "with open('prettyplots.mplstyle', 'w') as f:\n", 157 | " for k,v in config.items():\n", 158 | " if isinstance(v, tuple):\n", 159 | " v = ','.join(map(str, v))\n", 160 | " f.write(f'{k}:{v}\\n')" 161 | ] 162 | }, 163 | { 164 | "cell_type": "markdown", 165 | "id": "arbitrary-formula", 166 | "metadata": {}, 167 | "source": [ 168 | "### To use your config, add this line after matplotlib import\n", 169 | "\n", 170 | "```\n", 171 | "plt.style.use('./prettyplots.mplstyle') # change the path as needed\n", 172 | "```" 173 | ] 174 | } 175 | ], 176 | "metadata": { 177 | "kernelspec": { 178 | "display_name": "Python 3", 179 | "language": "python", 180 | "name": "python3" 181 | }, 182 | "language_info": { 183 | "codemirror_mode": { 184 | "name": "ipython", 185 | "version": 3 186 | }, 187 | "file_extension": ".py", 188 | "mimetype": "text/x-python", 189 | "name": "python", 190 | "nbconvert_exporter": "python", 191 | "pygments_lexer": "ipython3", 192 | "version": "3.8.5" 193 | } 194 | }, 195 | "nbformat": 4, 196 | "nbformat_minor": 5 197 | } 198 | --------------------------------------------------------------------------------