[
  {
    "path": ".bumpversion.cfg",
    "content": "[bumpversion]\ncurrent_version = 3.9.4\n\n[bumpversion:file:./check-matplotlib-version.py]\nsearch = __version__ == '{current_version}'\nreplace = __version__ == '{new_version}'\n\n[bumpversion:glob:./handout-*.tex]\nsearch = Matplotlib {current_version}\nreplace = Matplotlib {new_version}\n\n[bumpversion:file:./cheatsheets.tex]\nsearch = Version {current_version}\nreplace = Version {new_version}\n\n[bumpversion:file:./requirements/requirements.in]\nsearch = matplotlib=={current_version}\nreplace = matplotlib=={new_version}\n"
  },
  {
    "path": ".circleci/config.yml",
    "content": "version: 2.1\n\norbs:\n  python: circleci/python@0.2.1\n\njobs:\n  build_docs:\n    docker:\n      - image: cimg/python:3.9\n    steps:\n      - checkout\n      - run:\n          command: echo \"placeholder\"\n\nworkflows:\n  main:\n    jobs:\n      - build_docs\n"
  },
  {
    "path": ".flake8",
    "content": "[flake8]\nignore = E20,E22,E501,E701,F401,W\n\n[pep8]\nselect = E12,E231,E241,E251,E26,E30\n"
  },
  {
    "path": ".github/dependabot.yml",
    "content": "---\nversion: 2\nupdates:\n  - package-ecosystem: \"github-actions\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n    groups:\n      actions:\n        patterns:\n          - \"*\"\n"
  },
  {
    "path": ".github/workflows/main.yaml",
    "content": "name: CI\non: [push, pull_request]\n\njobs:\n  pre-commit:\n    permissions:\n      contents: read\n\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v5\n        with:\n          persist-credentials: false\n      - uses: actions/setup-python@v6\n      - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1\n  build:\n    runs-on: ubuntu-latest\n    permissions:\n      contents: write\n\n    steps:\n      - uses: actions/checkout@v5\n        with:\n          persist-credentials: false\n      - uses: actions/setup-python@v6\n        with:\n          python-version: \"3.10\"\n      - name: Install dependencies\n        run: |\n          sudo apt update\n          sudo apt install \\\n            fontconfig    \\\n            imagemagick   \\\n            poppler-utils\n          python -m pip install --upgrade pip\n          pip install -r requirements/requirements.txt\n      - name: Install Tex Live\n        run: |\n          sudo apt update\n          sudo apt install \\\n            texlive-base              \\\n            texlive-extra-utils       \\\n            texlive-fonts-extra       \\\n            texlive-fonts-recommended \\\n            texlive-latex-base        \\\n            texlive-latex-extra       \\\n            texlive-latex-recommended \\\n            texlive-xetex\n      - name: Build artifacts\n        run: |\n          # adjust the ImageMagick policies to convert PDF to PNG\n          # remove all policies restricting Ghostscript ability to process files\n          # https://stackoverflow.com/q/52998331\n          # https://stackoverflow.com/a/59193253\n          sudo sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml\n          #\n          make -C fonts/\n          cp -r fonts/ /usr/share/fonts/\n          fc-cache\n          make all\n      - name: Run checks\n        run: |\n          make check\n      - uses: actions/upload-artifact@v5\n        if: ${{ always() }}\n        with:\n          name: build\n          path: |\n            cheatsheets.pdf\n            handout-*.pdf\n            ./docs/_build/html/\n      - uses: actions/upload-artifact@v5\n        id: diffs-artifact-upload\n        if: ${{ always() }}\n        with:\n          name: diffs\n          path: |\n            diffs/\n      - name: Publish cheatsheets and handouts\n        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}\n        uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0\n        with:\n          github_token: ${{ secrets.GITHUB_TOKEN }}\n          publish_dir: ./docs/_build/html/\n          force_orphan: true\n"
  },
  {
    "path": ".gitignore",
    "content": "# built cheatsheets and handouts\n# ----------------------------------\ncheatsheets*.pdf\ncheatsheets*.png\nhandout-*.pdf\nhandout-*.png\n\n# TeX auxiliary files\n# ----------------------------------\n*.aux\n*.log\n*.out\n*.upa\n\n# generated figures\n# ----------------------------------\nfigures/*.pdf\nfonts/**/*.[ot]tf\n\n# html build\ndocs/_build/*\n\n# OS specific\n.DS_Store\n"
  },
  {
    "path": ".pre-commit-config.yaml",
    "content": "exclude: |\n  (?x)^(\n    .+[.]svg|\n  )$\nrepos:\n  - repo: https://github.com/pre-commit/pre-commit-hooks\n    rev: v4.0.1\n    hooks:\n      - id: check-yaml\n      - id: end-of-file-fixer\n      - id: trailing-whitespace\n  - repo: https://github.com/pycqa/flake8\n    rev: 7.3.0\n    hooks:\n      - id: flake8\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "Copyright (c) 2020, Nicolas P. Rougier\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this\n   list of conditions and the following disclaimer.\n2. Redistributions in binary form must reproduce the above copyright notice,\n   this list of conditions and the following disclaimer in the documentation\n   and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\nON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
  },
  {
    "path": "Makefile",
    "content": "SRC := $(wildcard *.tex)\nCONVERTFLAGS = -density 150 -alpha remove -depth 8\n\n.PHONY: default\ndefault: all\n\n.PHONY: all\nall: figures cheatsheets handouts docs\n\n.PHONY: figures\nfigures:\n\t# generate the figures\n\tcd scripts && for script in *.py; do echo $$script; MPLBACKEND=\"agg\" python $$script; done\n\t# crop some of the figures\n\tcd figures && pdfcrop adjustments.pdf adjustments.pdf\n\tcd figures && pdfcrop annotate.pdf annotate.pdf\n\tcd figures && pdfcrop annotation-arrow-styles.pdf annotation-arrow-styles.pdf\n\tcd figures && pdfcrop anatomy.pdf anatomy.pdf\n\tcd figures && pdfcrop colornames.pdf colornames.pdf\n\tcd figures && pdfcrop fonts.pdf fonts.pdf\n\tcd figures && pdfcrop markers.pdf markers.pdf\n\tcd figures && pdfcrop text-alignments.pdf text-alignments.pdf\n\tcd figures && pdfcrop tick-formatters.pdf tick-formatters.pdf\n\tcd figures && pdfcrop tick-locators.pdf tick-locators.pdf\n\tcd figures && pdfcrop tip-font-family.pdf tip-font-family.pdf\n\tcd figures && pdfcrop tip-hatched.pdf tip-hatched.pdf\n\n.PHONY: cheatsheets\ncheatsheets:\n\txelatex cheatsheets.tex\n\tconvert $(CONVERTFLAGS) cheatsheets.pdf -scene 1 cheatsheets.png\n\n.PHONY: handouts\nhandouts:\n\txelatex handout-beginner.tex\n\txelatex handout-intermediate.tex\n\txelatex handout-tips.tex\n\tconvert $(CONVERTFLAGS) handout-tips.pdf handout-tips.png\n\tconvert $(CONVERTFLAGS) handout-beginner.pdf handout-beginner.png\n\tconvert $(CONVERTFLAGS) handout-intermediate.pdf handout-intermediate.png\n\n.PHONY: check\ncheck:\n\t./check-matplotlib-version.py\n\t./check-num-pages.sh cheatsheets.pdf 2\n\t./check-num-pages.sh handout-tips.pdf 1\n\t./check-num-pages.sh handout-beginner.pdf 1\n\t./check-num-pages.sh handout-intermediate.pdf 1\n\t./check-diffs.py\n\t./check-links.py cheatsheets.pdf\n\n.PHONY: docs\ndocs:\n\tmake -C docs/ html\n\tcp ./cheatsheets*.p* ./docs/_build/html\n\tcp ./handout-*.p* ./docs/_build/html\n\n\n.PHONY: fonts\nfonts:\n\tmake -C fonts/\n\n.PHONY: clean\nclean: $(SRC)\n\tlatexmk -c $^\n\t- rm -rf ./build/\n\n.PHONY: clean-all\nclean-all: clean\n\t- rm ./logos/mpl-logo2.pdf\n\tgit clean -f -X ./figures/\n\tgit clean -f ./scripts/*.pdf\n\n.PHONY: requirements\nrequirements:\n\t$(MAKE) -C ./requirements/\n"
  },
  {
    "path": "README.md",
    "content": "# Cheatsheets for Matplotlib users\n\n## Cheatsheets\nCheatsheet [(download pdf)](https://matplotlib.org/cheatsheets/cheatsheets.pdf) | |\n:------------------------------------------------------------------------------:|:----------------------------------------------------------:\n![](https://matplotlib.org/cheatsheets/cheatsheets-1.png)                       | ![](https://matplotlib.org/cheatsheets/cheatsheets-2.png)\n\n## Handouts\n\nBeginner handout [(download pdf)](https://matplotlib.org/cheatsheets/handout-beginner.pdf) | Intermediate handout [(download pdf)](https://matplotlib.org/cheatsheets/handout-intermediate.pdf) | Tips handout [(download pdf)](https://matplotlib.org/cheatsheets/handout-tips.pdf)\n:-----------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------:\n![](https://matplotlib.org/cheatsheets/handout-beginner.png)                               | ![](https://matplotlib.org/cheatsheets/handout-intermediate.png)                                   | ![](https://matplotlib.org/cheatsheets/handout-tips.png)\n\n# For contributors to the cheatsheets\n\n## How to compile\n\n1. You need to create a `fonts` repository with:\n\n* `fonts/roboto/*`           : See https://fonts.google.com/specimen/Roboto\n                                or https://github.com/googlefonts/roboto/tree/master/src/hinted\n* `fonts/roboto-slab/*`      : See https://fonts.google.com/specimen/Roboto+Slab\n                                or https://github.com/googlefonts/robotoslab/tree/master/fonts/static\n* `fonts/source-code-pro/*`  : See https://fonts.google.com/specimen/Source+Code+Pro\n                                or https://github.com/adobe-fonts/source-code-pro/tree/release/OTF\n* `fonts/source-sans-pro/*`  : See https://fonts.google.com/specimen/Source+Sans+Pro\n                                or https://github.com/adobe-fonts/source-sans-pro/tree/release/OTF\n* `fonts/source-serif-pro/*` : See https://fonts.google.com/specimen/Source+Serif+Pro\n                                or https://github.com/adobe-fonts/source-serif-pro/tree/release/OTF\n* `fonts/eb-garamond/*`      : See https://bitbucket.org/georgd/eb-garamond/src/master\n* `fonts/pacifico/*`         : See https://fonts.google.com/download?family=Pacifico\n\nOn Linux, with `make` installed, the fonts can be set up with the following command:\n```shell\nmake -C fonts\n```\n\nThe fonts can be made discoverable by `matplotlib` (through `fontconfig`) by creating the following in `$HOME/.config/fontconfig/fonts.conf` (see [here](https://www.freedesktop.org/software/fontconfig/fontconfig-user.html)):\n\n```xml\n<?xml version=\"1.0\"?>\n<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n<fontconfig>\n<dir>/path/to/cheatsheets/fonts/</dir>\n...\n</fontconfig>\n```\n\n\n2. You need to generate all the figures:\n\n```\n$ cd scripts\n$ for script in *.py; do python $script; done\n$ cd ..\n```\n\n3. Compile the sheet\n```\n$ xelatex cheatsheets.tex\n$ xelatex cheatsheets.tex\n```\n"
  },
  {
    "path": "cheatsheets.tex",
    "content": "% -----------------------------------------------------------------------------\n% Matplotlib cheat sheet - Released under the BSD License\n% -----------------------------------------------------------------------------\n\\documentclass[10pt,landscape,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n% --- Page layout -------------------------------------------------------------\n\\usepackage[right=2.5mm, left=2.5mm, top=2.5mm, bottom=2.5mm]{geometry}\n\n% --- English stuff -----------------------------------------------------------\n\\usepackage[english]{babel}\n\\usepackage{xspace}\n\\usepackage{csquotes}\n\n% --- Graphics ----------------------------------------------------------------\n\\usepackage{tikz}\n\\usepackage{graphicx}\n\\usepackage[percent]{overpic}\n\\graphicspath{{./figures/}{./icons/}{./logos/}}\n\\usepackage[export]{adjustbox}\n\n% --- Framed boxes ------------------------------------------------------------\n\\usepackage[framemethod=TikZ]{mdframed}\n\\mdfsetup{skipabove=0pt,skipbelow=0pt}\n\\usepackage{menukeys}\n\n% --- URL, href and colors ----------------------------------------------------\n\\usepackage{xcolor}\n\\colorlet{citecolor}{black}\n\\colorlet{linkcolor}{black}\n\\colorlet{urlcolor}{black}\n\\usepackage[\n  bookmarks=true,\n  breaklinks=true,\n  pdfborder={0 0 0},\n  citecolor=citecolor,\n  linkcolor=linkcolor,\n  urlcolor=urlcolor,\n  colorlinks=true,\n  linktocpage=false,\n  hyperindex=true,\n  colorlinks=true,\n  linktocpage=false,\n  linkbordercolor=white]{hyperref}\n\n% --- Tests -------------------------------------------------------------------\n\\usepackage{etoolbox}\n\n% --- Fonts -------------------------------------------------------------------\n\\usepackage{fontspec}\n\\usepackage[fixed]{fontawesome5}\n\\usepackage[babel=true]{microtype}\n\\defaultfontfeatures{Ligatures=TeX}\n\\setmainfont{Source Serif Pro}[\n  Path           = fonts/source-serif-pro/SourceSerifPro-,\n  Extension      = .otf,\n  UprightFont    = Light,\n  ItalicFont     = LightIt,\n  BoldFont       = Regular,\n  BoldItalicFont = It ]\n\\setsansfont{Roboto}[\n  Path        = fonts/roboto/Roboto-,\n  Extension   = .ttf,\n  UprightFont = Light,\n  ItalicFont  = LightItalic,\n  BoldFont    = Regular ]\n\\setmonofont{Source Code Pro}[\n  Path        = fonts/source-code-pro/SourceCodePro-,\n  Extension   = .otf,\n  UprightFont = Light,\n  BoldFont    = Regular ]\n\\newfontfamily\\RobotoCon{Roboto Condensed}[\n  Path        = fonts/roboto/RobotoCondensed-,\n  Extension   = .ttf,\n  UprightFont = Regular,\n  ItalicFont  = Italic,\n  BoldFont    = Bold ]\n\\newfontfamily\\RobotoSlab{Roboto Slab}[\n  Path        = fonts/roboto-slab/RobotoSlab-,\n  Extension   = .ttf,\n  UprightFont = Light,\n  BoldFont    = Regular ]\n\\newfontfamily\\Roboto{Roboto}[\n  Path        = fonts/roboto/Roboto-,\n  Extension   = .ttf,\n  UprightFont = Regular,\n  ItalicFont  = Italic,\n  BoldFont    = Black ]\n\n% --- Arrays ------------------------------------------------------------------\n\\usepackage{multicol}\n\\usepackage{colortbl}\n\\usepackage{array, multirow}\n\n% --- Maths -------------------------------------------------------------------\n\\usepackage{amsmath}\n\n\n% --- PDF comments ------------------------------------------------------------\n\\usepackage{pdfcomment}\n\n% --- Default options ---------------------------------------------------------\n\\setlength\\parindent{0pt}\n\\setlength{\\tabcolsep}{2pt}\n\\baselineskip=0pt\n\\setlength\\columnsep{1.75mm}\n\n\n% --- Macros ------------------------------------------------------------------\n\\newcommand{\\button}[1]{\\tikz[baseline=(X.base)]\n  \\node [fill=orange!40, rectangle, inner sep=2pt,rounded corners=1pt] (X) {#1};}\n\n\\newcommand{\\API}[1]{\\tikz[baseline=(X.base)]\n  \\node [fill=black!40, rectangle, inner sep=2pt,rounded corners=1pt] (X)\n        {\\href{#1}{\\color{white}{\\tiny \\sffamily \\textbf{API}}}};}\n\n\\newcommand{\\READ}[1]{\\tikz[baseline=(X.base)]\n  \\node [fill=black!40, rectangle, inner sep=2pt,rounded corners=1pt] (X)\n        {\\href{#1}{\\color{white}{\\tiny \\sffamily \\textbf{READ}}}};}\n\n\\newcommand{\\api}[1]{\\tikz[baseline=(X.base)]\n  \\node [fill=orange!40, rectangle, inner sep=2pt,rounded corners=1pt] (X)\n        {\\href{#1}{\\color{white}{\\tiny \\sffamily \\textbf{API}}}};}\n\n\n\\newcommand{\\plot}[5]{%\n  \\begin{tabular}{@{}p{0.18\\columnwidth}p{0.795\\columnwidth}@{}}\n    \\adjustimage{width=0.18\\columnwidth,valign=t}{#1} &\n    {\\ttfamily \\scriptsize #2} \\hfill \\api{#3} \\newline\n    {\\scriptsize #4}  \\newline\n    {\\scriptsize #5 } \\vspace{.7em}\\\\\n  \\end{tabular}}\n\n\\newcommand{\\scale}[3]{%\n  \\begin{tabular}{@{}p{0.18\\columnwidth}p{0.288\\columnwidth}@{}}\n    \\adjustimage{width=0.18\\columnwidth,valign=t}{#1} & {\\ttfamily #2} \\newline\n    {\\scriptsize #3}\n  \\end{tabular}}\n\n\\newcommand{\\colormap}[1]{%\n  \\adjustimage{width=0.7\\columnwidth,valign=c}{colormap-#1.pdf} &\n  \\tiny \\ttfamily #1\\\\ \\arrayrulecolor{white}\\hline\n}\n\n\\newcommand{\\palette}[2]{%\n  \\adjustimage{width=0.7\\columnwidth,valign=c}{colors-#1.pdf} &\n  \\tiny \\ttfamily #2\\\\ \\arrayrulecolor{white}\\hline\n}\n\n\n\\newcommand{\\optional}[1]{\\textcolor{gray}{#1}}\n\\newcommand{\\mandatory}[1]{\\textbf{#1}}\n\\newcommand{\\parameter}[2]{%\n  \\expandafter\\ifstrequal\\expandafter{#1}{optional}%\n                                     {\\optional{#2}}{\\mandatory{#2}}}\n% --- Parameter: interpolation\n\n\\newcommand{\\paramx}[1]{%\n  \\pdftooltip{\\parameter{#1}{X}}\n  {Horizontal coordinates of data point. 1D array like or scalar. }\n}\n\n\\newcommand{\\paramy}[1]{%\n  \\pdftooltip{\\parameter{#1}{Y}}%\n  {Vertical coordinates of data point. 1D array like or scalar. }\n}\n\n\\newcommand{\\paramfmt}[1]{%\n  \\pdftooltip{\\parameter{#1}{fmt}}%\n  {A format string, e.g. 'ro' for red circles. Format strings are just\n   an abbreviation for quickly setting basic line properties. All of\n   these and more can also be controlled by keyword arguments.}\n}\n\n\\newcommand{\\paramcolor}[1]{%\n  \\pdftooltip{\\parameter{#1}{color}}%\n  {Set line color.}\n}\n\n\\newcommand{\\parammarker}[1]{%\n  \\pdftooltip{\\parameter{#1}{marker}}%\n  {Set marker style.}\n}\n\n\\newcommand{\\paramlinestyle}[1]{%\n  \\pdftooltip{\\parameter{#1}{linestyle}}%\n  {Set line style.}\n}\n\n\n  \\newcommand{\\interpolation}[1]{%\n  \\pdftooltip{\\parameter{#1}{interpolation}}\n  {None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36',\n   'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian',\n   'bessel', 'mitchell', 'sinc', 'lanczos'}\n}\n\n% --- Parameter: extent\n\\newcommand{\\extent}{\\pdftooltip{extent}{[left, right, bottom, top]}}\n\n% --- Parameter: origin\n\\newcommand{\\origin}{\\pdftooltip{origin}{'upper', 'lower'}}\n\n% --- Parameter: z\n\\newcommand{\\Z}{\\pdftooltip{z}{(M,N): an image with scalar data. The values are mappedto colors using normalization and a colormap.\\textCR\n(M, N, 3): an image with RGB values (0-1 float or 0-255 int)\\textCR\n(M, N, 4): an image with RGBA values (0-1 float or 0-255 int)}}\n\n% --- Parameter: cmap\n\\newcommand{\\cmap}{\\pdftooltip{cmap}{\n    Uniform: 'viridis', 'plasma', 'inferno', 'magma', 'cividis'\\textCR\n    \\textCR\n    Sequential: 'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',\n                'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',\n                'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn'\\textCR\n    \\textCR\n    Diverging: 'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',\n               'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr',\n               'seismic'\\textCR\n    \\textCR\n    Cyclic: 'twilight', 'twilight_shifted', 'hsv'\\textCR\n    \\textCR\n    Qualitative: 'Pastel1', 'Pastel2', 'Paired', 'Accent',\n                 'Dark2', 'Set1', 'Set2', 'Set3', 'tab10',\n                 'tab20', 'tab20b', 'tab20c'}}\n\n\n\\newenvironment{myboxed}[1]\n{\\begin{mdframed}[linecolor=black,\n                  backgroundcolor=white,\n                  outerlinewidth=0.25pt,\n                  %roundcorner=0.25em,\n                  innertopmargin=1ex,\n                  topline=true,\n                  rightline=true,\n                  leftline=true,\n                  bottomline=true,\n                  linecolor=black!0,\n                  frametitleaboveskip=0.5em,\n                  frametitlebelowskip=0.5em,\n                  innerbottommargin=.5\\baselineskip,\n                  innerrightmargin=.5em,\n                  innerleftmargin=.5em,\n                  %userdefinedwidth=1\\textwidth,\n                  % frametitle={\\scshape \\bfseries \\sffamily #1},\n                  frametitle={\\footnotesize \\RobotoSlab \\bfseries \\hspace*{0mm} #1},\n                  % frametitlerule=true,\n                  %frametitlerulecolor=red,\n                  frametitlebackgroundcolor=black!5,\n                  frametitlerulewidth=2pt]}\n{\\end{mdframed}}\n\n\n\n\n\n% -----------------------------------------------------------------------------\n\\begin{document}\n\\thispagestyle{empty}\n% \\footnotesize\n\\scriptsize\n\n\\begin{multicols*}{5}\n  \\begin{overpic}[width=\\columnwidth,tics=6,trim=12 6 18 6, clip]{logo2.png}\n    \\put (16.5,1.5) {\\scriptsize\\RobotoCon \\textcolor[HTML]{11557c}{Cheat sheet}}\n    \\put (80,1.5) {\\tiny\\Roboto \\textcolor[HTML]{11557c}{Version 3.9.4}}\n   \\end{overpic}\n  %\\textbf{\\Large \\RobotoCon Matplotlib 3.2 cheat sheet}\\\\\n  %{\\ttfamily https://matplotlib.org} \\hfill CC-BY 4.0\n  % \\bigskip\n  \\vspace{\\fill}\n  %\\hspace{1mm} \\small \\url{https://matplotlib.org/}\n  %\\vspace{\\fill}\n\n  % --- Quick start -----------------------------------------------------------\n  \\begin{myboxed}{Quick start \\hfill\n      \\API{https://matplotlib.org/tutorials/introductory/pyplot.html}}\n  {\\ttfamily \\scriptsize\n  import numpy as np\\\\\n  import matplotlib as mpl\\\\\n  import matplotlib.pyplot as plt\\\\\n  \\\\\n  \\\\\n  X = np.linspace(0, 2*np.pi, 100)\\\\\n  Y = np.cos(X)\\\\\n  \\\\\n  fig, ax = plt.subplots()\\\\\n  ax.plot(X, Y, color='green')\\\\\n  \\\\\n  fig.savefig(``figure.pdf'')\\\\\n  plt.show() }\n  \\end{myboxed}\n  \\vspace{\\fill}\n\n  % --- Figure anatomy --------------------------------------------------------\n  \\begin{myboxed}{Anatomy of a figure}\n  \\includegraphics[width=\\columnwidth]{anatomy.pdf}\n  \\end{myboxed}\n  \\vspace{\\fill}\n  % --- Layout ---------------------------------------------------------------\n  \\begin{myboxed}{Subplots layout \\hfill\n      \\API{https://matplotlib.org/tutorials/intermediate/gridspec.html} }\n  \\plot{layout-subplot.pdf}{\\textbf{subplot[s]}(rows, cols, …)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html}\n       {\\ttfamily fig, axs = plt.subplots(3, 3)}\n       {}\n  \\plot{layout-gridspec.pdf}{G = \\textbf{gridspec}(rows,cols, …)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.gridspec.GridSpec.html}\n       {\\ttfamily ax = G[0, :]}{}\n  \\plot{layout-inset.pdf}{ax.\\textbf{inset\\_axes}(extent)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.inset_axes.html}\n       {}{}\n  \\plot{layout-divider.pdf}{d=\\textbf{make\\_axes\\_locatable}(ax)}\n       {https://matplotlib.org/mpl_toolkits/axes_grid/users/axes_divider.html}\n       {\\ttfamily ax = d.new\\_horizontal('10\\%')}{}\n  \\end{myboxed}\n  \\vspace{\\fill}\n\n  % --- Getting help ----------------------------------------------------------\n  \\begin{myboxed}{Getting help}\n    \\href{https://matplotlib.org}\n         {\\faIcon{globe}\\,matplotlib.org}\\\\\n    \\href{https://github.com/matplotlib/matplotlib/issues}\n         {\\faIcon{github}\\,github.com/matplotlib/matplotlib/issues}\\\\\n    \\href{https://discourse.matplotlib.org}\n         {\\faIcon{discourse}\\,discourse.matplotlib.org}\\\\\n    \\href{https://stackoverflow.com/questions/tagged/matplotlib}\n         {\\faIcon{stack-overflow}\\,stackoverflow.com/questions/tagged/matplotlib}\\\\\n    \\href{https://gitter.im/matplotlib/matplotlib}\n         {\\faIcon{gitter}\\,{https://gitter.im/matplotlib/matplotlib}}\\\\\n    \\href{https://twitter.com/matplotlib}\n         {\\faIcon{twitter}\\,twitter.com/matplotlib}\\\\\n    \\href{https://mail.python.org/mailman/listinfo/matplotlib-users}\n         {\\faIcon[regular]{envelope}\\,Matplotlib users mailing list}\n  \\end{myboxed}\n\n\n  % --- Basic plots -----------------------------------------------------------\n  \\begin{myboxed}{Basic plots}\n  \\plot{basic-plot.pdf}{\\textbf{plot}([X], Y, [fmt], …)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html}\n       {\\optional{X},\n        \\mandatory{Y},\n        \\optional{fmt},\n        \\optional{color},\n        \\optional{marker},\n        \\optional{linestyle}}\n       {}\n  \\plot{basic-scatter.pdf}{\\textbf{scatter}(X, Y, …)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html}\n       {\\mandatory{X},\n        \\mandatory{Y},\n        \\optional{[s]izes},\n        \\optional{[c]olors},\n        \\optional{marker},\n        \\optional{cmap}}\n       {}\n  \\plot{basic-bar.pdf}{\\textbf{bar[h]}(x, height, …)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html}\n       { \\mandatory{x},\n         \\mandatory{height},\n         \\optional{width},\n         \\optional{bottom},\n         \\optional{align},\n         \\optional{color} }{}\n  \\plot{basic-imshow.pdf}{\\textbf{imshow}(Z, …)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html}\n       { \\mandatory{Z},\n         \\optional{cmap},\n         \\optional{interpolation},\n         \\optional{extent},\n         \\optional{origin} }\n       {}\n  \\plot{basic-contour.pdf}{\\textbf{contour[f]}([X], [Y], Z, …)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html}\n       { \\optional{X},\n         \\optional{Y},\n         \\mandatory{Z},\n         \\optional{levels},\n         \\optional{colors},\n         \\optional{extent},\n         \\optional{origin} }\n       {}\n  \\plot{basic-pcolormesh.pdf}{\\textbf{pcolormesh}([X], [Y], Z, …)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pcolormesh.html}\n       { \\optional{X},\n         \\optional{Y},\n         \\mandatory{Z},\n         \\optional{vmin},\n         \\optional{vmax},\n         \\optional{cmap}}\n       {}\n  \\plot{basic-quiver.pdf}{\\textbf{quiver}([X], [Y], U, V, …)}\n     {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.quiver.html}\n     { \\optional{X},\n       \\optional{Y},\n       \\mandatory{U},\n       \\mandatory{V},\n       \\optional{C},\n       \\optional{units},\n       \\optional{angles} }\n     {}\n  \\plot{basic-pie.pdf}{\\textbf{pie}(X, …)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pie.html}\n       {\\mandatory{Z},\n         \\optional{explode},\n         \\optional{labels},\n         \\optional{colors},\n         \\optional{radius}}\n       {}\n   \\plot{basic-text.pdf}{\\textbf{text}(x, y, text, …)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.text.html}\n       {\\mandatory{x},\n        \\mandatory{y},\n        \\mandatory{text},\n        \\optional{va},\n        \\optional{ha},\n        \\optional{size},\n        \\optional{weight},\n        \\optional{transform} }\n       {}\n   \\plot{basic-fill.pdf}{\\textbf{fill[\\_between][x]}(…)}\n       {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.fill.html}\n       {\\mandatory{X},\n        \\optional{Y1},\n        \\optional{Y2},\n        \\optional{color},\n        \\optional{where} }\n       {}\n  \\end{myboxed}\n  \\vspace{\\fill}\n  % --- Advanced plots --------------------------------------------------------\n  \\begin{myboxed}{Advanced plots}\n  \\plot{advanced-step.pdf}{\\textbf{step}(X, Y, [fmt], …)}\n     {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.step.html}\n     {\\mandatory{X},\n      \\mandatory{Y},\n      \\optional{fmt},\n      \\optional{color},\n      \\optional{marker},\n      \\optional{where} }\n     {}\n  \\plot{advanced-boxplot.pdf}{\\textbf{boxplot}(X, …)}\n     {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.boxplot.html}\n     { \\mandatory{X},\n       \\optional{notch},\n       \\optional{sym},\n       \\optional{bootstrap},\n       \\optional{widths} }\n     {}\n  \\plot{advanced-errorbar.pdf}{\\textbf{errorbar}(X,Y,xerr,yerr, …)}\n     {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.errorbar.html}\n     { \\mandatory{X},\n       \\mandatory{Y},\n       \\optional{xerr},\n       \\optional{yerr},\n       \\optional{fmt} }\n     {}\n  \\plot{advanced-hist.pdf}{\\textbf{hist}(X, bins, …)}\n     {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html}\n     {\\mandatory{X},\n      \\optional{bins},\n      \\optional{range},\n      \\optional{density},\n      \\optional{weights}}\n     {}\n  \\plot{advanced-violin.pdf}{\\textbf{violinplot}(D, …)}\n     {https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.violinplot.html}\n     {\\mandatory{D},\n      \\optional{positions},\n      \\optional{widths},\n      \\optional{vert} }\n     {}\n  \\plot{advanced-barbs.pdf}{\\textbf{barbs}([X], [Y], U, V, …)}\n     {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.barbs.html}\n     { \\optional{X},\n       \\optional{Y},\n       \\mandatory{U},\n       \\mandatory{V},\n       \\optional{C},\n       \\optional{length},\n       \\optional{pivot},\n       \\optional{sizes} }\n     {}\n  \\plot{advanced-event.pdf}{\\textbf{eventplot}(positions, …)}\n     {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.eventplot.html}\n     {\\mandatory{positions},\n       \\optional{orientation},\n       \\optional{lineoffsets} }\n     {}\n  \\plot{advanced-hexbin.pdf}{\\textbf{hexbin}(X, Y, C, …)}\n     {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hexbin.html}\n     {\\mandatory{X},\n      \\mandatory{Y},\n      \\optional{C},\n      \\optional{gridsize},\n       \\optional{bins} }\n     {}\n  \\end{myboxed}\n\n\n  % --- Scale ---------------------------------------------------------------\n  \\begin{myboxed}{Scales \\hfill\n    \\API{https://matplotlib.org/stable/api/scale_api.html}}\n  {\\ttfamily ax.\\textbf{set\\_[xy]scale}(scale, …)}\n  \\smallskip\n  \\scale{scale-linear.pdf}{\\textbf{linear}}{any values}\n  \\scale{scale-log.pdf}{\\textbf{log}}{values > 0}\n  \\scale{scale-symlog.pdf}{\\textbf{symlog}}{any values}\n  \\scale{scale-logit.pdf}{\\textbf{logit}}{0 < values <  1}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  % --- Projections -----------------------------------------------------------\n  \\begin{myboxed}{Projections \\hfill\n      \\API{https://matplotlib.org/stable/api/projections_api.html}}\n  {\\ttfamily \\textbf{subplot}(…, projection=p)}\n  \\smallskip\n  \\scale{projection-polar.pdf}{p='polar'}{}\n  \\scale{projection-3d.pdf}\n      {p='3d'\\hfill\\api{https://matplotlib.org/stable/api/toolkits/mplot3d.html}}{}\n  \\plot{projection-cartopy.pdf}{p=ccrs.Orthographic()}\n       {https://scitools.org.uk/cartopy/docs/latest/reference/projections.html}\n       {import cartopy.crs as ccrs}\n       {}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  % --- Linestyles ---------------------------------------------------------------\n  \\begin{myboxed}{Lines \\hfill\n      \\API{https://matplotlib.org/gallery/lines_bars_and_markers/linestyles.html}}\n  \\includegraphics[width=\\columnwidth]{linestyles.pdf}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  % --- Markers ---------------------------------------------------------------\n  \\begin{myboxed}{Markers \\hfill\n                \\API{https://matplotlib.org/stable/api/markers_api.html}}\n      \\includegraphics[width=\\columnwidth]{markers.pdf}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  % --- Colors ---------------------------------------------------------------\n  \\begin{myboxed}{Colors \\hfill\n      \\API{https://matplotlib.org/tutorials/colors/colors.html}}\n    %  mpl.colors.to\\_rbga(\\textbf{color})\\smallskip\\\\\n    \\def\\arraystretch{0.5}\n    \\begin{tabular}{@{}p{0.7\\columnwidth}p{0.25\\columnwidth}@{}}\n      \\palette{cycle}{'Cn'}\n      \\palette{raw}{ 'x' }\n      \\palette{name}{'name'}\n      \\palette{rgba}{(R,G,B[,A])}\n      \\palette{HexRGBA}{'\\#RRGGBB[AA]'}\n      \\palette{grey}{'x.y'}\n    \\end{tabular}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n\n\n  % --- Colormaps -------------------------------------------------------------\n  \\begin{myboxed}{Colormaps \\hfill\n      \\API{https://matplotlib.org/tutorials/colors/colormaps.html}}\n    {\\ttfamily plt.\\textbf{get\\_cmap}(name) \\smallskip\\\\}\n    \\def\\arraystretch{0.5}\n    \\begin{tabular}{@{}p{0.7\\columnwidth}p{0.25\\columnwidth}@{}}\n      \\scriptsize \\rule{0pt}{1.25em}Uniform & \\\\\n      \\colormap{viridis} \\colormap{magma} \\colormap{plasma}\n      %\n      \\scriptsize \\rule{0pt}{1.25em}Sequential &\\\\\n      \\colormap{Greys} \\colormap{YlOrBr} \\colormap{Wistia}\n      %\n      \\scriptsize \\rule{0pt}{1.25em}Diverging &\\\\\n      \\colormap{Spectral} \\colormap{coolwarm} \\colormap{RdGy}\n      %\n      \\scriptsize \\rule{0pt}{1.25em}Qualitative &\\\\\n      \\colormap{tab10} \\colormap{tab20}\n      %\n      \\scriptsize \\rule{0pt}{1.25em}Cyclic &\\\\\n      \\colormap{twilight} % \\colormap{hsv}\n    \\end{tabular}\n  \\end{myboxed}\n\n  % --- Ticks locators --------------------------------------------------------\n  \\begin{myboxed}{Tick locators \\hfill\n    \\API{https://matplotlib.org/stable/api/ticker_api.html}}\n    {\\tiny \\ttfamily\n      from matplotlib import ticker\\\\\n      ax.[xy]axis.set\\_[minor|major]\\_locator(\\textbf{locator})\\par\n      \\vspace{1em}\n      \\hspace{-1em}\\includegraphics[width=\\columnwidth]{tick-locators.pdf}\n      }\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Tick formatters \\hfill\n    \\API{https://matplotlib.org/stable/api/ticker_api.html}}\n    {\\tiny \\ttfamily\n      from matplotlib import ticker\\\\\n      ax.[xy]axis.set\\_[minor|major]\\_formatter(\\textbf{formatter})\\par\n      \\vspace{1em}\n      \\hspace{-1em}\\includegraphics[width=\\columnwidth]{tick-formatters.pdf}\n    }\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Ornaments}\n    {\\ttfamily ax.\\textbf{legend}(…) \\hfill\n    \\api{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html}}\\\\\n     handles, labels, loc, title, frameon\\smallskip\\\\\n    \\includegraphics[width=0.9\\columnwidth]{legend.pdf}\n    \\medskip\\\\\n    %\n    {\\ttfamily ax.\\textbf{colorbar}(…)} \\hfill\n    \\api{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.colorbar.html}\\\\\n    mappable, ax, cax, orientation \\smallskip\\\\\n    \\includegraphics[width=\\columnwidth]{colorbar.pdf}\\\\\n    \\medskip\\\\\n    %\n    {\\ttfamily ax.\\textbf{annotate}(…)} \\hfill\n    \\api{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.annotate.html}\\\\\n    \\mandatory{text},\n    \\mandatory{xy},\n    \\mandatory{xytext},\n    \\optional{xycoords},\n    \\optional{textcoords},\n    \\optional{arrowprops}\n    \\smallskip\\\\\n    \\includegraphics[width=\\columnwidth]{annotate.pdf}\\\\\n    %\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Event handling \\hfill\n      \\API{https://matplotlib.org/users/event_handling.html}}\n    {\\ttfamily \\scriptsize\n      fig, ax = plt.subplots()\\par\n      \\par\n      def on\\_click(event):\\par\n      ~~print(event)\\par\n      fig.canvas.mpl\\_connect(\\par\n      ~~'button\\_press\\_event', on\\_click)\\par\n    }\n  \\end{myboxed}\n\n  %\n  % \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Animation \\hfill\n      \\API{https://matplotlib.org/stable/api/animation_api.html}}\n  {\\ttfamily \\scriptsize\n  import matplotlib.animation as mpla\\par\n  ~\\par\n  T = np.linspace(0, 2*np.pi, 100)\\par\n  S = np.sin(T)\\par\n  line, = plt.plot(T, S)\\par\n  def animate(i):\\par\n  ~~~~line.set\\_ydata(np.sin(T+i/50))\\par\n  anim = mpla.FuncAnimation(\\par\n  ~~~~plt.gcf(), animate, interval=5)\\par\n  plt.show()\\par\n  }\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Styles \\hfill\n      \\API{https://matplotlib.org/tutorials/introductory/customizing.html}}\n    \\setlength{\\fboxsep}{0pt}%\n    \\setlength{\\fboxrule}{.25pt}%\n              {\\ttfamily plt.style.use(\\textbf{style})\\medskip}\n\n    \\fbox{\\includegraphics[width=.32\\columnwidth]{style-default.pdf}}\n    \\fbox{\\includegraphics[width=.32\\columnwidth]{style-classic.pdf}}\n    \\fbox{\\includegraphics[width=.32\\columnwidth]{style-grayscale.pdf}}\n\n    \\fbox{\\includegraphics[width=.32\\columnwidth]{style-ggplot.pdf}}\n    \\fbox{\\includegraphics[width=.32\\columnwidth]{style-seaborn-v0_8.pdf}}\n    \\fbox{\\includegraphics[width=.32\\columnwidth]{style-fast.pdf}}\n\n    \\fbox{\\includegraphics[width=.32\\columnwidth]{style-bmh.pdf}}\n    \\fbox{\\includegraphics[width=.32\\columnwidth]{style-Solarize_Light2.pdf}}\n    \\fbox{\\includegraphics[width=.32\\columnwidth]{style-seaborn-v0_8-notebook.pdf}}\n\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Quick reminder}\n  {\\ttfamily\n    ax.\\textbf{grid}()\\\\\n    ax.\\textbf{set\\_[xy]lim}(vmin, vmax)\\\\\n    ax.\\textbf{set\\_[xy]label}(label)\\\\\n    ax.\\textbf{set\\_[xy]ticks}(ticks, [labels])\\\\\n    ax.\\textbf{set\\_[xy]ticklabels}(labels)\\\\\n    ax.\\textbf{set\\_title}(title)\\\\\n    ax.\\textbf{tick\\_params}(width=10, …)\\\\\n    ax.\\textbf{set\\_axis\\_[on|off]}()\\\\\n    \\\\\n    fig.\\textbf{suptitle}(title)\\\\\n    fig.\\textbf{tight\\_layout}()\\\\\n    plt.\\textbf{gcf}(), plt.\\textbf{gca}()\\\\\n    mpl.\\textbf{rc}('axes', linewidth=1, …)\\\\\n    {[fig|ax]}.patch.\\textbf{set\\_alpha}(0)\\\\\n    \\verb|text=r'$\\frac{-e^{i\\pi}}{2^n}$'|}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  %% % --- Toolkits --------------------------------------------------------------\n  %% \\begin{myboxed}{Toolkits and libraries}\n  %%   \\href{https://matplotlib.org/basemap/}{Basemap} ---\n  %% \\href{https://scitools.org.uk/cartopy/docs/latest/}{Cartopy} ---\n  %% \\href{https://geopandas.org/}{GeoPandas} ---\n  %% \\href{https://residentmario.github.io/geoplot/index.html}{Geoplot} ---\n  %% \\href{https://github.com/yhat/ggpy}{GGPlot} ---\n  %% \\href{http://holoviews.org/}{Holoviews} ---\n  %% \\href{https://seaborn.pydata.org/}{Seaborn} ---\n  %% \\href{https://gr-framework.org/}{GR Framework} ---\n  %% \\href{https://www.scikit-yb.org/en/latest/}{Yellowbrick}\n  %% \\end{myboxed}\n  %% %\n  %% \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Keyboard shortcuts \\hfill\n    \\API{https://matplotlib.org/users/navigation_toolbar.html}}\n    \\def\\arraystretch{1.25}\n    \\begin{tabular}{ll}\n      \\keys{\\ctrl+s} Save        & \\keys{\\ctrl+w} Close plot\\\\\n      \\keys{r} Reset view        & \\keys{f} Fullscreen 0/1\\\\\n      \\keys{f} View forward      & \\keys{b} View back\\\\\n      \\keys{p} Pan view          & \\keys{o} Zoom to rect\\\\\n      \\keys{x} X pan/zoom        & \\keys{y} Y pan/zoom\\\\\n      \\keys{g} Minor grid 0/1    & \\keys{G} Major grid 0/1\\\\\n      \\keys{l} X axis log/linear & \\keys{L} Y axis log/linear\\\\\n      %\\keys{l} & Toggle y linear / log axis\\\\\n    \\end{tabular}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Ten simple rules \\hfill\n      \\READ{https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1003833}}\n    1. Know your audience\\\\\n    2. Identify your message\\\\\n    3. Adapt the figure\\\\\n    4. Captions are not optional\\\\\n    5. Do not trust the defaults\\\\\n    6. Use color effectively\\\\\n    7. Do not mislead the reader\\\\\n    8. Avoid “chartjunk”\\\\\n    9. Message trumps beauty\\\\\n    10. Get the right tool\n  \\end{myboxed}\n\\end{multicols*}\n\n\\begin{multicols*}{5}\n  \\begin{myboxed}{Axes adjustments\\hfill\n      \\API{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots_adjust.html}}\n    plt.\\textbf{subplots\\_adjust}( … )\\\\\n\n    \\includegraphics[width=\\columnwidth]{adjustments.pdf}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Extent \\& origin \\hfill\n      \\API{https://matplotlib.org/tutorials/intermediate/imshow_extent.html} }\n    ax.\\textbf{imshow}( extent=…, origin=… )\\\\\n\n    \\includegraphics[width=\\columnwidth]{extents.pdf}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Text alignments \\hfill\n      \\API{https://matplotlib.org/tutorials/text/text_props.html} }\n    ax.\\textbf{text}( …, ha=… , va=…, …)\\\\\n\n    \\includegraphics[width=\\columnwidth]{text-alignments.pdf}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Text parameters  \\hfill\n      \\API{https://matplotlib.org/tutorials/text/text_props.html}}\n    ax.\\textbf{text}(…, family=…, size=…, weight=…)\\\\\n    ax.\\textbf{text}(…, fontproperties=…)\\\\\n\n    \\includegraphics[width=\\columnwidth]{fonts.pdf}\n  \\end{myboxed}\n\n\n  \\begin{myboxed}{Uniform colormaps}\n    \\begin{tabular}{@{}p{0.7\\columnwidth}p{0.25\\columnwidth}@{}}\n      \\scriptsize \\rule{0pt}{1.25em}\\noindent\n      \\colormap{viridis}\n      \\colormap{plasma}\n      \\colormap{inferno}\n      \\colormap{magma}\n      \\colormap{cividis}\n    \\end{tabular}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Sequential colormaps}\n    \\begin{tabular}{@{}p{0.7\\columnwidth}p{0.25\\columnwidth}@{}}\n      \\scriptsize \\rule{0pt}{1.25em}\\noindent\n      \\colormap{Greys}\n      \\colormap{Purples}\n      \\colormap{Blues}\n      \\colormap{Greens}\n      \\colormap{Oranges}\n      \\colormap{Reds}\n      \\colormap{YlOrBr}\n      \\colormap{YlOrRd}\n      \\colormap{OrRd}\n      \\colormap{PuRd}\n      \\colormap{RdPu}\n      \\colormap{BuPu}\n      \\colormap{GnBu}\n      \\colormap{PuBu}\n      \\colormap{YlGnBu}\n      \\colormap{PuBuGn}\n      \\colormap{BuGn}\n      \\colormap{YlGn}\n    \\end{tabular}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Diverging colormaps}\n    \\begin{tabular}{@{}p{0.7\\columnwidth}p{0.25\\columnwidth}@{}}\n      \\scriptsize \\rule{0pt}{1.25em}\\noindent\n      \\colormap{PiYG}\n      \\colormap{PRGn}\n      \\colormap{BrBG}\n      \\colormap{PuOr}\n      \\colormap{RdGy}\n      \\colormap{RdBu}\n      \\colormap{RdYlBu}\n      \\colormap{RdYlGn}\n      \\colormap{Spectral}\n      \\colormap{coolwarm}\n      \\colormap{bwr}\n      \\colormap{seismic}\n    \\end{tabular}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Qualitative colormaps}\n    \\begin{tabular}{@{}p{0.7\\columnwidth}p{0.25\\columnwidth}@{}}\n      \\scriptsize \\rule{0pt}{1.25em}\\noindent\n      \\colormap{Pastel1}\n      \\colormap{Pastel2}\n      \\colormap{Paired}\n      \\colormap{Accent}\n      \\colormap{Dark2}\n      \\colormap{Set1}\n      \\colormap{Set2}\n      \\colormap{Set3}\n      \\colormap{tab10}\n      \\colormap{tab20}\n      \\colormap{tab20b}\n      \\colormap{tab20c}\n    \\end{tabular}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Miscellaneous colormaps}\n    \\begin{tabular}{@{}p{0.7\\columnwidth}p{0.25\\columnwidth}@{}}\n      \\scriptsize \\rule{0pt}{1.25em}\\noindent\n      \\colormap{terrain}\n      \\colormap{ocean}\n      \\colormap{cubehelix}\n      \\colormap{rainbow}\n      \\colormap{twilight}\n    \\end{tabular}\n  \\end{myboxed}\n\n\n\n  \\begin{myboxed}{Color names \\hfill\n      \\API{https://matplotlib.org/stable/api/colors_api.html} }\n    \\includegraphics[width=\\columnwidth]{colornames.pdf}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Image interpolation\n      \\hfill \\API{https://matplotlib.org/gallery/images_contours_and_fields/interpolation_methods.html} }\n        \\smallskip\n%%    plt.\\textbf{imshow}(…, interpolation=…)\\\\\n%%    plt.\\textbf{contour[f]}(…, interpolation=…)\\\\\n    \\includegraphics[width=\\columnwidth]{interpolations.pdf}\n  \\end{myboxed}\n\n\n  \\begin{myboxed}{Legend placement}\n    \\includegraphics[width=\\columnwidth]{legend-placement.pdf}\n    ax.\\textbf{legend}(loc=\"string\", bbox\\_to\\_anchor=(x, y))\\\\\n    \\begin{tabular}{@{}p{0.33\\columnwidth}\n                       p{0.33\\columnwidth}\n                       p{0.33\\columnwidth}@{}}\n      \\scriptsize \\rule{0pt}{1.25em}\\noindent\n      2: upper left  & 9: upper center  & 1: upper right\\\\\n      6: center left & 10: center       & 7: center right\\\\\n      3: lower left  & 8: lower center  & 4: lower right\\\\\n    \\end{tabular}\n\n    \\begin{tabular}{@{}p{0.495\\columnwidth}\n                       p{0.495\\columnwidth}@{}}\n      \\scriptsize \\rule{0pt}{1.25em}\\noindent\n      \\tiny A: upper right /  {\\ttfamily (-0.1, 0.9)} & \\tiny B: center right / {\\ttfamily (-0.1, 0.5)}\\\\\n      \\tiny C: lower right /  {\\ttfamily (-0.1, 0.1)} & \\tiny D: upper left /   {\\ttfamily (0.1, -0.1)}\\\\\n      \\tiny E: upper center / {\\ttfamily (0.5, -0.1)} & \\tiny F: upper right /  {\\ttfamily (0.9, -0.1)}\\\\\n      \\tiny G: lower left /   {\\ttfamily (1.1, 0.1)} & \\tiny H: center left /  {\\ttfamily (1.1, 0.5)}\\\\\n      \\tiny I: upper left /   {\\ttfamily (1.1, 0.9)} & \\tiny J: lower right /  {\\ttfamily (0.9, 1.1)}\\\\\n      \\tiny K: lower center / {\\ttfamily (0.5, 1.1)} & \\tiny L: lower left /   {\\ttfamily (0.1, 1.1)}\n    \\end{tabular}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Annotation connection styles \\hfill\n      \\API{https://matplotlib.org/tutorials/text/annotations.html} }\n    \\includegraphics[width=\\columnwidth]{annotation-connection-styles.pdf}\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Annotation arrow styles \\hfill\n      \\API{https://matplotlib.org/tutorials/text/annotations.html} }\n    \\includegraphics[width=\\columnwidth]{annotation-arrow-styles.pdf}\n  \\end{myboxed}\n\n  %\n  \\vspace{\\fill}\n  %\n\n  %\n  \\begin{myboxed}{How do I …}\n    \\textbf{… resize a figure?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ fig.set\\_size\\_inches(w, h)\\\\\n    \\textbf{… save a figure?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ fig.savefig(\"figure.pdf\")\\\\\n    \\textbf{… save a transparent figure?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ fig.savefig(\"figure.pdf\", transparent=True)\\\\\n    \\textbf{… clear a figure/an axes?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ fig.clear() $\\rightarrow$ ax.clear()\\\\\n    \\textbf{… close all figures?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ plt.close(\"all\")\\\\\n    \\textbf{… remove ticks?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ ax.set\\_[xy]ticks([])\\\\\n    \\textbf{… remove tick labels ?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ ax.set\\_[xy]ticklabels([])\\\\\n    \\textbf{… rotate tick labels ?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ ax.tick\\_params(axis=\"x\", rotation=90)\\\\\n    \\textbf{… hide top spine?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ ax.spines['top'].set\\_visible(False)\\\\\n    \\textbf{… hide legend border?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$  ax.legend(frameon=False)\\\\\n    \\textbf{… show error as shaded region?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ ax.fill\\_between(X, Y+error, Y-error)\\\\\n    \\textbf{… draw a rectangle?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$  ax.add\\_patch(plt.Rectangle((0, 0), 1, 1)\\\\\n    \\textbf{… draw a vertical line?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$  ax.axvline(x=0.5)\\\\\n    \\textbf{… draw outside frame?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$  ax.plot(…, clip\\_on=False)\\\\\n    \\textbf{… use transparency?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$  ax.plot(…, alpha=0.25)\\\\\n    \\textbf{… convert an RGB image into a gray image? }\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$  gray = 0.2989*R + 0.5870*G + 0.1140*B\\\\\n    \\textbf{… set figure background color?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ fig.patch.set\\_facecolor(``grey'')\\\\\n    \\textbf{… get a reversed colormap?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ plt.get\\_cmap(``viridis\\_r'')\\\\\n    \\textbf{… get a discrete colormap?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ plt.get\\_cmap(``viridis'', 10)\\\\\n    \\textbf{… show a figure for one second?}\\\\\n    \\hspace*{2.5mm}~$\\rightarrow$ fig.show(block=False), time.sleep(1)\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Performance tips}\n    \\smallskip\n    {\\ttfamily \\fontsize{6pt}{7pt}\\selectfont\n     %\n    \\textcolor{red}{scatter(X, Y)  \\hfill slow}\\\\\n    plot(X, Y, marker=\"o\", ls=\"\")  \\hfill fast%\n    \\vskip.5\\baselineskip\n    %\n    \\textcolor{red}{for i in range(n): plot(i, X[i], \"o\") \\hfill slow}\\\\\n    plot(X, marker=\"o\", ls=\"\") \\hfill fast%\n    \\vskip.5\\baselineskip\n    %\n    \\textcolor{red}{cla(); imshow(…); canvas.draw() \\hfill slow}\\\\\n    im.set\\_data(…); canvas.draw() \\hfill fast%\n    \\vskip.1\\baselineskip\n    }\n  \\end{myboxed}\n  %\n  \\vspace{\\fill}\n  %\n  \\begin{myboxed}{Beyond Matplotlib}\n        \\smallskip\n    \\href{https://seaborn.pydata.org/}{\\textbf{Seaborn}}: Statistical data visualization\\\\\n    \\href{https://scitools.org.uk/cartopy/docs/latest/}{\\textbf{Cartopy}}: Geospatial data processing\\\\\n    \\href{https://yt-project.org/doc/index.html}{\\textbf{yt}}: Volumetric data visualization\\\\\n    \\href{https://mpld3.github.io}{\\textbf{mpld3}}: Bringing Matplotlib to the browser\\\\\n    \\href{https://datashader.org/}{\\textbf{Datashader}}: Large data processing pipeline\\\\\n    \\href{https://plotnine.org/}{\\textbf{plotnine}}: A grammar of graphics for Python\n  \\end{myboxed}\n  %\n  \\begin{center}\n  \\href{https://github.com/matplotlib/cheatsheets}{Matplotlib Cheatsheets}\\\\\n  Copyright (c) 2021 Matplotlib Development Team\\\\\n  Released under a CC-BY 4.0 International License\\\\\n  \\smallskip\n  \\includegraphics[width=\\columnwidth]{numfocus.png}\n  \\end{center}\n\n\\end{multicols*}\n\\end{document}\n"
  },
  {
    "path": "check-diffs.py",
    "content": "#!/usr/bin/env python\n\nimport os\nimport subprocess\nimport sys\nfrom pathlib import Path\n\n\nROOT_DIR = Path(__file__).parent\n\nif os.environ.get('GITHUB_ACTIONS', '') == '':\n    print('Not running when not in GitHub Actions.')\n    sys.exit()\nsummary_file = os.environ.get('GITHUB_STEP_SUMMARY')\nif summary_file is None:\n    sys.exit('$GITHUB_STEP_SUMMARY is not set')\n\ngh_pages = ROOT_DIR.parent / 'pages'\nsubprocess.run(['git', 'fetch', 'https://github.com/matplotlib/cheatsheets.git',\n                'gh-pages:upstream-gh-pages'], check=True)\nsubprocess.run(['git', 'worktree', 'add', gh_pages, 'upstream-gh-pages'],\n               check=True)\n\ndiff_dir = ROOT_DIR / 'diffs'\ndiff_dir.mkdir(exist_ok=True)\n\nhashes = {}\nfor original in gh_pages.glob('*.png'):\n    result = subprocess.run(\n        ['compare', '-metric', 'PHASH',\n         original,\n         ROOT_DIR / 'docs/_build/html' / original.name,\n         diff_dir / f'{original.stem}-diff.png'],\n        text=True, stderr=subprocess.PIPE)\n    if result.returncode == 2:  # Some kind of IO or similar error.\n        hashes[original] = (float('nan'), result.stderr)\n    elif result.stderr:  # Images were different.\n        hashes[original] = (float(result.stderr), '')\n    else:  # No differences.\n        hashes[original] = (0.0, '')\n\nwith open(summary_file, 'w+') as summary:\n    print('# Cheatsheet image comparison', file=summary)\n    print('| Filename | Perceptual Hash Difference | Error message |', file=summary)\n    print('| -------- | -------------------------- | ------------- |', file=summary)\n    for filename, (hash, message) in sorted(hashes.items()):\n        message = message.replace('\\n', ' ').replace('|', '\\\\|')\n        print(f'| {filename.name} | {hash:.05f} | {message}', file=summary)\n    print(file=summary)\n\nsubprocess.run(['git', 'worktree', 'remove', gh_pages])\n"
  },
  {
    "path": "check-links.py",
    "content": "#!/usr/bin/env python\nimport sys\n\nimport pdfx\n\n\npdf = pdfx.PDFx(sys.argv[1])\n\nrefs = [ref for ref in pdf.get_references() if ref.reftype == 'url']\n\nstatus_codes = [pdfx.downloader.get_status_code(ref.ref) for ref in refs]\n\nbroken_links = [(ref.ref, code) for ref, code in zip(refs, status_codes) if code != 200]\n\n# it seems that Twitter does not respond well to the link checker and throws a 400\nif all(['twitter.com' in url for url, _ in broken_links]):\n    sys.exit(0)\nelse:\n    print('Broken links:', broken_links)\n    sys.exit(1)\n"
  },
  {
    "path": "check-matplotlib-version.py",
    "content": "#!/usr/bin/env python\nimport matplotlib as mpl\n\n\nassert mpl.__version__ == '3.9.4'\n"
  },
  {
    "path": "check-num-pages.sh",
    "content": "#!/bin/bash\n#\n# Check that a given pdf has a certain number of pages.\n# Usage:\n#   check-num-pages.sh [pdffile] [num_pages]\n\nset -x\npdffile=$1\nnum_pages=$2\n[[ \"$(pdfinfo $pdffile | grep Pages | awk '{print $2}')\" == \"$num_pages\" ]] || exit 1\n"
  },
  {
    "path": "docs/Makefile",
    "content": "# Minimal makefile for Sphinx documentation\n#\n\n# You can set these variables from the command line, and also\n# from the environment for the first two.\nSPHINXOPTS    ?= -W\nSPHINXBUILD   ?= sphinx-build\nSOURCEDIR     = .\nBUILDDIR      = _build\n\n# Put it first so that \"make\" without argument is like \"make help\".\nhelp:\n\t@$(SPHINXBUILD) -M help \"$(SOURCEDIR)\" \"$(BUILDDIR)\" $(SPHINXOPTS) $(O)\n\nshow:\n\t@python -c \"import webbrowser; webbrowser.open_new_tab('file://$(shell pwd)/build/html/index.html')\"\n\n.PHONY: help Makefile\n\n# Catch-all target: route all unknown targets to Sphinx using the new\n# \"make mode\" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).\n%: Makefile\n\t@$(SPHINXBUILD) -M $@ \"$(SOURCEDIR)\" \"$(BUILDDIR)\" $(SPHINXOPTS) $(O)\n"
  },
  {
    "path": "docs/conf.py",
    "content": "import datetime\n\n# -- Project information -----------------------------------------------------\n\nhtml_title = 'Visualization with Python'\nproject = \"Matplotlib cheatsheets\"\ncopyright = (\n    f\"2012 - {datetime.datetime.now().year} The Matplotlib development team\"\n)\nauthor = \"Matplotlib Developers\"\n\n# -- General configuration ---------------------------------------------------\n\n# Add any Sphinx extension module names here, as strings. They can be\n# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom\n# ones.\nextensions = [\"sphinx_design\"]\n\n# Add any paths that contain templates here, relative to this directory.\n\ntemplates_path = []\n\n# List of patterns, relative to source directory, that match files and\n# directories to ignore when looking for source files.\n# This pattern also affects html_static_path and html_extra_path.\nexclude_patterns = [\"_build\", \"Thumbs.db\", \".DS_Store\"]\n\n# -- Options for HTML output -------------------------------------------------\n\nhtml_css_files = ['css/normalize.css', 'css/landing.css']\nhtml_theme = \"mpl_sphinx_theme\"\nhtml_favicon = \"_static/favicon.ico\"\nhtml_theme_options = {\n    \"navbar_links\": (\"absolute\", \"server-stable\"),\n}\nhtml_sidebars = {\n    \"**\": []\n}\n# Add any paths that contain custom static files (such as style sheets) here,\n# relative to this directory. They are copied after the theme static files,\n# so a file named \"default.css\" will overwrite the theme's \"default.css\".\nhtml_static_path = [\"_static\"]\n"
  },
  {
    "path": "docs/index.rst",
    "content": ".. title:: Matplotlib cheatsheets\n\n***********************************\nMatplotlib cheatsheets and handouts\n***********************************\n\nCheatsheets\n***********\n\n.. grid:: 2\n\n    .. grid-item::\n\n        .. image:: ../cheatsheets-1.png\n            :width: 270px\n            :align: center\n            :alt: image of first page of cheatsheets\n\n    .. grid-item::\n\n        .. image:: ../cheatsheets-2.png\n            :width: 270px\n            :align: center\n            :alt: image of second page of cheatsheets\n\n`Cheatsheets [pdf] <./cheatsheets.pdf>`_\n\n\n\nHandouts\n********\n\n.. grid:: 1 2 3 3\n\n    .. grid-item::\n\n        .. image:: ../handout-beginner.png\n            :width: 270px\n            :align: center\n            :alt: image of beginner handout\n\n        `Beginner [pdf] <./handout-beginner.pdf>`_\n\n    .. grid-item::\n\n        .. image:: ../handout-intermediate.png\n            :width: 270px\n            :align: center\n            :alt: image of intermediate handout\n\n        `Intermediate [pdf] <./handout-intermediate.pdf>`_\n\n    .. grid-item::\n\n        .. image:: ../handout-tips.png\n            :width: 270px\n            :align: center\n            :alt: image of tips handout\n\n        `Tips [pdf] <./handout-tips.pdf>`_\n\nContribute\n**********\n\nIssues, suggestions, or pull-requests gratefully accepted at\n`matplotlib/cheatsheets <https://github.com/matplotlib/cheatsheets>`_\n"
  },
  {
    "path": "fonts/.gitignore",
    "content": ".uuid\n"
  },
  {
    "path": "fonts/Makefile",
    "content": "FONT_DIRS := eb-garamond roboto roboto-mono roboto-slab source-code-pro source-sans-pro source-serif-pro pacifico\n\nEB_GARAMOND_ZIP      := https://bitbucket.org/georgd/eb-garamond/downloads/EBGaramond-0.016.zip\nROBOTO_ZIP           := https://github.com/googlefonts/roboto/releases/download/v2.138/roboto-unhinted.zip\nROBOTO_MONO_ZIP      := https://github.com/googlefonts/RobotoMono/archive/8f651634e746da6df6c2c0be73255721d24f2372.zip\nROBOTO_SLAB_ZIP      := https://github.com/googlefonts/robotoslab/archive/a65e6d00d8e3e7ee2fabef844e58fa12690384d2.zip\nSOURCE_CODE_PRO_ZIP  := https://github.com/adobe-fonts/source-code-pro/releases/download/2.038R-ro%2F1.058R-it%2F1.018R-VAR/OTF-source-code-pro-2.038R-ro-1.058R-it.zip\nSOURCE_SANS_PRO_ZIP  := https://github.com/adobe-fonts/source-sans/releases/download/2.045R-ro%2F1.095R-it/source-sans-pro-2.045R-ro-1.095R-it.zip\nSOURCE_SERIF_PRO_ZIP := https://github.com/adobe-fonts/source-serif/releases/download/3.001R/source-serif-pro-3.001R.zip\nPACIFICO             := https://raw.githubusercontent.com/googlefonts/Pacifico/refs/heads/main/fonts/ttf/Pacifico-Regular.ttf\n\nUNZIP_FLAGS := -x \"__MACOSX/*\"\n\n\n.PHONY: default\ndefault: all\n\n.PHONY: all\nall: sources\n\tmkdir -p $(FONT_DIRS)\n\tcd eb-garamond && unzip -j /tmp/eb-garamond.zip \"EBGaramond-0.016/otf/*.otf\" $(UNZIP_FLAGS)\n\tcd roboto && unzip -j /tmp/roboto.zip \"*.ttf\" $(UNZIP_FLAGS)\n\tcd roboto-mono && unzip -j /tmp/roboto-mono.zip \"RobotoMono-8f651634e746da6df6c2c0be73255721d24f2372/fonts/ttf/*.ttf\" $(UNZIP_FLAGS)\n\tcd roboto-slab && unzip -j /tmp/roboto-slab.zip \"robotoslab-a65e6d00d8e3e7ee2fabef844e58fa12690384d2/fonts/static/*.ttf\" $(UNZIP_FLAGS)\n\tcd source-code-pro && unzip -j /tmp/source-code-pro.zip \"*.otf\" $(UNZIP_FLAGS)\n\tcd source-sans-pro && unzip -j /tmp/source-sans-pro.zip \"source-sans-pro-2.045R-ro-1.095R-it/OTF/*.otf\" $(UNZIP_FLAGS)\n\tcd source-serif-pro && unzip -j /tmp/source-serif-pro.zip \"source-serif-pro-3.001R/OTF/*.otf\" $(UNZIP_FLAGS)\n\tcd pacifico && cp /tmp/pacifico.ttf .\n\n.PHONY: sources\nsources:\n\twget $(EB_GARAMOND_ZIP) -O /tmp/eb-garamond.zip\n\twget $(ROBOTO_ZIP) -O /tmp/roboto.zip\n\twget $(ROBOTO_MONO_ZIP) -O /tmp/roboto-mono.zip\n\twget $(ROBOTO_SLAB_ZIP) -O /tmp/roboto-slab.zip\n\twget $(SOURCE_CODE_PRO_ZIP) -O /tmp/source-code-pro.zip\n\twget $(SOURCE_SANS_PRO_ZIP) -O /tmp/source-sans-pro.zip\n\twget $(SOURCE_SERIF_PRO_ZIP) -O /tmp/source-serif-pro.zip\n\twget $(PACIFICO) -O /tmp/pacifico.ttf\n\n.PHONY: clean\nclean:\n\t- rm $(HOME)/.cache/matplotlib/fontlist*\n\t- rm -rf $(FONT_DIRS)\n"
  },
  {
    "path": "handout-beginner.tex",
    "content": "\\documentclass[10pt,landscape,a4paper]{article}\n\\usepackage[right=10mm, left=10mm, top=10mm, bottom=10mm]{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage[english]{babel}\n\\usepackage[rm,light]{roboto}\n\\usepackage{xcolor}\n\\usepackage{graphicx}\n\\graphicspath{{./figures/}}\n\\usepackage{multicol}\n\\usepackage{colortbl}\n\\usepackage{array}\n\\setlength\\parindent{0pt}\n\\setlength{\\tabcolsep}{2pt}\n\\baselineskip=0pt\n\\setlength\\columnsep{1em}\n\\definecolor{Gray}{gray}{0.85}\n\n% --- Listing -----------------------------------------------------------------\n\\usepackage{listings}\n\\lstset{\n  frame=tb, framesep=4pt, framerule=0pt,\n  backgroundcolor=\\color{black!5},\n  basicstyle=\\ttfamily,\n  commentstyle=\\ttfamily\\color{black!50},\n  breakatwhitespace=false,\n  breaklines=true,\n  extendedchars=true,\n  keepspaces=true,\n  language=Python,\n  rulecolor=\\color{black},\n  showspaces=false,\n  showstringspaces=false,\n  showtabs=false,\n  tabsize=2,\n  %\n  emph = { plot, scatter, imshow, bar, contourf, pie, subplots, show, savefig,\n           errorbar, boxplot, hist, set_title, set_xlabel, set_ylabel, suptitle,  },\n  emphstyle = {\\ttfamily\\bfseries}\n}\n\n% --- Fonts -------------------------------------------------------------------\n\\usepackage{fontspec}\n\\usepackage[babel=true]{microtype}\n\\defaultfontfeatures{Ligatures = TeX, Mapping = tex-text}\n\\setsansfont{Roboto} [ Path           = fonts/roboto/Roboto-,\n                       Extension      = .ttf,\n                       UprightFont    = Light,\n                       ItalicFont     = LightItalic,\n                       BoldFont       = Regular,\n                       BoldItalicFont = Italic ]\n\\setromanfont{RobotoSlab} [ Path           = fonts/roboto-slab/RobotoSlab-,\n                            Extension      = .ttf,\n                            UprightFont    = Light,\n                            BoldFont       = Bold ]\n\\setmonofont{RobotoMono} [ Path           = fonts/roboto-mono/RobotoMono-,\n                           Extension      = .ttf,\n                           Scale          = 0.90,\n                           UprightFont    = Light,\n                           ItalicFont     = LightItalic,\n                           BoldFont       = Regular,\n                           BoldItalicFont = Italic ]\n\\renewcommand{\\familydefault}{\\sfdefault}\n\n% -----------------------------------------------------------------------------\n\\begin{document}\n\\thispagestyle{empty}\n\n\\section*{\\LARGE \\rmfamily\n          Matplotlib \\textcolor{orange}{\\mdseries for beginners}}\n\n\\begin{multicols*}{3}\n\nMatplotlib is a library for making 2D plots in Python. It is designed\nwith the philosophy that you should be able to create simple plots\nwith just a few commands:\\\\\n\n\\fbox{1} \\textbf{Initialize}\n\\begin{lstlisting}\n import numpy as np\n import matplotlib.pyplot as plt\n\\end{lstlisting}\n%\n\\fbox{2} \\textbf{Prepare}\n\\begin{lstlisting}\n X = np.linspace(0, 10*np.pi, 1000)\n Y = np.sin(X)\n\\end{lstlisting}\n%\n\\fbox{3} \\textbf{Render}\n\\begin{lstlisting}\n fig, ax = plt.subplots()\n ax.plot(X, Y)\n plt.show()\n\\end{lstlisting}\n%\n\\fbox{4} \\textbf{Observe} \\medskip\\\\\n\\includegraphics[width=\\linewidth]{sine.pdf}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Choose}\n% -----------------------------------------------------------------------------\n\nMatplotlib offers several kind of plots (see Gallery): \\medskip\n\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n X = np.random.uniform(0, 1, 100)\n Y = np.random.uniform(0, 1, 100)\n ax.scatter(X, Y)\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{basic-scatter.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n X = np.arange(10)\n Y = np.random.uniform(1, 10, 10)\n ax.bar(X, Y)\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{basic-bar.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n Z = np.random.uniform(0, 1, (8, 8))\n\n ax.imshow(Z)\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{basic-imshow.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n Z = np.random.uniform(0, 1, (8, 8))\n\n ax.contourf(Z)\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{basic-contour.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n Z = np.random.uniform(0, 1, 4)\n\n ax.pie(Z)\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{basic-pie.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n Z = np.random.normal(0, 1, 100)\n\n ax.hist(Z)\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{advanced-hist.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n X = np.arange(5)\n Y = np.random.uniform(0, 1, 5)\n ax.errorbar(X, Y, Y/4)\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{advanced-errorbar.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n Z = np.random.normal(0, 1, (100, 3))\n\n ax.boxplot(Z)\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{advanced-boxplot.pdf}}\n\\end{tabular}\n\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Tweak}\n% -----------------------------------------------------------------------------\nYou can modify pretty much anything in a plot, including limits,\ncolors, markers, line width and styles, ticks and ticks labels,\ntitles, etc. \\medskip\n\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n X = np.linspace(0, 10, 100)\n Y = np.sin(X)\n ax.plot(X, Y, color=\"black\")\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{plot-color.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n X = np.linspace(0, 10, 100)\n Y = np.sin(X)\n ax.plot(X, Y, linestyle=\"--\")\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{plot-linestyle.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n X = np.linspace(0, 10, 100)\n Y = np.sin(X)\n ax.plot(X, Y, linewidth=5)\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{plot-linewidth.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n X = np.linspace(0, 10, 100)\n Y = np.sin(X)\n ax.plot(X, Y, marker=\"o\")\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{plot-marker.pdf}}\n\\end{tabular}\n\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Organize}\n% -----------------------------------------------------------------------------\n\nYou can plot several data on the same figure, but you can also split a figure\nin several subplots (named {\\em Axes}): \\medskip\n\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n X = np.linspace(0, 10, 100)\n Y1, Y2 = np.sin(X), np.cos(X)\n ax.plot(X, Y1, X, Y2)\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{plot-multi.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n fig, (ax1, ax2) = plt.subplots(2, 1)\n ax1.plot(X, Y1, color=\"C1\")\n ax2.plot(X, Y2, color=\"C0\")\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{plot-vsplit.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n fig, (ax1, ax2) = plt.subplots(1, 2)\n ax1.plot(Y1, X, color=\"C1\")\n ax2.plot(Y2, X, color=\"C0\")\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{plot-hsplit.pdf}}\n\\end{tabular}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Label \\mdseries (everything)}\n% -----------------------------------------------------------------------------\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n ax.plot(X, Y)\n fig.suptitle(None)\n ax.set_title(\"A Sine wave\")\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{plot-title.pdf}}\n\\end{tabular}\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n ax.plot(X, Y)\n ax.set_ylabel(None)\n ax.set_xlabel(\"Time\")\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{plot-xlabel.pdf}}\n\\end{tabular}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Explore}\n% -----------------------------------------------------------------------------\n\nFigures are shown with a graphical user interface that allows to zoom\nand pan the figure, to navigate between the different views and to\nshow the value under the mouse.\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Save \\mdseries (bitmap or vector format)}\n% -----------------------------------------------------------------------------\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n fig.savefig(\"my-first-figure.png\", dpi=300)\n fig.savefig(\"my-first-figure.pdf\")\n\\end{lstlisting}\n%\n\\vfill\n%\n{\\scriptsize\n  Matplotlib 3.9.4 handout for beginners.\n  Copyright (c) 2021 Matplotlib Development Team.\n  Released under a CC-BY 4.0 International License.\n  Supported by NumFOCUS.\n\\par}\n\n\\end{multicols*}\n\\end{document}\n"
  },
  {
    "path": "handout-intermediate.tex",
    "content": "\\documentclass[10pt,landscape,a4paper]{article}\n\\usepackage[right=10mm, left=10mm, top=10mm, bottom=10mm]{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage[english]{babel}\n\\usepackage[rm,light]{roboto}\n\\usepackage{xcolor}\n\\usepackage{graphicx}\n\\graphicspath{{./figures/}}\n\\usepackage{multicol}\n\\usepackage{colortbl}\n\\usepackage{array}\n\\setlength\\parindent{0pt}\n\\setlength{\\tabcolsep}{2pt}\n\\baselineskip=0pt\n\\setlength\\columnsep{1em}\n\\definecolor{Gray}{gray}{0.85}\n\n% --- Listing -----------------------------------------------------------------\n\\usepackage{listings}\n\\lstset{\n  frame=tb, framesep=4pt, framerule=0pt,\n  backgroundcolor=\\color{black!5},\n  basicstyle=\\ttfamily,\n  commentstyle=\\ttfamily\\color{black!50},\n  breakatwhitespace=false,\n  breaklines=true,\n  extendedchars=true,\n  keepspaces=true,\n  language=Python,\n  rulecolor=\\color{black},\n  showspaces=false,\n  showstringspaces=false,\n  showtabs=false,\n  tabsize=2,\n  %\n  emph = { plot, scatter, imshow, bar, contourf, pie, subplots, spines,\n    add_gridspec, add_subplot, set_xscale, set_minor_locator,\n    annotate, set_minor_formatter, tick_params, fill_betweenx, text, legend,\n    errorbar, boxplot, hist, title, xlabel, ylabel, suptitle },\n  emphstyle = {\\ttfamily\\bfseries}\n}\n\n% --- Fonts -------------------------------------------------------------------\n\\usepackage{fontspec}\n\\usepackage[babel=true]{microtype}\n\\defaultfontfeatures{Ligatures = TeX, Mapping = tex-text}\n\\setsansfont{Roboto} [ Path           = fonts/roboto/Roboto-,\n                       Extension      = .ttf,\n                       UprightFont    = Light,\n                       ItalicFont     = LightItalic,\n                       BoldFont       = Regular,\n                       BoldItalicFont = Italic ]\n\\setromanfont{RobotoSlab} [ Path           = fonts/roboto-slab/RobotoSlab-,\n                            Extension      = .ttf,\n                            UprightFont    = Light,\n                            BoldFont       = Bold ]\n\\setmonofont{RobotoMono} [ Path           = fonts/roboto-mono/RobotoMono-,\n                           Extension      = .ttf,\n                           Scale          = 0.90,\n                           UprightFont    = Light,\n                           ItalicFont     = LightItalic,\n                           BoldFont       = Regular,\n                           BoldItalicFont = Italic ]\n\\renewcommand{\\familydefault}{\\sfdefault}\n\n% -----------------------------------------------------------------------------\n\\begin{document}\n\\thispagestyle{empty}\n\n\\section*{\\LARGE \\rmfamily\n          Matplotlib \\textcolor{orange}{\\mdseries for intermediate users}}\n\n\\begin{multicols*}{3}\n\nA matplotlib figure is composed of a hierarchy of elements that forms\nthe actual figure. Each element can be modified. \\medskip\n\n\\includegraphics[width=\\linewidth]{anatomy.pdf}\n\n\\subsection*{\\rmfamily Figure, axes \\& spines}\n\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n fig, axs = plt.subplots(3, 3)\n axs[0, 0].set_facecolor(\"#ddddff\")\n axs[2, 2].set_facecolor(\"#ffffdd\")\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{layout-subplot-color.pdf}}\n\\end{tabular}\n\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n gs = fig.add_gridspec(3, 3)\n ax = fig.add_subplot(gs[0, :])\n ax.set_facecolor(\"#ddddff\")\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{layout-gridspec-color.pdf}}\n\\end{tabular}\n\n% -----------------------------------------------------------------------------\n\\begin{tabular}{@{}m{.821\\linewidth}m{.169\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n fig, ax = plt.subplots()\n ax.spines[\"top\"].set_color(\"None\")\n ax.spines[\"right\"].set_color(\"None\")\n\\end{lstlisting}\n& \\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{layout-spines.pdf}}\n\\end{tabular}\n\n\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Ticks \\& labels}\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\small]\n from mpl.ticker import MultipleLocator as ML\n from mpl.ticker import ScalarFormatter as SF\n ax.xaxis.set_minor_locator(ML(0.2))\n ax.xaxis.set_minor_formatter(SF())\n ax.tick_params(axis='x',which='minor',rotation=90)\n\\end{lstlisting}\n\\includegraphics[width=\\linewidth]{tick-multiple-locator.pdf}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Lines \\& markers}\n\n\\begin{lstlisting}\n X = np.linspace(0.1, 10*np.pi, 1000)\n Y = np.sin(X)\n ax.plot(X, Y, \"C1o:\", markevery=50, mec=\"1.0\")\n\\end{lstlisting}\n\\includegraphics[width=\\linewidth]{sine-marker.pdf}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Scales \\& projections}\n\n\\begin{lstlisting}\n fig, ax = plt.subplots()\n ax.set_xscale(\"log\")\n ax.plot(X, Y, \"C1o-\", markevery=50, mec=\"1.0\")\n\\end{lstlisting}\n\\includegraphics[width=\\linewidth]{sine-logscale.pdf}\n\n\\subsection*{\\rmfamily Text \\& ornaments}\n\\begin{lstlisting}[]\n ax.fill_betweenx([-1, 1], [0], [2*np.pi])\n ax.text(0, -1, r\" Period $\\Phi$\")\n\\end{lstlisting}\n\\includegraphics[width=\\linewidth]{sine-period.pdf}\n\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Legend}\n\\begin{lstlisting}[]\n ax.plot(X, np.sin(X), \"C0\", label=\"Sine\")\n ax.plot(X, np.cos(X), \"C1\", label=\"Cosine\")\n ax.legend(bbox_to_anchor=(0,1,1,.1), ncol=2,\n           mode=\"expand\", loc=\"lower left\")\n\\end{lstlisting}\n\\includegraphics[width=\\linewidth]{sine-legend.pdf}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Annotation}\n\\begin{lstlisting}[]\n ax.annotate(\"A\", (X[250],Y[250]), (X[250],-1),\n   ha=\"center\", va=\"center\", arrowprops={\n     \"arrowstyle\": \"->\", \"color\": \"C1\"})\n\\end{lstlisting}\n\\includegraphics[width=\\linewidth]{sine-annotate.pdf}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Colors}\n\nAny color can be used, but Matplotlib offers sets of colors:\\\\\n\\includegraphics[width=\\linewidth]{colors-cycle.pdf} \\smallskip\n\\includegraphics[width=\\linewidth]{colors-grey.pdf}\\\\\n%As well as nice colormaps (viridis an magma):\\\\\n%\\includegraphics[width=\\linewidth]{colormap-viridis.pdf} \\smallskip\n%\\includegraphics[width=\\linewidth]{colormap-magma.pdf} \\medskip\n\n% -----------------------------------------------------------------------------\n\\vspace{-1em}\n\\subsection*{\\rmfamily Size \\& DPI}\n\nConsider a square figure to be included in a two-column A4 paper with\n2\\,cm margins on each side and a column separation of 1\\,cm. The width of\na figure is (21 - 2*2 - 1)/2 = 8\\,cm. One inch being 2.54\\,cm, figure size\nshould be 3.15$\\times$3.15\\,in.\n\\begin{lstlisting}[]\n fig = plt.figure(figsize=(3.15, 3.15), dpi=50)\n plt.savefig(\"figure.pdf\", dpi=600)\n\\end{lstlisting}\n\n\n\\vfill\n%\n{\\scriptsize\n  Matplotlib 3.9.4 handout for intermediate users.\n  Copyright (c) 2021 Matplotlib Development Team.\n  Released under a CC-BY 4.0 International License.\n  Supported by NumFOCUS.\n\\par}\n\n\n\n\\end{multicols*}\n\\end{document}\n"
  },
  {
    "path": "handout-tips.tex",
    "content": "\\documentclass[10pt,landscape,a4paper]{article}\n\\usepackage[right=10mm, left=10mm, top=10mm, bottom=10mm]{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage[english]{babel}\n\\usepackage[rm,light]{roboto}\n\\usepackage{xcolor}\n\\usepackage{graphicx}\n\\graphicspath{{./figures/}}\n\\usepackage{multicol}\n\\usepackage{colortbl}\n\\usepackage{array}\n\\setlength\\parindent{0pt}\n\\setlength{\\tabcolsep}{2pt}\n\\baselineskip=0pt\n\\setlength\\columnsep{1em}\n\\definecolor{Gray}{gray}{0.85}\n\n% --- Listing -----------------------------------------------------------------\n\\usepackage{listings}\n\\lstset{\n  frame=tb, framesep=4pt, framerule=0pt,\n  backgroundcolor=\\color{black!5},\n  basicstyle=\\ttfamily\\footnotesize,\n  commentstyle=\\ttfamily\\color{black!50},\n  breakatwhitespace=false,\n  breaklines=true,\n  extendedchars=true,\n  keepspaces=true,\n  language=Python,\n  rulecolor=\\color{black},\n  showspaces=false,\n  showstringspaces=false,\n  showtabs=false,\n  tabsize=2,\n  %\n  emph = {\n    plot, scatter, imshow, bar, contourf, pie, subplots, spines,\n    add_gridspec, add_subplot, set_xscale, set_minor_locator, linestyle,\n    dash_capstyle, projection, Stroke, Normal, add_axes, label, savefig,\n    get_cmap, histtype, annotate, set_minor_formatter, tick_params,\n    fill_betweenx, text, legend, errorbar, boxplot, hist, title, xlabel,\n    ylabel, suptitle, fraction, pad, set_fontname, get_xticklabels},\n  emphstyle = {\\ttfamily\\bfseries}\n}\n\n% --- Fonts -------------------------------------------------------------------\n\\usepackage{fontspec}\n\\usepackage[babel=true]{microtype}\n\\defaultfontfeatures{Ligatures = TeX, Mapping = tex-text}\n\\setsansfont{Roboto} [ Path           = fonts/roboto/Roboto-,\n                       Extension      = .ttf,\n                       UprightFont    = Light,\n                       ItalicFont     = LightItalic,\n                       BoldFont       = Regular,\n                       BoldItalicFont = Italic ]\n\\setromanfont{RobotoSlab} [ Path           = fonts/roboto-slab/RobotoSlab-,\n                            Extension      = .ttf,\n                            UprightFont    = Light,\n                            BoldFont       = Bold ]\n\\setmonofont{RobotoMono} [ Path           = fonts/roboto-mono/RobotoMono-,\n                           Extension      = .ttf,\n                           Scale          = 0.90,\n                           UprightFont    = Light,\n                           ItalicFont     = LightItalic,\n                           BoldFont       = Regular,\n                           BoldItalicFont = Italic ]\n\\renewcommand{\\familydefault}{\\sfdefault}\n\n% -----------------------------------------------------------------------------\n\\begin{document}\n\\thispagestyle{empty}\n\n\\section*{\\LARGE \\rmfamily\n          Matplotlib \\textcolor{orange}{\\mdseries tips \\& tricks}}\n\n\\begin{multicols*}{3}\n\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Transparency}\n\nScatter plots can be enhanced by using transparency (alpha) in order\nto show area with higher density. Multiple scatter plots can be\nused to delineate a frontier.\n\n\\begin{tabular}{@{}m{.774\\linewidth}m{.216\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n X = np.random.normal(-1, 1, 500)\n Y = np.random.normal(-1, 1, 500)\n ax.scatter(X, Y, 50, \"0.0\", lw=2) # optional\n ax.scatter(X, Y, 50, \"1.0\", lw=0) # optional\n ax.scatter(X, Y, 40, \"C1\",  lw=0, alpha=0.1)\n\\end{lstlisting} &\n\\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{tip-transparency.pdf}}\n\\end{tabular}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Rasterization}\nIf your figure has many graphical elements, such as a huge\nscatter, you can rasterize them to save memory and keep other elements\nin vector format.\n\\begin{lstlisting}\n X = np.random.normal(-1, 1, 10_000)\n Y = np.random.normal(-1, 1, 10_000)\n ax.scatter(X, Y, rasterized=True)\n fig.savefig(\"rasterized-figure.pdf\", dpi=600)\n\\end{lstlisting}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Offline rendering}\n\nUse the Agg backend to render a figure directly in an array.\n\\begin{lstlisting}\n from matplotlib.backends.backend_agg import FigureCanvas\n canvas = FigureCanvas(Figure()))\n ... # draw some stuff\n canvas.draw()\n Z = np.array(canvas.renderer.buffer_rgba())\n\\end{lstlisting}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Range of continuous colors}\n\nYou can use colormap to pick from a range of continuous colors.\n\n\\begin{tabular}{@{}m{.774\\linewidth}m{.216\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n X = np.random.randn(1000, 4)\n cmap = plt.get_cmap(\"Oranges\")\n colors = cmap([0.2, 0.4, 0.6, 0.8])\n\n ax.hist(X, 2, histtype='bar', color=colors)\n\\end{lstlisting} &\n\\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{tip-color-range.pdf}}\n\\end{tabular}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Text outline}\nUse text outline to make text more visible.\n\n\\begin{tabular}{@{}m{.774\\linewidth}m{.216\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n import matplotlib.patheffects as fx\n text = ax.text(0.5, 0.1, \"Label\")\n text.set_path_effects([\n   fx.Stroke(linewidth=3, foreground='1.0'),\n   fx.Normal()])\n\\end{lstlisting} &\n\\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{tip-outline.pdf}}\n\\end{tabular}\n\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Multiline plot}\nYou can plot several lines at once using {\\em None} as separator.\n\n\\begin{lstlisting}\n X,Y = [], []\n for x in np.linspace(0, 10*np.pi, 100):\n   X.extend([x, x, None]), Y.extend([0, sin(x), None])\n ax.plot(X, Y, \"black\")\n\\end{lstlisting}\n\\includegraphics[width=\\linewidth]{tip-multiline.pdf}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Dotted lines}\nTo have rounded dotted lines, use a custom {\\ttfamily linestyle} and\nmodify {\\ttfamily dash\\_capstyle}.\n\\begin{lstlisting}\n ax.plot([0, 1], [0, 0], \"C1\",\n        linestyle=(0, (0.01, 1)), dash_capstyle=\"round\")\n ax.plot([0, 1], [1, 1], \"C1\",\n        linestyle=(0, (0.01, 2)), dash_capstyle=\"round\")\n\\end{lstlisting}\n\\includegraphics[width=\\linewidth]{tip-dotted.pdf}\n\n% -----------------------------------------------------------------------------\n\\subsection*{\\rmfamily Combining axes}\nYou can use overlaid axes with different projections.\n\n\\begin{tabular}{@{}m{.774\\linewidth}m{.216\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n ax1 = fig.add_axes([0, 0, 1, 1],\n                    label=\"cartesian\")\n ax2 = fig.add_axes([0, 0, 1, 1],\n                    label=\"polar\",\n                    projection=\"polar\")\n\\end{lstlisting} &\n\\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{tip-dual-axis.pdf}}\n\\end{tabular}\n\n\\subsection*{\\rmfamily Colorbar adjustment}\nYou can adjust a colorbar's size when adding it.\n\n\\begin{tabular}{@{}m{.754\\linewidth}m{.236\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n im = ax.imshow(Z)\n\n cb = plt.colorbar(im,\n         fraction=0.046, pad=0.04)\n cb.set_ticks([])\n\\end{lstlisting} &\n\\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{tip-colorbar.pdf}}\n\\end{tabular}\n\n\\subsection*{\\rmfamily Taking advantage of typography}\nYou can use a condensed font such as Roboto\nCondensed to save space on tick labels.\n\\begin{lstlisting}\n for tick in ax.get_xticklabels(which='both'):\n     tick.set_fontname(\"Roboto Condensed\")\n\\end{lstlisting}\n\\includegraphics[width=\\linewidth]{tip-font-family.pdf}\n\n\\subsection*{\\rmfamily Getting rid of margins}\nOnce your figure is finished, you can call {\\ttfamily tight\\_layout()}\nto remove white margins. If there are remaining margins, you can use\nthe {\\ttfamily pdfcrop} utility (comes with TeX live).\n\n\n\\subsection*{\\rmfamily Hatching}\nYou can achieve a nice visual effect with thick hatch patterns.\n\n\\begin{tabular}{@{}m{.774\\linewidth}m{.216\\linewidth}}\n\\begin{lstlisting}[belowskip=-\\baselineskip]\n cmap = plt.get_cmap(\"Oranges\")\n plt.rcParams['hatch.color'] = cmap(0.2)\n plt.rcParams['hatch.linewidth'] = 8\n ax.bar(X, Y, color=cmap(0.6), hatch=\"/\")\n\\end{lstlisting} &\n\\raisebox{-0.75em}{\\includegraphics[width=\\linewidth]{tip-hatched.pdf}}\n\\end{tabular}\n\n\n\\subsection*{\\rmfamily Read the documentation}\n\nMatplotlib comes with an extensive documentation explaining the\ndetails of each command and is generally accompanied by examples.\nTogether with the huge online gallery, this documentation is a\ngold-mine.\n\n\\vfill\n%\n{\\scriptsize\n  Matplotlib 3.9.4 handout for tips \\& tricks.\n  Copyright (c) 2021 Matplotlib Development Team.\n  Released under a CC-BY 4.0 International License.\n  Supported by NumFOCUS.\n\\par}\n\n\n\n\\end{multicols*}\n\\end{document}\n"
  },
  {
    "path": "logos/mpl-logos2.py",
    "content": "\"\"\"\n===============\nMatplotlib logo\n===============\n\nThis example generates the current matplotlib logo.\n\"\"\"\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.cm as cm\nimport matplotlib.font_manager\nfrom matplotlib.patches import Rectangle, PathPatch\nfrom matplotlib.textpath import TextPath\nimport matplotlib.transforms as mtrans\n\nMPL_BLUE = '#11557c'\n\n\ndef get_font_properties():\n    # The original font is Calibri, if that is not installed, we fall back\n    # to Carlito, which is metrically equivalent.\n    if 'Calibri' in matplotlib.font_manager.findfont('Calibri:bold'):\n        return matplotlib.font_manager.FontProperties(family='Calibri',\n                                                      weight='bold')\n    if 'Carlito' in matplotlib.font_manager.findfont('Carlito:bold'):\n        print('Original font not found. Falling back to Carlito. '\n              'The logo text will not be in the correct font.')\n        return matplotlib.font_manager.FontProperties(family='Carlito',\n                                                      weight='bold')\n    print('Original font not found. '\n          'The logo text will not be in the correct font.')\n    return None\n\n\ndef create_icon_axes(fig, ax_position, lw_bars, lw_grid, lw_border, rgrid):\n    \"\"\"\n    Create a polar axes containing the matplotlib radar plot.\n\n    Parameters\n    ----------\n    fig : matplotlib.figure.Figure\n        The figure to draw into.\n    ax_position : (float, float, float, float)\n        The position of the created Axes in figure coordinates as\n        (x, y, width, height).\n    lw_bars : float\n        The linewidth of the bars.\n    lw_grid : float\n        The linewidth of the grid.\n    lw_border : float\n        The linewidth of the Axes border.\n    rgrid : array-like\n        Positions of the radial grid.\n\n    Returns\n    -------\n    ax : matplotlib.axes.Axes\n        The created Axes.\n    \"\"\"\n    with plt.rc_context({'axes.edgecolor': MPL_BLUE,\n                         'axes.linewidth': lw_border}):\n        ax = fig.add_axes(ax_position, projection='polar')\n        ax.set_axisbelow(True)\n\n        N = 7\n        arc = 2. * np.pi\n        theta = np.arange(0.0, arc, arc / N)\n        radii = np.array([2, 6, 8, 7, 4, 5, 8])\n        width = np.pi / 4 * np.array([0.4, 0.4, 0.6, 0.8, 0.2, 0.5, 0.3])\n        bars = ax.bar(theta, radii, width=width, bottom=0.0, align='edge',\n                      edgecolor='0.3', lw=lw_bars)\n        for r, bar in zip(radii, bars):\n            color = *cm.jet(r / 10.)[:3], 0.6  # color from jet with alpha=0.6\n            bar.set_facecolor(color)\n\n        ax.tick_params(labelbottom=False, labeltop=False,\n                       labelleft=False, labelright=False)\n\n        ax.grid(lw=lw_grid, color='0.9')\n        ax.set_rmax(9)\n        ax.set_yticks(rgrid)\n\n        # the actual visible background - extends a bit beyond the axis\n        ax.add_patch(Rectangle((0, 0), arc, 9.58,\n                               facecolor='white', zorder=0,\n                               clip_on=False, in_layout=False))\n        return ax\n\n\ndef create_text_axes(fig, height_px):\n    \"\"\"Create an axes in *fig* that contains 'matplotlib' as Text.\"\"\"\n    ax = fig.add_axes((0, 0, 1, 1))\n    ax.set_aspect(\"equal\")\n    ax.set_axis_off()\n\n    path = TextPath((0, 0), \"matplotlib\", size=height_px * 0.8,\n                    prop=get_font_properties())\n\n    fp = get_font_properties()\n    fp.set_weight('light')\n    path1 = TextPath((80, -13), 'Cheat sheet', size=height_px * 0.12,\n                     prop=fp)\n    path2 = TextPath((310, -13), f'Version {matplotlib. __version__}',\n                     size=height_px * 0.12,\n                     prop=fp)\n\n    angle = 4.25  # degrees\n    trans = mtrans.Affine2D().skew_deg(angle, 0)\n\n    patch = PathPatch(path, transform=trans + ax.transData, color=MPL_BLUE,\n                      lw=0)\n    patch1 = PathPatch(path1, transform=trans + ax.transData, color=MPL_BLUE,\n                       lw=0)\n    patch2 = PathPatch(path2, color=MPL_BLUE,\n                       lw=0)\n\n    ax.add_patch(patch)\n    ax.add_patch(patch1)\n    ax.add_patch(patch2)\n    ax.autoscale()\n\n\ndef make_logo(height_px, lw_bars, lw_grid, lw_border, rgrid, with_text=False):\n    \"\"\"\n    Create a full figure with the Matplotlib logo.\n\n    Parameters\n    ----------\n    height_px : int\n        Height of the figure in pixel.\n    lw_bars : float\n        The linewidth of the bar border.\n    lw_grid : float\n        The linewidth of the grid.\n    lw_border : float\n        The linewidth of icon border.\n    rgrid : sequence of float\n        The radial grid positions.\n    with_text : bool\n        Whether to draw only the icon or to include 'matplotlib' as text.\n    \"\"\"\n    dpi = 100\n    height = height_px / dpi\n    figsize = (5 * height, height) if with_text else (height, height)\n    fig = plt.figure(figsize=figsize, dpi=dpi)\n    fig.patch.set_alpha(0)\n\n    if with_text:\n        create_text_axes(fig, height_px)\n    ax_pos = (0.535, 0.12, .17, 0.75) if with_text else (0.03, 0.03, .94, .94)\n    ax = create_icon_axes(fig, ax_pos, lw_bars, lw_grid, lw_border, rgrid)\n\n    fig.savefig('mpl-logo2.pdf')\n\n    return fig, ax\n\n\n##############################################################################\n# A large logo:\n\nmake_logo(height_px=110, lw_bars=0.7, lw_grid=0.5, lw_border=1,\n          rgrid=[1, 3, 5, 7])\n\n##############################################################################\n# A small 32px logo:\n\nmake_logo(height_px=32, lw_bars=0.3, lw_grid=0.3, lw_border=0.3, rgrid=[5])\n\n##############################################################################\n# A large logo including text, as used on the matplotlib website.\n\nmake_logo(height_px=110, lw_bars=0.7, lw_grid=0.5, lw_border=1,\n          rgrid=[1, 3, 5, 7], with_text=True)\n# plt.show()\n"
  },
  {
    "path": "requirements/Makefile",
    "content": ".PHONY: default\ndefault: all\n\n.PHONY: all\nall: requirements.txt\n\n.PHONY: install\ninstall: requirements.txt\n\tpip-sync $^\n\n%.txt: %.in\n\tpip-compile $<\n"
  },
  {
    "path": "requirements/requirements.in",
    "content": "autopep8\nbump2version\ncartopy==0.22.0\nflake8\nmatplotlib==3.9.4\npillow>=9\npdfx\npip-tools\npre-commit\nscipy\n# Docs\nmpl-sphinx-theme~=3.9.0\npydata-sphinx-theme==0.13.3\nsphinx\nsphinx-design\n"
  },
  {
    "path": "requirements/requirements.txt",
    "content": "#\n# This file is autogenerated by pip-compile with Python 3.10\n# by the following command:\n#\n#    pip-compile requirements.in\n#\naccessible-pygments==0.0.4\n    # via pydata-sphinx-theme\nalabaster==0.7.16\n    # via sphinx\nautopep8==2.0.4\n    # via -r requirements.in\nbabel==2.14.0\n    # via\n    #   pydata-sphinx-theme\n    #   sphinx\nbeautifulsoup4==4.12.3\n    # via pydata-sphinx-theme\nbuild==1.0.3\n    # via pip-tools\nbump2version==1.0.1\n    # via -r requirements.in\ncartopy==0.22.0\n    # via -r requirements.in\ncertifi==2024.7.4\n    # via\n    #   pyproj\n    #   requests\ncffi==1.16.0\n    # via cryptography\ncfgv==3.4.0\n    # via pre-commit\nchardet==4.0.0\n    # via\n    #   pdfminer-six\n    #   pdfx\ncharset-normalizer==3.3.2\n    # via requests\nclick==8.1.7\n    # via pip-tools\ncontourpy==1.2.0\n    # via matplotlib\ncryptography==44.0.1\n    # via pdfminer-six\ncycler==0.12.1\n    # via matplotlib\ndistlib==0.3.8\n    # via virtualenv\ndocutils==0.20.1\n    # via\n    #   pydata-sphinx-theme\n    #   sphinx\nfilelock==3.13.1\n    # via virtualenv\nflake8==7.0.0\n    # via -r requirements.in\nfonttools==4.47.2\n    # via matplotlib\nidentify==2.5.33\n    # via pre-commit\nidna==3.7\n    # via requests\nimagesize==1.4.1\n    # via sphinx\njinja2==3.1.5\n    # via sphinx\nkiwisolver==1.4.5\n    # via matplotlib\nmarkupsafe==2.1.4\n    # via jinja2\nmatplotlib==3.9.4\n    # via\n    #   -r requirements.in\n    #   cartopy\n    #   mpl-sphinx-theme\nmccabe==0.7.0\n    # via flake8\nmpl-sphinx-theme==3.9.0\n    # via -r requirements.in\nnodeenv==1.8.0\n    # via pre-commit\nnumpy==1.26.3\n    # via\n    #   cartopy\n    #   contourpy\n    #   matplotlib\n    #   scipy\n    #   shapely\npackaging==23.2\n    # via\n    #   build\n    #   cartopy\n    #   matplotlib\n    #   pydata-sphinx-theme\n    #   sphinx\npdfminer-six==20201018\n    # via pdfx\npdfx==1.4.1\n    # via -r requirements.in\npillow==10.3.0\n    # via\n    #   -r requirements.in\n    #   matplotlib\npip-tools==7.3.0\n    # via -r requirements.in\nplatformdirs==4.2.0\n    # via virtualenv\npre-commit==3.6.0\n    # via -r requirements.in\npycodestyle==2.11.1\n    # via\n    #   autopep8\n    #   flake8\npycparser==2.21\n    # via cffi\npydata-sphinx-theme==0.13.3\n    # via\n    #   -r requirements.in\n    #   mpl-sphinx-theme\npyflakes==3.2.0\n    # via flake8\npygments==2.17.2\n    # via\n    #   accessible-pygments\n    #   pydata-sphinx-theme\n    #   sphinx\npyparsing==3.1.1\n    # via matplotlib\npyproj==3.6.1\n    # via cartopy\npyproject-hooks==1.0.0\n    # via build\npyshp==2.3.1\n    # via cartopy\npython-dateutil==2.8.2\n    # via matplotlib\npyyaml==6.0.1\n    # via pre-commit\nrequests==2.32.4\n    # via sphinx\nscipy==1.12.0\n    # via -r requirements.in\nshapely==2.0.2\n    # via cartopy\nsix==1.16.0\n    # via python-dateutil\nsnowballstemmer==2.2.0\n    # via sphinx\nsortedcontainers==2.4.0\n    # via pdfminer-six\nsoupsieve==2.5\n    # via beautifulsoup4\nsphinx==7.2.6\n    # via\n    #   -r requirements.in\n    #   pydata-sphinx-theme\n    #   sphinx-design\nsphinx-design==0.5.0\n    # via -r requirements.in\nsphinxcontrib-applehelp==1.0.8\n    # via sphinx\nsphinxcontrib-devhelp==1.0.6\n    # via sphinx\nsphinxcontrib-htmlhelp==2.0.5\n    # via sphinx\nsphinxcontrib-jsmath==1.0.1\n    # via sphinx\nsphinxcontrib-qthelp==1.0.7\n    # via sphinx\nsphinxcontrib-serializinghtml==1.1.10\n    # via sphinx\ntomli==2.0.1\n    # via\n    #   autopep8\n    #   build\n    #   pip-tools\n    #   pyproject-hooks\ntyping-extensions==4.9.0\n    # via pydata-sphinx-theme\nurllib3==2.5.0\n    # via requests\nvirtualenv==20.26.6\n    # via pre-commit\nwheel==0.42.0\n    # via pip-tools\n\n# The following packages are considered to be unsafe in a requirements file:\n# pip\n# setuptools\n"
  },
  {
    "path": "scripts/adjustements.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as mpatches\nfrom matplotlib.collections import PatchCollection\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n])\nmpl.rc('font', size=4)\nmpl.rc('lines', linewidth=0.5)\nmpl.rc('patch', linewidth=0.5)\n\n\nsubplots_kw = dict(\n    figsize=(5.7/2.54, 5.7/2.54 * 95/115),\n    subplot_kw=dict(\n        frameon=False,\n        aspect=1,\n        xlim=(0-5, 100+10),\n        ylim=(-10, 80+5),\n        xticks=[],\n        yticks=[],\n    ),\n)\n\n(fig, ax) = plt.subplots(**subplots_kw)\n\nbox = mpatches.FancyBboxPatch(\n    (0, 0), 100, 83, mpatches.BoxStyle(\"Round\", pad=0, rounding_size=2),\n    facecolor=\"0.9\", edgecolor=\"black\")\nax.add_artist(box)\n\nbox = mpatches.FancyBboxPatch(\n    (0, 0), 100, 75, mpatches.BoxStyle(\"Round\", pad=0, rounding_size=0),\n    facecolor=\"white\", edgecolor=\"black\")\nax.add_artist(box)\n\n\nbox = mpatches.Rectangle(\n    (5, 5), 45, 30, zorder=10,\n    facecolor=\"white\", edgecolor=\"black\")\nax.add_artist(box)\n\nbox = mpatches.Rectangle(\n    (5, 40), 45, 30, zorder=10,\n    facecolor=\"white\", edgecolor=\"black\")\nax.add_artist(box)\n\nbox = mpatches.Rectangle(\n    (55, 5), 40, 65, zorder=10,\n    facecolor=\"white\", edgecolor=\"black\")\nax.add_artist(box)\n\n# Window button\nX, Y = [5, 10, 15], [79, 79, 79]\nplt.scatter(X, Y, s=20, zorder=10,\n            edgecolor=\"black\", facecolor=\"white\")\n\n\n# Window size extension\nX, Y = [0, 0], [0, -8]\nplt.plot(X, Y, color=\"black\", linestyle=\":\", clip_on=False)\n\nX, Y = [100, 100], [0, -8]\nplt.plot(X, Y, color=\"black\", linestyle=\":\", clip_on=False)\n\nX, Y = [100, 108], [0, 0]\nplt.plot(X, Y, color=\"black\", linestyle=\":\", clip_on=False)\n\nX, Y = [100, 108], [75, 75]\nplt.plot(X, Y, color=\"black\", linestyle=\":\", clip_on=False)\n\n\ndef ext_arrow(p0, p1, p2, p3):\n    p0, p1 = np.asarray(p0), np.asarray(p1)\n    p2, p3 = np.asarray(p2), np.asarray(p3)\n    ax.arrow(*p0, *(p1-p0), zorder=20, linewidth=0,\n             length_includes_head=True, width=.4,\n             head_width=2, head_length=2, color=\"black\")\n    ax.arrow(*p3, *(p2-p3), zorder=20, linewidth=0,\n             length_includes_head=True, width=.4,\n             head_width=2, head_length=2, color=\"black\")\n    plt.plot([p1[0], p2[0]], [p1[1], p2[1]], linewidth=.5, color=\"black\")\n\n\ndef int_arrow(p0, p1):\n    p0, p1 = np.asarray(p0), np.asarray(p1)\n    ax.arrow(*((p0+p1)/2), *((p1-p0)/2), zorder=20, linewidth=0,\n             length_includes_head=True, width=.4,\n             head_width=2, head_length=2, color=\"black\")\n    ax.arrow(*((p0+p1)/2), *(-(p1-p0)/2), zorder=20, linewidth=0,\n             length_includes_head=True, width=.4,\n             head_width=2, head_length=2, color=\"black\")\n\n\nx = 0\ny = 10\next_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) )\nax.text(x+9.5, y, \"left\", ha=\"left\", va=\"center\", zorder=20)\n\nx += 50\next_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) )\nax.text(x-4.5, y, \"wspace\", ha=\"right\", va=\"center\", zorder=20)\n\nx += 45\next_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) )\nax.text(x-4.5, y, \"right\", ha=\"right\", va=\"center\", zorder=20)\n\ny = 0\nx = 25\next_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) )\nax.text(x, y+9.5, \"bottom\", ha=\"center\", va=\"bottom\", zorder=20)\n\ny += 35\next_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) )\nax.text(x, y-4.5, \"hspace\", ha=\"center\", va=\"top\", zorder=20)\n\ny += 35\next_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) )\nax.text(x, y-4.5, \"top\", ha=\"center\", va=\"top\", zorder=20)\n\nint_arrow((0, -5), (100, -5))\nax.text(50, -5, \"figure width\", backgroundcolor=\"white\", zorder=30,\n        ha=\"center\", va=\"center\")\n\nint_arrow((105, 0), (105, 75))\nax.text(105, 75/2, \"figure height\", backgroundcolor=\"white\", zorder=30,\n        rotation=\"vertical\", ha=\"center\", va=\"center\")\n\nint_arrow((55, 62.5), (95, 62.5))\nax.text(75, 62.5, \"axes width\", backgroundcolor=\"white\", zorder=30,\n        ha=\"center\", va=\"center\")\n\nint_arrow((62.5, 5), (62.5, 70))\nax.text(62.5, 35, \"axes height\", backgroundcolor=\"white\", zorder=30,\n        rotation=\"vertical\", ha=\"center\", va=\"center\")\n\n\nfig.savefig(ROOT_DIR / \"figures/adjustments.pdf\")\n"
  },
  {
    "path": "scripts/advanced-plots.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\n\n# Script to generate all the advanced plots\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n    ROOT_DIR / 'styles/plotlet.mplstyle',\n])\n\n\nsubplot_kw = dict(\n    xlim=(0, 8), xticks=np.arange(1, 8),\n    ylim=(0, 8), yticks=np.arange(1, 8),\n)\n\n# Step plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nX = np.linspace(0, 10, 16)\nY = 4 + 2*np.sin(2*X)\nax.step(X, Y, color=\"C1\")\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/advanced-step.pdf\")\n\n# Violin plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(10)\nD = np.random.normal((3, 5, 4), (0.75, 1.00, 0.75), (200, 3))\nVP = ax.violinplot(D, [2, 4, 6], widths=1.5,\n                   showmeans=False, showmedians=False, showextrema=False)\nfor body in VP['bodies']:\n    body.set_facecolor('C1')\n    body.set_alpha(1)\nax.set_axisbelow(True)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/advanced-violin.pdf\")\n\n# Boxplot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(10)\nD = np.random.normal((3, 5, 4), (1.25, 1.00, 1.25), (100, 3))\nVP = ax.boxplot(D, positions=[2, 4, 6], widths=1.5, patch_artist=True,\n                showmeans=False, showfliers=False,\n                medianprops={\"color\": \"white\",\n                             \"linewidth\": 0.25},\n                boxprops={\"facecolor\": \"C1\",\n                          \"edgecolor\": \"white\",\n                          \"linewidth\": 0.25},\n                whiskerprops={\"color\": \"C1\",\n                              \"linewidth\": 0.75},\n                capprops={\"color\": \"C1\",\n                          \"linewidth\": 0.75})\nax.set_axisbelow(True)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/advanced-boxplot.pdf\")\n\n# Barbs plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(1)\nX = [[2, 4, 6]]\nY = [[1.5, 3, 2]]\nU = -np.ones((1, 3)) * 0\nV = -np.ones((1, 3)) * np.linspace(50, 100, 3)\nax.barbs(X, Y, U, V, barbcolor=\"C1\", flagcolor=\"C1\", length=5, linewidth=0.5)\nax.set_axisbelow(True)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/advanced-barbs.pdf\")\n\n# Event plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(1)\nX = [2, 4, 6]\nD = np.random.gamma(4, size=(3, 50))\nax.eventplot(D, colors=\"C1\", orientation=\"vertical\", lineoffsets=X,\n             linewidth=0.25)\nax.set_axisbelow(True)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/advanced-event.pdf\")\n\n# Errorbar plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(1)\nX = [2, 4, 6]\nY = [4, 5, 4]\nE = np.random.uniform(0.5, 1.5, 3)\nax.errorbar(X, Y, E, color=\"C1\", linewidth=0.75, capsize=1)\nax.set_axisbelow(True)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/advanced-errorbar.pdf\")\n\n# Hexbin plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(1)\nX = np.random.uniform(1.5, 6.5, 100)\nY = np.random.uniform(1.5, 6.5, 100)\nC = np.random.uniform(0, 1, 10000)\nax.hexbin(X, Y, C, gridsize=4, linewidth=0.25, edgecolor=\"white\",\n          cmap=plt.get_cmap(\"Wistia\"), alpha=1.0)\nax.set_axisbelow(True)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/advanced-hexbin.pdf\")\n\n# Hist plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(1)\nX = 4 + np.random.normal(0, 1.5, 200)\nax.hist(X, bins=8, facecolor=\"C1\", linewidth=0.25, edgecolor=\"white\")\nax.set_ylim(0, 80), ax.set_yticks(np.arange(1, 80, 10))\nax.set_axisbelow(True)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/advanced-hist.pdf\")\n\n# Xcorr plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(3)\nY = np.random.uniform(-4, 4, 250)\nX = np.random.uniform(-4, 4, 250)\nax.xcorr(X, Y, usevlines=True, maxlags=6, normed=True, lw=1,\n         color=\"C1\")\nax.set_xlim(-8, 8), ax.set_xticks(np.arange(-8, 8, 2))\nax.set_ylim(-.25, .25), ax.set_yticks(np.linspace(-.25, .25, 9))\nax.set_axisbelow(True)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/advanced-xcorr.pdf\")\n"
  },
  {
    "path": "scripts/anatomy.py",
    "content": "# ----------------------------------------------------------------------------\n# Title:   Scientific Visualisation - Python & Matplotlib\n# Author:  Nicolas P. Rougier\n# License: BSD\n# ----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nfrom matplotlib.ticker import AutoMinorLocator, MultipleLocator, FuncFormatter\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n])\n\nnp.random.seed(123)\n\nX = np.linspace(0.5, 3.5, 100)\nY1 = 3+np.cos(X)\nY2 = 1+np.cos(1+X/0.75)/2\nY3 = np.random.uniform(Y1, Y2, len(X))\n\n(fig, ax) = plt.subplots(figsize=(8, 8), subplot_kw=dict(aspect=1))\n\n\ndef minor_tick(x, pos):\n    if not x % 1.0:\n        return \"\"\n    return \"%.2f\" % x\n\n\nax.xaxis.set_major_locator(MultipleLocator(1.000))\nax.xaxis.set_minor_locator(AutoMinorLocator(4))\nax.yaxis.set_major_locator(MultipleLocator(1.000))\nax.yaxis.set_minor_locator(AutoMinorLocator(4))\nax.xaxis.set_minor_formatter(FuncFormatter(minor_tick))\n\nax.set_xlim(0, 4)\nax.set_ylim(0, 4)\n\nax.tick_params(which='major', width=1.0)\nax.tick_params(which='major', length=10)\nax.tick_params(which='minor', width=1.0, labelsize=10)\nax.tick_params(which='minor', length=5, labelsize=10, labelcolor='0.25')\n\nax.grid(linestyle=\"--\", linewidth=0.5, color='.25', zorder=-10)\n\nax.plot(X, Y1, c=(0.25, 0.25, 1.00), lw=2, label=\"Blue signal\", zorder=10)\nax.plot(X, Y2, c=(1.00, 0.25, 0.25), lw=2, label=\"Red signal\")\nax.plot(X, Y3, linewidth=0,\n        marker='o', markerfacecolor='w', markeredgecolor='k')\n\nax.set_title(\"Anatomy of a figure\", fontsize=20, verticalalignment='bottom')\nax.set_xlabel(\"X axis label\")\nax.set_ylabel(\"Y axis label\")\n\nax.legend(loc=\"upper right\")\n\n\ndef circle(x, y, radius=0.15):\n    from matplotlib.patches import Circle\n    from matplotlib.patheffects import withStroke\n    circle = Circle((x, y), radius, clip_on=False, zorder=10, linewidth=1,\n                    edgecolor='black', facecolor=(0, 0, 0, .0125),\n                    path_effects=[withStroke(linewidth=5, foreground='w')])\n    ax.add_artist(circle)\n\n\ndef text(x, y, text):\n    ax.text(x, y, text, backgroundcolor=\"white\",\n            # fontname=\"Yanone Kaffeesatz\", fontsize=\"large\",\n            ha='center', va='top', weight=\"regular\", color='#000099')\n\n\n# Minor tick\ncircle(0.50, -0.10)\ntext(0.50, -0.32, \"Minor tick label\")\n\n# Major tick\ncircle(-0.03, 4.00)\ntext(0.03, 3.80, \"Major tick\")\n\n# Minor tick\ncircle(0.00, 3.50)\ntext(0.00, 3.30, \"Minor tick\")\n\n# Major tick label\ncircle(-0.15, 3.00)\ntext(-0.15, 2.80, \"Major tick label\")\n\n# X Label\ncircle(1.80, -0.27)\ntext(1.80, -0.45, \"X axis label\")\n\n# Y Label\ncircle(-0.27, 1.80)\ntext(-0.27, 1.6, \"Y axis label\")\n\n# Title\ncircle(1.60, 4.13)\ntext(1.60, 3.93, \"Title\")\n\n# Blue plot\ncircle(1.75, 2.80)\ntext(1.75, 2.60, \"Line\\n(line plot)\")\n\n# Red plot\ncircle(1.20, 0.60)\ntext(1.20, 0.40, \"Line\\n(line plot)\")\n\n# Scatter plot\ncircle(3.20, 1.75)\ntext(3.20, 1.55, \"Markers\\n(scatter plot)\")\n\n# Grid\ncircle(3.00, 3.00)\ntext(3.00, 2.80, \"Grid\")\n\n# Legend\ncircle(3.70, 3.80)\ntext(3.70, 3.60, \"Legend\")\n\n# Axes\ncircle(0.5, 0.5)\ntext(0.5, 0.3, \"Axes\")\n\n# Figure\ncircle(-0.3, 0.65)\ntext(-0.3, 0.45, \"Figure\")\n\ncolor = '#000099'\nax.annotate('Spines', xy=(4.0, 0.35), xytext=(3.3, 0.5), color=color,\n            weight='regular',  # fontsize=\"large\", fontname=\"Yanone Kaffeesatz\",\n            arrowprops=dict(arrowstyle='->',\n                            connectionstyle=\"arc3\",\n                            color=color))\n\nax.annotate('', xy=(3.15, 0.0), xytext=(3.45, 0.45), color=color,\n            weight='regular',  # fontsize=\"large\", fontname=\"Yanone Kaffeesatz\",\n            arrowprops=dict(arrowstyle='->',\n                            connectionstyle=\"arc3\",\n                            color=color))\n\nfig.savefig(ROOT_DIR / \"figures/anatomy.pdf\")\n# plt.show()\n"
  },
  {
    "path": "scripts/animation.py",
    "content": "import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\n\nT = np.linspace(0, 2*np.pi, 100)\nS = np.sin(T)\nline, = plt.plot(T, S)\n\n\ndef animate(i):\n    line.set_ydata(np.sin(T+i/50))\n\n\na=animation.FuncAnimation(\n    plt.gcf(), animate, interval=5)\n# plt.show()\n"
  },
  {
    "path": "scripts/annotate.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfig = plt.figure(figsize=(6, 1))\n# ax = plt.subplot(111, frameon=False, aspect=.1)\n# b = 0.0\nax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1)\n\n\nplt.scatter([5.5], [0.75], s=100, c=\"k\")\nplt.xlim(0, 6), plt.ylim(0, 1)\nplt.xticks([]), plt.yticks([])\n\nplt.annotate(\"text\", (5.5, .75), (0.75, .75), size=16, va=\"center\", ha=\"center\",\n             arrowprops=dict(facecolor='black', shrink=0.05))\n\nplt.text( 5.5, 0.6, \"xy\\nxycoords\", size=10, va=\"top\", ha=\"center\", color=\".5\")\nplt.text( .75, 0.6, \"xytext\\ntextcoords\", size=10, va=\"top\", ha=\"center\", color=\".5\")\n\nfig.savefig(ROOT_DIR / \"figures/annotate.pdf\")\n# plt.show()\n"
  },
  {
    "path": "scripts/annotation-arrow-styles.py",
    "content": "import pathlib\n\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as mpatches\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nstyles = mpatches.ArrowStyle.get_styles()\n\n\ndef demo_con_style(ax, connectionstyle):\n    ax.text(.05, .95, connectionstyle.replace(\",\", \",\\n\"),\n            family=\"Source Code Pro\",\n            transform=ax.transAxes, ha=\"left\", va=\"top\", size=\"x-small\")\n\n\n(fig, axes) = plt.subplots(4, 4, figsize=(4, 2.5), frameon=False)\nfor ax in axes.flatten():\n    ax.axis(\"off\")\nfor i, (ax, style) in enumerate(zip(axes.flatten(), mpatches.ArrowStyle.get_styles())):\n    x0, y0 = 0.8, 0.5\n    x1, y1 = 0.2, 0.5\n    ax.plot([x0, x1], [y0, y1], \".\", color=\"0.25\")\n    ax.annotate(\"\",\n                xy=(x0, y0), xycoords='data',\n                xytext=(x1, y1), textcoords='data',\n                arrowprops=dict(arrowstyle=style,\n                                color=\"black\",\n                                shrinkA=5, shrinkB=5,\n                                patchA=None, patchB=None,\n                                connectionstyle=\"arc3,rad=0\"))\n    ax.text( (x1+x0)/2, y0-0.2, style,\n             transform=ax.transAxes,\n             family=\"Source Code Pro\", ha=\"center\", va=\"top\")\n\nfig.savefig(ROOT_DIR / \"figures/annotation-arrow-styles.pdf\")\n# plt.show()\n"
  },
  {
    "path": "scripts/annotation-connection-styles.py",
    "content": "import pathlib\n\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n    ROOT_DIR / 'styles/plotlet-grid.mplstyle',\n])\nmpl.rc('lines', markersize=3)\n\n\ndef demo_con_style(ax, connectionstyle):\n    x1, y1 = 0.3, 0.2\n    x2, y2 = 0.8, 0.6\n    ax.plot([x1, x2], [y1, y2], \".\")\n    ax.annotate(\"\",\n                xy=(x1, y1), xycoords='data',\n                xytext=(x2, y2), textcoords='data',\n                arrowprops=dict(arrowstyle=\"->\", lw=0.5, color=\"0.5\",\n                                shrinkA=3, shrinkB=3,\n                                patchA=None, patchB=None,\n                                connectionstyle=connectionstyle),\n                )\n    ax.text(.05, .95, connectionstyle.replace(\",\", \",\\n\"),\n            transform=ax.transAxes, ha=\"left\", va=\"top\", size=4)\n\n\nfig, axs = plt.subplots(3, 3, figsize=(5.7/2.54, 5.7/2.54))\ndemo_con_style(axs[0, 0], \"arc3,rad=0\")\ndemo_con_style(axs[0, 1], \"arc3,rad=0.3\")\ndemo_con_style(axs[0, 2], \"angle3,angleA=0,angleB=90\")\ndemo_con_style(axs[1, 0], \"angle,angleA=-90,angleB=180,rad=0\")\ndemo_con_style(axs[1, 1], \"angle,angleA=-90,angleB=180,rad=10\")\ndemo_con_style(axs[1, 2], \"arc,angleA=-90,angleB=0,armA=0,armB=20,rad=0\")\ndemo_con_style(axs[2, 0], \"bar,fraction=0.3\")\ndemo_con_style(axs[2, 1], \"bar,fraction=-0.3\")\ndemo_con_style(axs[2, 2], \"bar,angle=180,fraction=-0.2\")\n\nfor ax in axs.flat:\n    ax.set(xlim=(0, 1), ylim=(0, 1), xticks=[], yticks=[], aspect=1)\n\nfig.savefig(ROOT_DIR / \"figures/annotation-connection-styles.pdf\")\n"
  },
  {
    "path": "scripts/basic-plots.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\n\n# Script to generate all the basic plots\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n    ROOT_DIR / 'styles/plotlet.mplstyle',\n])\n\n\nsubplot_kw = dict(\n    xlim=(0, 8), xticks=np.arange(1, 8),\n    ylim=(0, 8), yticks=np.arange(1, 8),\n)\n\n# Basic line plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nX = np.linspace(0, 10, 100)\nY = 4 + 2*np.sin(2*X)\nax.plot(X, Y, color=\"C1\")\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/basic-plot.pdf\")\n\n# Basic line plot (color)\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nX = np.linspace(0, 10, 100)\nY = 4 + 2*np.sin(2*X)\nax.plot(X, Y, color=\"black\")\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/basic-plot-color.pdf\")\n\n# Basic scatter plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(3)\nX = 4 + np.random.normal(0, 1.25, 24)\nY = 4 + np.random.normal(0, 1.25, len(X))\nax.scatter(X, Y, 5, zorder=10,\n           edgecolor=\"white\", facecolor=\"C1\", linewidth=0.25)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/basic-scatter.pdf\")\n\n# Basic bar plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(3)\nX = 0.5 + np.arange(8)\nY = np.random.uniform(2, 7, len(X))\nax.bar(X, Y, bottom=0, width=1,\n       edgecolor=\"white\", facecolor=\"C1\", linewidth=0.25)\nax.set_axisbelow(True)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/basic-bar.pdf\")\n\n# Basic imshow plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(3)\nZ = np.zeros((8, 8, 4))\nZ[:, :] = mpl.colors.to_rgba(\"C1\")\nZ[..., 3] = np.random.uniform(0.25, 1.0, (8, 8))\nax.imshow(Z, extent=[0, 8, 0, 8], interpolation=\"nearest\")\nax.grid(linewidth=0.25, color=\"white\")\nfig.savefig(ROOT_DIR / \"figures/basic-imshow.pdf\")\n\n# Basic pcolormesh plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(1)\nX, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))\nZ = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)\nZ = Z - Z.min()\nplt.pcolormesh(X, Y, Z, cmap='Oranges', shading='auto')\nax.set_xlim(-3, 3), ax.set_xticks(np.arange(-3, 4))\nax.set_ylim(-3, 3), ax.set_yticks(np.arange(-3, 4))\nfig.savefig(ROOT_DIR / \"figures/basic-pcolormesh.pdf\")\n\n# Basic contour plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\ncolors = np.zeros((5, 4))\ncolors[:] = mpl.colors.to_rgba(\"C1\")\ncolors[:, 3] = np.linspace(0.15, 0.85, len(colors))\nplt.contourf(Z, len(colors), extent=[0, 8, 0, 8], colors=colors)\nplt.contour(Z, len(colors), extent=[0, 8, 0, 8], colors=\"white\",\n            linewidths=0.125, nchunk=10)\nfig.savefig(ROOT_DIR / \"figures/basic-contour.pdf\")\n\n# Basic pie plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nX = [1, 2, 3, 4]\ncolors = np.zeros((len(X), 4))\ncolors[:] = mpl.colors.to_rgba(\"C1\")\ncolors[:, 3] = np.linspace(0.25, 0.75, len(X))\nax.set_axisbelow(True)\nax.grid(linewidth=0.25, color=\"0.75\")\nax.pie(X, colors=[\"white\"] * len(X), radius=3, center=(4, 4),\n       wedgeprops={\"linewidth\": 0.25, \"edgecolor\": \"white\"}, frame=True)\nax.pie(X, colors=colors, radius=3, center=(4, 4),\n       wedgeprops={\"linewidth\": 0.25, \"edgecolor\": \"white\"}, frame=True)\nfig.savefig(ROOT_DIR / \"figures/basic-pie.pdf\")\n\n# Basic text plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nax.set_axisbelow(True)\nax.grid(linewidth=0.25, color=\"0.75\")\nax.text(4, 4, \"TEXT\", color=\"C1\", size=8, weight=\"bold\",\n        ha=\"center\", va=\"center\", rotation=25)\nfig.savefig(ROOT_DIR / \"figures/basic-text.pdf\")\n\n# Basic fill plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(1)\nX = np.linspace(0, 8, 16)\nY1 = 3 + 4*X/8 + np.random.uniform(0.0, 0.5, len(X))\nY2 = 1 + 2*X/8 + np.random.uniform(0.0, 0.5, len(X))\nplt.fill_between(X, Y1, Y2, color=\"C1\", alpha=.5, linewidth=0)\nplt.plot(X, (Y1+Y2)/2, color=\"C1\", linewidth=0.5)\nax.set_axisbelow(True)\nax.grid(color=\"0.75\")\nfig.savefig(ROOT_DIR / \"figures/basic-fill.pdf\")\n\n# Basic quiver plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nnp.random.seed(1)\nT = np.linspace(0, 2*np.pi, 8)\nX, Y = 4 + np.cos(T), 4 + np.sin(T)\nU, V = 1.5*np.cos(T), 1.5*np.sin(T)\nplt.quiver(X, Y, U, V, color=\"C1\",\n           angles='xy', scale_units='xy', scale=0.5, width=.05)\nax.set_axisbelow(True)\nax.grid(color=\"0.75\")\nfig.savefig(ROOT_DIR / \"figures/basic-quiver.pdf\")\n"
  },
  {
    "path": "scripts/colorbar.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\n\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfig = plt.figure(figsize=(6, .65))\n# ax = plt.subplot(111, frameon=False, aspect=.1)\nb = 0.025\nax = fig.add_axes([b, 10*b, 1-2*b, 1-10*b], frameon=False, aspect=0.05)\n\ncmap = plt.get_cmap(\"Oranges\")\nnorm = mpl.colors.Normalize(vmin=0, vmax=1)\nsm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)\nsm.set_array([])\nplt.colorbar(sm, cax=ax, ticks=np.linspace(0, 1, 11),\n             orientation=\"horizontal\")\n\nfig.savefig(ROOT_DIR / \"figures/colorbar.pdf\")\n# plt.show()\n"
  },
  {
    "path": "scripts/colormaps.py",
    "content": "import pathlib\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfigsize = 4.0, 0.25\nfig = plt.figure(figsize=figsize)\nax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1)\nymin, ymax=  0, 1\nxmin, xmax = 0, figsize[0]/figsize[1]\n\n# Uniform colormaps\n# -----------------------------------------------------------------------------\ncmaps = ('viridis', 'plasma', 'inferno', 'magma', 'cividis',\n\n         'PRGn', 'PiYG', 'RdYlGn', 'BrBG', 'RdGy', 'PuOr', 'RdBu',\n         'RdYlBu', 'Spectral', 'coolwarm', 'bwr', 'seismic',\n\n         'tab10', 'tab20', 'tab20b', 'tab20c',\n         'Pastel1', 'Pastel2', 'Paired',\n         'Set1', 'Set2', 'Set3', 'Accent', 'Dark2',\n\n         'Greys', 'Reds', 'Oranges', 'YlOrBr', 'YlOrRd', 'OrRd',\n         'PuRd', 'RdPu', 'BuPu', 'Purples', 'YlGnBu', 'Blues',\n         'PuBu', 'GnBu', 'PuBuGn', 'BuGn', 'Greens', 'YlGn',\n\n         'bone', 'gray', 'pink', 'afmhot', 'hot', 'gist_heat', 'copper',\n         'Wistia', 'autumn', 'summer', 'spring', 'cool', 'winter',\n\n         'twilight', 'twilight_shifted', 'hsv',\n\n         'terrain', 'ocean', 'gist_earth', 'cubehelix', 'rainbow'\n         )\n\nfor name in cmaps:\n    # The maximum number of segments in a cmap is 256, and for anything smaller,\n    # the cmap will map as a suitably discrete set of colours.\n    Z = np.linspace(0, 1, 256).reshape(1, 256)\n\n    ax.imshow(Z, extent=[xmin, xmax, ymin, ymax], cmap=name)\n    ax.set_xlim(xmin, xmax), ax.set_xticks([])\n    ax.set_ylim(ymin, ymax), ax.set_yticks([])\n\n    fig.savefig(ROOT_DIR / f\"figures/colormap-{name}.pdf\")\n    ax.clear()\n"
  },
  {
    "path": "scripts/colornames.py",
    "content": "\"\"\"\n========================\nVisualizing named colors\n========================\n\nSimple plot example with the named colors and its visual representation.\n\"\"\"\nimport pathlib\n\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n])\nmpl.rc('figure.constrained_layout', h_pad=0, w_pad=0, hspace=0, wspace=0)\n\ncolors = dict(mpl.colors.BASE_COLORS, **mpl.colors.CSS4_COLORS)\n\n# Sort colors by hue, saturation, value and name.\nby_hsv = sorted((tuple(mpl.colors.rgb_to_hsv(mpl.colors.to_rgba(color)[:3])), name)\n                for name, color in colors.items())\nsorted_names = [name for hsv, name in by_hsv]\n\nn = len(sorted_names)\nncols = 3\nnrows = n // ncols\n\nfig, ax = plt.subplots(figsize=(4.5, 6))\n\n# Get height and width\nX, Y = fig.get_dpi() * fig.get_size_inches()\nh = Y / (nrows + 1)\nw = X / ncols\n\nfor i, name in enumerate(sorted_names):\n    col = i // nrows\n    row = i % nrows\n    y = Y - (row * h) - h\n\n    xi_line = w * (col + 0.05)\n    xf_line = w * (col + 0.25)\n    xi_text = w * (col + 0.3)\n\n    ax.text(xi_text, y, name, fontsize=7,\n            horizontalalignment='left',\n            verticalalignment='center')\n\n    ax.hlines(y + h * 0.1, xi_line, xf_line,\n              color=colors[name], linewidth=(h * 0.6))\n\nax.set_xlim(0, X)\nax.set_ylim(0, Y)\nax.set_axis_off()\n\nfig.savefig(ROOT_DIR / \"figures/colornames.pdf\")\n"
  },
  {
    "path": "scripts/colors.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\n\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfigsize = 4.0, 0.25\nfig = plt.figure(figsize=figsize)\nax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1)\nymin, ymax=  0, 1\nxmin, xmax = 0, figsize[0]/figsize[1]\nax.set_xlim(xmin, xmax), ax.set_xticks([])\nax.set_ylim(ymin, ymax), ax.set_yticks([])\n\n# Uniform colormaps\n# -----------------------------------------------------------------------------\npalettes = {\n    'raw' : ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'],\n    'rgba' : [(1, 0, 0), (1, 0, 0, 0.75), (1, 0, 0, 0.50), (1, 0, 0, 0.25)],\n    'HexRGBA' : [\"#FF0000\", \"#FF0000BB\", \"#FF000088\", \"#FF000044\"],\n    'cycle' : [\"C%d\" % i for i in range(10)],\n    'grey' : [\"%1.1f\" % (i/10) for i in range(11)],\n    'name' : [\"DarkRed\", \"Firebrick\", \"Crimson\", \"IndianRed\", \"Salmon\" ] }\n\nfor name, colors in palettes.items():\n    C = mpl.colors.to_rgba_array(colors).reshape((1, len(colors), 4))\n    ax.imshow(C, extent=[xmin, xmax, ymin, ymax])\n\n    # Drop alpha by assuming we're on a white background PDF.\n    alpha = C[0, :, 3]\n    rgb = C[0, :, :3] * alpha[:, np.newaxis] + (1 - alpha[:, np.newaxis])\n    # Same calculation for luminance as\n    # https://matplotlib.org/stable/users/explain/colors/colors.html#comparison-between-x11-css4-and-xkcd-colors\n    luma = 0.299 * rgb[:, 0] + 0.587 * rgb[:, 1] + 0.114 * rgb[:, 2]\n\n    dx = (xmax-xmin)/len(colors)\n    for i in range(len(colors)):\n        text_color = \"black\" if luma[i] > 0.5 else \"white\"\n        text = str(colors[i]).replace(' ', '')\n        ax.text((i+0.5)*dx, (ymin+ymax)/2, text, color=text_color, zorder=10,\n                family=\"Source Code Pro\", size=9, ha=\"center\", va=\"center\")\n\n    fig.savefig(ROOT_DIR / f\"figures/colors-{name}.pdf\")\n    ax.clear()\n"
  },
  {
    "path": "scripts/extents.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n])\nmpl.rc('figure.constrained_layout', wspace=0.05)\n\nZ = np.arange(5*5).reshape(5, 5)\n\n(fig, axs) = plt.subplots(figsize=(8, 5), nrows=2, ncols=2)\n\nax = axs[0, 0]\nax.imshow(Z, extent=[0, 10, 0, 5], interpolation=\"nearest\", origin=\"upper\")\nax.set_xlim(-1, 11), ax.set_xticks([])\nax.set_ylim(-1, 6), ax.set_yticks([0, 5])\nax.text(1, 4.5, \"(0,0)\", ha=\"center\", va=\"center\", color=\"white\", size=\"large\")\nax.text(9, 0.5, \"(4,4)\", ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\nax.text(5.0, 5.5, 'origin=\"upper\"',\n        ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\nax.text(5.0, -0.5, \"extent=[0,10,0,5]\",\n        ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\n\nax = axs[1, 0]\nax.imshow(Z, extent=[0, 10, 0, 5], interpolation=\"nearest\", origin=\"lower\")\nax.set_xlim(-1, 11), ax.set_xticks([0, 10])\nax.set_ylim(-1, 6), ax.set_yticks([0, 5])\nax.text(1, 0.5, \"(0,0)\", ha=\"center\", va=\"center\", color=\"white\", size=\"large\")\nax.text(9, 4.5, \"(4,4)\", ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\n\nax.text(5.0, 5.5, 'origin=\"lower\"',\n        ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\nax.text(5.0, -0.5, \"extent=[0,10,0,5]\",\n        ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\n\nax = axs[1, 1]\nax.imshow(Z, extent=[10, 0, 0, 5], interpolation=\"nearest\", origin=\"lower\")\nax.set_xlim(-1, 11), ax.set_xticks([0, 10])\nax.set_ylim(-1, 6), ax.set_yticks([])\nax.text(9, 0.5, \"(0,0)\", ha=\"center\", va=\"center\", color=\"white\", size=\"large\")\nax.text(1, 4.5, \"(4,4)\", ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\nax.text(5.0, 5.5, 'origin=\"lower\"',\n        ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\nax.text(5.0, -0.5, \"extent=[10,0,0,5]\",\n        ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\n\nax = axs[0, 1]\nax.imshow(Z, extent=[10, 0, 0, 5], interpolation=\"nearest\", origin=\"upper\")\nax.set_xlim(-1, 11), ax.set_xticks([])\nax.set_ylim(-1, 6), ax.set_yticks([])\nax.text(9, 4.5, \"(0,0)\", ha=\"center\", va=\"center\", color=\"white\", size=\"large\")\nax.text(1, 0.5, \"(4,4)\", ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\nax.text(5.0, 5.5, 'origin=\"upper\"',\n        ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\nax.text(5.0, -0.5, \"extent=[10,0,0,5]\",\n        ha=\"center\", va=\"center\", color=\"black\", size=\"large\")\n\nfig.savefig(ROOT_DIR / \"figures/extents.pdf\", dpi=600)\n"
  },
  {
    "path": "scripts/fonts.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfig = plt.figure(figsize=(4.25, 3.8))\nax = fig.add_axes([0, 0, 1, 1], frameon=False, xticks=[], yticks=[],\n                  xlim=[0, 40], ylim=[0, 38])\n\ny = 1\n\n# -----------------------------------------------------------------------------\nvariants = {\n    \"normal\" : \"../fonts/eb-garamond/EBGaramond08-Regular.otf\",\n    \"small-caps\" : \"../fonts/eb-garamond/EBGaramondSC08-Regular.otf\"\n}\n\ntext = \"The quick brown fox jumps over the lazy dog\"\nfor i, (variant, file) in enumerate(variants.items()):\n    ax.text(1, y, text, size=9, va=\"center\", font=pathlib.Path(file).resolve())\n\n    ax.text(39, y, variant,\n            color=\"0.25\", va=\"center\", ha=\"right\",\n            size=\"small\", family=\"Source Code Pro\", weight=400)\n    y += 1.65\ny += 1\n\n# -----------------------------------------------------------------------------\nstyles = [\"normal\", \"italic\"]\n\ntext = \"The quick brown fox jumps over the lazy dog\"\nfor i, style in enumerate(styles):\n    ax.text(1, y, text, size=9, va=\"center\", style=style,\n            family=\"Source Sans Pro\")\n\n    ax.text(39, y, style,\n            color=\"0.25\", va=\"center\", ha=\"right\",\n            size=\"small\", family=\"Source Code Pro\", weight=400)\n    y += 1.65\ny += 1\n\n\n# -----------------------------------------------------------------------------\nfamilies = {\n    \"Pacifico\"        : \"cursive\",\n    \"Source Sans Pro\" : \"sans\",\n    \"Source Serif Pro\": \"serif\",\n    \"Source Code Pro\" : \"monospace\" }\n\ntext = \"The quick brown fox jumps over the lazy dog\"\nfor i, (family, label) in enumerate(families.items()):\n    ax.text(1, y, text,\n            va=\"center\", size=9, family=family, weight=\"regular\")\n\n    ax.text(39, y, label,\n            color=\"0.25\", va=\"center\", ha=\"right\",\n            size=\"small\", family=\"Source Code Pro\", weight=400)\n    y += 1.65\ny += 1\n\n\n# -----------------------------------------------------------------------------\nweights = {\n    'ultralight' : 100,\n    'light'      : 200,\n    'normal'     : 400, 'regular'  : 400, 'book' : 400,\n    'medium'     : 500, 'roman'    : 500,\n    'semibold'   : 600, 'demibold' : 600, 'demi' : 600,\n    'bold'       : 700,\n    'heavy'      : 800, 'extra bold' : 800,\n    'black'      : 900 }\n\ntext = \"The quick brown fox jumps over the lazy dog\"\nfor i, weight in enumerate([\"ultralight\", \"normal\", \"semibold\", \"bold\", \"black\"]):\n    ax.text(1, y, text, size=9,\n            va=\"center\", family=\"Source Sans Pro\", weight=weight)\n\n    ax.text(39, y, f\"{weight} ({weights[weight]:d})\",\n            color=\"0.25\", va=\"center\", ha=\"right\",\n            size=\"small\", family=\"Source Code Pro\", weight=400)\n    y += 1.65\ny += 1\n\n# -----------------------------------------------------------------------------\nsizes = { \"xx-small\" : 0.579,\n          \"x-small\"  : 0.694,\n          \"small\"    : 0.833,\n          \"medium\"   : 1.0,\n          \"large\"    : 1.200,\n          \"x-large\"  : 1.440,\n          \"xx-large\" : 1.728 }\n\ntext = \"The quick brown fox\"\nfor i, (size, scaling) in enumerate(sizes.items()):\n    ax.text(1, y, text, size=size,\n            ha=\"left\", va=\"center\", family=\"Source Sans Pro\", weight=\"light\")\n\n    ax.text(39, y, f\"{size} ({scaling:.2f})\",\n            color=\"0.25\", va=\"center\", ha=\"right\",\n            size=\"small\", family=\"Source Code Pro\", weight=400)\n    y += 1.65* max(sizes[size], sizes[\"small\"])\n\n\nfig.savefig(ROOT_DIR / \"figures/fonts.pdf\")\n# plt.show()\n"
  },
  {
    "path": "scripts/interpolations.py",
    "content": "import pathlib\n\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n    ROOT_DIR / 'styles/plotlet-grid.mplstyle',\n])\n\nmethods = [None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16',\n           'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric',\n           'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos']\n\nnp.random.seed(1)\nZ = np.random.uniform(0, 1, (3, 3))\n\n\nfig, axs = plt.subplots(nrows=6, ncols=3, figsize=(5.7/2.54, 5.7/2.54*2),\n                        # fig, axs = plt.subplots(nrows=6, ncols=3, figsize=(4.5,9),\n                        subplot_kw={'xticks': [], 'yticks': []})\nfor ax, interp_method in zip(axs.flat, methods):\n    ax.imshow(Z, interpolation=interp_method, cmap='viridis',\n              extent=[0, 1, 0, 1], rasterized=True)\n    ax.text(0.5, 0.1, str(interp_method), weight=\"bold\", color=\"white\", size=6,\n            ha=\"center\", va=\"center\")\n\nfig.savefig(ROOT_DIR / \"figures/interpolations.pdf\", dpi=600)\n# plt.show()\n"
  },
  {
    "path": "scripts/layouts.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1 import make_axes_locatable\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfig = plt.figure(figsize=(0.4, 0.4))\nmargin = 0.01\nfig.subplots_adjust(left=margin, right=1-margin, top=1-margin, bottom=margin)\nmpl.rc('axes', linewidth=.5)\n\n# Subplots\n# -----------------------------------------------------------------------------\nnrows, ncols = 3, 3\nfor i in range(nrows*ncols):\n    ax = plt.subplot(ncols, nrows, i+1)\n    ax.set_xticks([]), ax.set_yticks([])\nfig.savefig(ROOT_DIR / \"figures/layout-subplot.pdf\")\nfig.clear()\n\n# Subplots (colored)\n# -----------------------------------------------------------------------------\nnrows, ncols = 3, 3\nfor i in range(nrows*ncols):\n    ax = plt.subplot(ncols, nrows, i+1)\n    ax.set_xticks([]), ax.set_yticks([])\n    if i == 0: ax.set_facecolor(\"#ddddff\")\n    if i == 8: ax.set_facecolor(\"#ffdddd\")\nfig.savefig(ROOT_DIR / \"figures/layout-subplot-color.pdf\")\nfig.clear()\n\n# Spines\n# -----------------------------------------------------------------------------\nax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[])\nax.spines[\"top\"].set_color(\"None\")\nax.spines[\"right\"].set_color(\"None\")\nfig.savefig(ROOT_DIR / \"figures/layout-spines.pdf\")\nfig.clear()\n\n\n# Gridspec\n# -----------------------------------------------------------------------------\ngs = fig.add_gridspec(3, 3)\nax1 = fig.add_subplot(gs[0, :], xticks=[], yticks=[])\nax2 = fig.add_subplot(gs[1, :-1], xticks=[], yticks=[])\nax3 = fig.add_subplot(gs[1:, -1], xticks=[], yticks=[])\nax4 = fig.add_subplot(gs[-1, 0], xticks=[], yticks=[])\nax5 = fig.add_subplot(gs[-1, -2], xticks=[], yticks=[])\nfig.savefig(ROOT_DIR / \"figures/layout-gridspec.pdf\")\nfig.clear()\n\n# Gridspec (colored)\n# -----------------------------------------------------------------------------\ngs = fig.add_gridspec(3, 3)\nax1 = fig.add_subplot(gs[0, :], xticks=[], yticks=[])\nax1.set_facecolor(\"#ddddff\")\nax2 = fig.add_subplot(gs[1, :-1], xticks=[], yticks=[])\nax3 = fig.add_subplot(gs[1:, -1], xticks=[], yticks=[])\nax4 = fig.add_subplot(gs[-1, 0], xticks=[], yticks=[])\nax5 = fig.add_subplot(gs[-1, -2], xticks=[], yticks=[])\nfig.savefig(ROOT_DIR / \"figures/layout-gridspec-color.pdf\")\nfig.clear()\n\n# Inset axes\n# -----------------------------------------------------------------------------\nmpl.rc('axes', linewidth=.5)\nmargin = 0.0125\nax1 = fig.add_axes([margin, margin, 1-2*margin, 1-2*margin], xticks=[], yticks=[])\nax2 = ax1.inset_axes([0.5, 0.5, 0.4, 0.4], xticks=[], yticks=[])\nfig.savefig(ROOT_DIR / \"figures/layout-inset.pdf\")\nfig.clear()\n\n\n# Axes divider\n# -----------------------------------------------------------------------------\nmargin = 0.0125\nax = fig.add_axes([margin, margin, 1-2*margin, 1-2*margin], xticks=[], yticks=[])\ndivider = make_axes_locatable(ax)\ncax = divider.new_horizontal(size=\"10%\", pad=0.025)\nfig.add_axes(cax)\ncax.set_xticks([]), cax.set_yticks([])\nfig.savefig(ROOT_DIR / \"figures/layout-divider.pdf\")\n"
  },
  {
    "path": "scripts/legend.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n])\nmpl.rc('font', size=6)\nmpl.rc('lines', markersize=4)\n\n\nsubplots_kw = dict(\n    figsize=(5.7/2.54, 5.7/2.54),\n    subplot_kw=dict(\n        aspect=1, frameon=True,\n        xlim=(0, 1), ylim=(0, 1),\n        xticks=[], yticks=[],\n    ),\n)\n\n(fig, ax) = plt.subplots(**subplots_kw)\n\n\ndef text(x, y, _text):\n    color= \"C1\"\n    if not 0 < x < 1 or not 0 < y < 1: color = \"C0\"\n    size = 0.15\n    ax.text(x, y, _text, color=\"white\",  # bbox={\"color\": \"C1\"},\n            size=\"xx-large\", weight=\"bold\", ha=\"center\", va=\"center\")\n    rect = plt.Rectangle((x-size/2, y-size/2), size, size, facecolor=color,\n                         zorder=-10, clip_on=False)\n    ax.add_patch(rect)\n\n\ndef point(x, y):\n    ax.scatter([x], [y], facecolor=\"C0\", edgecolor=\"white\",\n               zorder=10, clip_on=False)\n\n\nd = .1\ne = .15/2\n\ntext(  d, d, \"3\"), text( 0.5, d, \"8\"), text(1-d, d, \"4\")\ntext(  d, 0.5, \"6\"), text( 0.5, 0.5, \"10\"), text(1-d, 0.5, \"7\")\ntext(  d, 1-d, \"2\"), text( 0.5, 1-d, \"9\"), text(1-d, 1-d, \"1\")\n\ntext( -d, 1-d, \"A\"), text( -d, 0.5, \"B\"), text(  -d, d, \"C\")\npoint(-d+e, 1-d+e), point(-d+e, 0.5), point(-d+e, d-e),\n\ntext(  d, -d, \"D\"), text(0.5, -d, \"E\"), text( 1-d, -d, \"F\")\npoint(d-e, -d+e), point(0.5, -d+e), point(1-d+e, -d+e),\n\ntext(1+d, d, \"G\"), text(1+d, 0.5, \"H\"), text( 1+d, 1-d, \"I\")\npoint(1+d-e, d-e), point(1+d-e, .5), point(1+d-e, 1-d+e),\n\ntext(1-d, 1+d, \"J\"), text(0.5, 1+d, \"K\"), text(   d, 1+d, \"L\")\npoint(1-d+e, 1+d-e), point(0.5, 1+d-e), point(d-e, 1+d-e),\n\nfig.savefig(ROOT_DIR / \"figures/legend-placement.pdf\")\n"
  },
  {
    "path": "scripts/linestyles.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfig = plt.figure(figsize=(4.25, 2*.55))\nax = fig.add_axes([0, 0, 1, 1], xlim=[0.75, 10.25], ylim=[0.5, 2.5], frameon=False,\n                  xticks=[], yticks=[])\ny = 2\n\n\ndef split(n_segment):\n    width = 9\n    segment_width = 0.75*(width/n_segment)\n    segment_pad = (width - n_segment*segment_width)/(n_segment-1)\n    X0 = 1+np.arange(n_segment)*(segment_width+segment_pad)\n    X1 = X0 + segment_width\n    return X0, X1\n\n\n# Line style\n# ----------------------------------------------------------------------------\nX0, X1 = split(5)\nstyles = \"-\", \":\", \"--\", \"-.\", (0, (0.01, 2))\n\nfor x0, x1, style in zip(X0, X1, styles):\n    ax.plot([x0, x1], [y, y], color=\"C1\", linestyle=style,\n            solid_capstyle=\"round\", dash_capstyle=\"round\", linewidth=3)\n    if isinstance(style, str): text = '\"%s\"' % style\n    else: text = '%s' % str(style)\n    text = text.replace(' ', '')\n    ax.text((x0+x1)/2, y-0.2, text,\n            size=8, ha=\"center\", va=\"top\", family=\"Source Code Pro\")\nax.text(X0[0]-0.25, y+0.2, \"linestyle or ls\", family=\"Source Code Pro\",\n        size=14, ha=\"left\", va=\"baseline\")\ny -= 1\n\n# Dash capstyle\n# ----------------------------------------------------------------------------\nX0, X1 = split(3)\nstyles = \"butt\", \"round\", \"projecting\"\nfor x0, x1, style in zip(X0, X1, styles):\n    ax.plot([x0, x1], [y, y], color=\"C1\", dash_capstyle=\"projecting\",\n            linewidth=7, linestyle=\"--\", alpha=.25)\n    ax.plot([x0, x1], [y, y], color=\"C1\", linewidth=7,\n            linestyle=\"--\", dash_capstyle=style)\n    ax.text((x0+x1)/2, y-0.2, '\"%s\"' % style, family=\"Source Code Pro\",\n            size=10, ha=\"center\", va=\"top\")\nax.text(X0[0]-0.25, y+0.2, \"capstyle or dash_capstyle\", family=\"Source Code Pro\",\n        size=14, ha=\"left\", va=\"baseline\")\n\n\nfig.savefig(ROOT_DIR / \"figures/linestyles.pdf\", dpi=200)\n# plt.show()\n"
  },
  {
    "path": "scripts/markers.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\n# Markers\n# -----------------------------------------------------------------------------\nfig = plt.figure(figsize=(3.5, 1.5))\nax = fig.add_axes([0, 0, 1, 1], frameon=False,\n                  xlim=[0.5, 10.5], ylim=[0.0, 4.35], xticks=[], yticks=[])\nX = np.linspace(1, 10, 12)\nY = np.arange(1, 4)\nX, Y = np.meshgrid(X, Y)\nX , Y = X.ravel(), Y.ravel()\n\nplt.scatter(X, 1+Y, s=256, marker=\"s\", fc=\"C1\", ec=\"none\", alpha=.25)\nmarkers = [\n    \"$♠$\", \"$♣$\", \"$♥$\", \"$♦$\", \"$→$\", \"$←$\", \"$↑$\", \"$↓$\", \"$◐$\", \"$◑$\", \"$◒$\", \"$◓$\",\n    \"1\", \"2\", \"3\", \"4\", \"+\", \"x\", \"|\", \"_\", 4, 5, 6, 7,\n    \".\", \"o\", \"s\", \"P\", \"X\", \"*\", \"p\", \"D\", \"<\", \">\", \"^\", \"v\", ]\nfor x, y, marker in zip(X, Y, markers):\n    if y == 3: fc = \"white\"\n    else: fc = \"C1\"\n    plt.scatter(x, 1+y, s=100, marker=marker, fc=fc, ec=\"C1\", lw=0.5)\n\n    if y == 1: marker = \"\\$%s\\$\" % marker\n    if isinstance(marker, str): text = \"'%s'\" % marker\n    else: text = '%s' % marker\n    plt.text(x, 1+y-0.4, text,\n             size=\"x-small\", ha=\"center\", va=\"top\", family=\"Monospace\")\n\n\n# Spacing\nn_segment = 4\nwidth = 9\nsegment_width = 0.75*(width/n_segment)\nsegment_pad = (width - n_segment*segment_width)/(n_segment-1)\nX0 =  1+np.arange(n_segment)*(segment_width+segment_pad)\nmarks = [ 10, [0, -1], (25, 5), [0, 25, -1] ]\ny = .6\nfor x0, mark in zip(X0, marks):\n    X = np.linspace(x0, x0+segment_width, 50)\n    Y = y*np.ones(len(X))\n    ax.plot(X, Y, linewidth=1, color=\"black\",\n            marker=\".\", mfc=\"white\", mec=\"black\", mew=\"1\", markevery=mark)\n    ax.text((X[0]+X[-1])/2, y-0.2, '%s' % str(mark),\n            size=\"x-small\", ha=\"center\", va=\"top\")\n\nplt.text(.7, 1, \"markevery\",\n         size=\"medium\", ha=\"left\", va=\"center\", family=\"Source Code Pro\")\nfig.savefig(ROOT_DIR / \"figures/markers.pdf\", dpi=600)\n"
  },
  {
    "path": "scripts/performance-tips.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport time\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n\nfig, ax = plt.subplots()\n\nn = 10_000_000\nnp.random.seed(1)\nX = np.random.uniform(0, 1, n)\nY = np.random.uniform(0, 1, n)\n\nstart = time.perf_counter()\nax.plot(X, Y, marker=\"o\", ls=\"\")\nend = time.perf_counter()\nprint(f\"Time: {end-start}s\")\n\nax.clear()\n\nstart = time.perf_counter()\nax.scatter(X, Y)\nend = time.perf_counter()\nprint(f\"Time: {end-start}s\")\n\nax.clear()\n\nn = 1_000\nnp.random.seed(1)\nX = []\nfor i in range(n):\n    X.append(np.random.uniform(0, 1, 10))\n# np.random.uniform(0,1,n)\n# Y = np.random.uniform(0,1,n)\n\nstart = time.perf_counter()\n# for i in range(0,n,2): plt.plot(X[i:i+2], Y[i:i+2])\nfor i in range(n): plt.plot(X[i])\nend = time.perf_counter()\nprint(f\"Time: {end-start}s\")\n\nax.clear()\n\nstart = time.perf_counter()\nax.plot(sum([list(x)+[None] for x in X], []))\n# X0,Y0 = X[0::2], Y[0::2]\n# X1,Y1 = X[1::2], Y[1::2]\n# S = [None]*len(X)\n# X = [v for t in zip(X0,X1,S) for v in t]\n# Y = [v for t in zip(Y0,Y1,S) for v in t]\n# plt.plot(X,Y)\nend = time.perf_counter()\nprint(f\"Time: {end-start}s\")\n"
  },
  {
    "path": "scripts/plot-variations.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\n# Scripts to generate all the basic plots\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n    ROOT_DIR / 'styles/plotlet.mplstyle',\n])\nmpl.rc('axes', titlepad=1)\n\n\nsubplot_kw = dict(\n    xlim=(0, 8), xticks=np.arange(1, 8),\n    ylim=(0, 8), yticks=np.arange(1, 8),\n)\n\n# Basic line plot (color)\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nX = np.linspace(0, 10, 100)\nY = 4+2*np.sin(2*X)\nax.plot(X, Y, color=\"black\", linewidth=0.75)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/plot-color.pdf\")\n\n# Basic line plot (linestyle)\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nX = np.linspace(0, 10, 100)\nY = 4+2*np.sin(2*X)\nax.plot(X, Y, color=\"C1\", linewidth=0.75, linestyle=\"--\")\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/plot-linestyle.pdf\")\n\n# Basic line plot (linewidth)\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nX = np.linspace(0, 10, 100)\nY = 4+2*np.sin(2*X)\nax.plot(X, Y, color=\"C1\", linewidth=1.5)\nax.grid()\nfig.savefig(\"../figures/plot-linewidth.pdf\")\nfig.savefig(ROOT_DIR / \"figures/plot-linewidth.pdf\")\n\n# Basic line plot (marker)\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nX = np.linspace(0, 10, 100)\nY = 4+2*np.sin(2*X)\nax.plot(X, Y, color=\"C1\", linewidth=0.75, marker=\"o\", markevery=5, markersize=2)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/plot-marker.pdf\")\n\n# Basic line plot (multi)\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nX = np.linspace(0, 10, 100)\nY1 = 4+2*np.sin(2*X)\nY2 = 4+2*np.cos(2*X)\nax.plot(X, Y1, color=\"C1\", linewidth=0.75)\nax.plot(X, Y2, color=\"C0\", linewidth=0.75)\nax.grid()\nfig.savefig(ROOT_DIR / \"figures/plot-multi.pdf\")\n\n# Basic line plot (vsplit)\n# -----------------------------------------------------------------------------\n(fig, [ax2, ax1]) = plt.subplots(nrows=2, gridspec_kw=dict(hspace=0.2), subplot_kw=subplot_kw)\n\nX = np.linspace(0, 10, 100)\nY1 = 2+1*np.sin(2*X)\nax1.plot(X, Y1, color=\"C1\", linewidth=0.75)\nax1.set_ylim(0, 4), ax1.set_yticks(np.arange(1, 4))\nax1.grid()\nax1.tick_params(axis=u'both', which=u'both', length=0)\n\nY2 = 2+1*np.cos(2*X)\nax2.plot(X, Y2, color=\"C0\", linewidth=0.75)\nax2.set_ylim(0, 4), ax2.set_yticks(np.arange(1, 4))\nax2.grid()\nax2.tick_params(axis=u'both', which=u'both', length=0)\nfig.savefig(ROOT_DIR / \"figures/plot-vsplit.pdf\")\n\n# Basic line plot (hsplit)\n# -----------------------------------------------------------------------------\n(fig, [ax1, ax2]) = plt.subplots(ncols=2, gridspec_kw=dict(wspace=0.2), subplot_kw=subplot_kw)\n\nX = np.linspace(0, 10, 100)\nY1 = 2+1*np.sin(2*X)\nax1.plot(Y1, X, color=\"C1\", linewidth=0.75)\nax1.set_xlim(0, 4), ax1.set_xticks(np.arange(1, 4))\nax1.grid()\nax1.tick_params(axis=u'both', which=u'both', length=0)\n\nY2 = 2+1*np.cos(2*X)\nax2.plot(Y2, X, color=\"C0\", linewidth=0.75)\nax2.set_xlim(0, 4), ax2.set_xticks(np.arange(1, 4))\nax2.grid()\nax2.tick_params(axis=u'both', which=u'both', length=0)\nfig.savefig(ROOT_DIR / \"figures/plot-hsplit.pdf\")\n\n# Basic line plot (title)\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nX = np.linspace(0, 10, 100)\nY = 3+2*np.sin(2*X)\nax.plot(X, Y, color=\"C1\", linewidth=0.75)\nax.set_ylim(0, 6), ax.set_yticks(np.arange(1, 6))\nax.grid()\nax.set_title(\"A Sine wave\", size=4, weight=\"bold\")\nfig.savefig(ROOT_DIR / \"figures/plot-title.pdf\")\n\n# Basic line plot (xlabel)\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw=subplot_kw)\nX = np.linspace(0, 10, 100)\nY = 3+2*np.sin(2*X)\nax.plot(X, Y, color=\"C1\", linewidth=0.75), ax.set_xticklabels([])\nax.set_ylim(0, 6), ax.set_yticks(np.arange(1, 6)), ax.set_yticklabels([])\nax.grid()\nax.text(4, -1, \"Time\", transform=ax.transData, clip_on=False,\n        size=3.5, ha=\"center\", va=\"center\")\nfig.savefig(ROOT_DIR / \"figures/plot-xlabel.pdf\")\n"
  },
  {
    "path": "scripts/projections.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport cartopy\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n    ROOT_DIR / 'styles/plotlet.mplstyle',\n])\n\nCARTOPY_SOURCE_TEMPLATE = 'https://naturalearth.s3.amazonaws.com/{resolution}_{category}/ne_{resolution}_{name}.zip'\n\n\n# Configures cartopy to download NaturalEarth shapefiles from S3 instead of naciscdn\n# Taken from https://github.com/SciTools/cartopy/issues/1325#issuecomment-904343657\ntarget_path_template = cartopy.io.shapereader.NEShpDownloader.default_downloader().target_path_template\ndownloader = cartopy.io.shapereader.NEShpDownloader(url_template=CARTOPY_SOURCE_TEMPLATE,\n                                                    target_path_template=target_path_template)\ncartopy.config['downloaders'][('shapefiles', 'natural_earth')] = downloader\n\n\n# Polar plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw={'projection': 'polar'})\nT = np.linspace(0, 3*2*np.pi, 500)\nR = np.linspace(0, 2, len(T))\nax.plot(T, R, color=\"C1\")\nax.set_xticks(np.linspace(0, 2*np.pi, 2*8))\nax.set_xticklabels([])\nax.set_yticks(np.linspace(0, 2, 8))\nax.set_yticklabels([])\nax.set_ylim(0, 2)\nax.grid(linewidth=0.2)\nfig.savefig(ROOT_DIR / \"figures/projection-polar.pdf\")\nfig.clear()\n\n# 3D plot\n# -----------------------------------------------------------------------------\n(fig, ax) = plt.subplots(subplot_kw={'projection': '3d'})\nr = np.linspace(0, 1.25, 50)\np = np.linspace(0, 2*np.pi, 50)\nR, P = np.meshgrid(r, p)\nZ = ((R**2 - 1)**2)\nX, Y = R*np.cos(P), R*np.sin(P)\n\n# Plot the surface.\nax.plot_surface(X, Y, Z, color=\"C1\", antialiased=False)\nax.set_zlim(0, 1)\nax.set_xticks([])\nax.set_yticks([])\nax.set_zticks([])\nfig.savefig(ROOT_DIR / \"figures/projection-3d.pdf\")\nfig.clear()\n\n# Cartopy plot\n# -----------------------------------------------------------------------------\nfig = plt.figure()\nax = fig.add_subplot(frameon=False,\n                     projection=cartopy.crs.Orthographic())\nax.add_feature(cartopy.feature.LAND, zorder=0,\n               facecolor=\"C1\", edgecolor=\"0.0\", linewidth=0)\nfig.savefig(ROOT_DIR / \"figures/projection-cartopy.pdf\")\n"
  },
  {
    "path": "scripts/scales.py",
    "content": "import pathlib\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfig = plt.figure(figsize=(0.4, 2/3*0.4))\nax = fig.add_axes([0, 0, 1, 1], frameon=False)\nax.tick_params(axis='both', which='both', length=0)\nax.set_xlim(-2, 2)\nX = np.linspace(-2, +2, 1001)\nY = np.sin(X*2.5*2*np.pi)\n\n\n# Linear scale\n# -----------------------------------------------------------------------------\nax.set_xlim(X.min(), X.max())\nax.set_xscale(\"linear\")\nax.plot(X, Y, color=\"C1\", linewidth=0.75)\nax.set_ylim(-2.5, 1.5)\nax.text(0, 0.12, \"-∞\", ha=\"left\", va=\"bottom\", size=3, transform=ax.transAxes)\nax.text(0, 0.15, \"⇤\", ha=\"left\", va=\"top\", size=4, transform=ax.transAxes)\nax.text(1, 0.12, \"+∞\", ha=\"right\", va=\"bottom\", size=3, transform=ax.transAxes)\nax.text(1, 0.15, \"⇥\", ha=\"right\", va=\"top\", size=4, transform=ax.transAxes)\nfig.savefig(ROOT_DIR / \"figures/scale-linear.pdf\")\nax.clear()\n\n# Log scale\n# -----------------------------------------------------------------------------\nax.set_xscale(\"log\", base=10)\nax.plot(X, Y, color=\"C1\", linewidth=0.75)\nax.set_ylim(-2.5, 1.5)\nax.text(0, 0.12, \"0\", ha=\"left\", va=\"bottom\", size=3, transform=ax.transAxes)\nax.text(0, 0.15, \"⇤\", ha=\"left\", va=\"top\", size=4, transform=ax.transAxes)\nax.text(1, 0.12, \"+∞\", ha=\"right\", va=\"bottom\", size=3, transform=ax.transAxes)\nax.text(1, 0.15, \"⇥\", ha=\"right\", va=\"top\", size=4, transform=ax.transAxes)\nfig.savefig(ROOT_DIR / \"figures/scale-log.pdf\")\nax.clear()\n\n# Symlog scale\n# -----------------------------------------------------------------------------\nax.set_xscale(\"symlog\", base=10, linthresh=1)\nax.plot(X, Y, color=\"C1\", linewidth=0.75)\nax.set_ylim(-2.5, 1.5)\nax.text(0, 0.12, \"-∞\", ha=\"left\", va=\"bottom\", size=3, transform=ax.transAxes)\nax.text(0, 0.15, \"⇤\", ha=\"left\", va=\"top\", size=4, transform=ax.transAxes)\nax.text(1, 0.12, \"+∞\", ha=\"right\", va=\"bottom\", size=3, transform=ax.transAxes)\nax.text(1, 0.15, \"⇥\", ha=\"right\", va=\"top\", size=4, transform=ax.transAxes)\nfig.savefig(ROOT_DIR / \"figures/scale-symlog.pdf\")\nax.clear()\n\n# Symlog scale\n# -----------------------------------------------------------------------------\nax.set_xscale(\"logit\")\nax.plot(X, Y, color=\"C1\", linewidth=0.75)\nax.set_ylim(-2.5, 1.5)\nax.text(0, 0.12, \"0\", ha=\"left\", va=\"bottom\", size=3, transform=ax.transAxes)\nax.text(0, 0.15, \"⇤\", ha=\"left\", va=\"top\", size=4, transform=ax.transAxes)\nax.text(1, 0.12, \"1\", ha=\"right\", va=\"bottom\", size=3, transform=ax.transAxes)\nax.text(1, 0.15, \"⇥\", ha=\"right\", va=\"top\", size=4, transform=ax.transAxes)\nfig.savefig(ROOT_DIR / \"figures/scale-logit.pdf\")\nax.clear()\n"
  },
  {
    "path": "scripts/sine.py",
    "content": "# ----------------------------------------------------------------------------\n# Author:  Nicolas P. Rougier\n# License: BSD\n# ----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n    ROOT_DIR / 'styles/sine-plot.mplstyle',\n])\n\nX = np.linspace(0, 10*np.pi, 1000)\nY = np.sin(X)\n\n\nfig, ax = plt.subplots(figsize=(5.7/2.54, 1.2/2.54))\nax.set_yticks(np.linspace(-1, 1, 5))\nax.plot(X, Y, color=\"C1\")\nfig.savefig(ROOT_DIR / \"figures/sine.pdf\")\n\n\nX = np.linspace(0.1, 10*np.pi, 1000)\nY = np.sin(X)\n\n\nfig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54))\nax.plot(X, Y, \"C1o:\", markevery=50, mec=\"1.0\")\nax.set_ylim(-1.5, 1.5)\nfig.savefig(ROOT_DIR / \"figures/sine-marker.pdf\")\n\n\nfig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54))\nax.set_xscale(\"log\")\nax.plot(X, Y, \"C1o-\", markevery=50, mec=\"1.0\")\nax.set_ylim(-1.5, 1.5)\nfig.savefig(ROOT_DIR / \"figures/sine-logscale.pdf\")\n\n\nfig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54))\nax.plot(X, Y, \"C1\")\nax.fill_betweenx([-1.5, 1.5], [0], [2*np.pi], color=\".9\")\nax.text(0, -1, r\" Period $\\Phi$\", va=\"top\")\nax.set_ylim(-1.5, 1.5)\nfig.savefig(ROOT_DIR / \"figures/sine-period.pdf\")\n\n\nfig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54))\nax.plot(X, np.sin(X), \"C0\", label=\"Sine\")\nax.plot(X, np.cos(X), \"C1\", label=\"Cosine\")\nax.legend(bbox_to_anchor=(0.0, .9, 1.02, 0.1),\n          frameon=False, mode=\"expand\", ncol=2, loc=\"lower left\")\nax.set_title(\"Sine and Cosine\")\nax.set_xticks([]), ax.set_yticks([])\nax.set_ylim(-1.25, 1.25)\nfig.savefig(ROOT_DIR / \"figures/sine-legend.pdf\")\n\n\nfig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54))\nX = np.linspace(0, 10*np.pi, 1000)\nY = np.sin(X)\nax.plot(X, Y, \"C1o-\", markevery=50, mec=\"1.0\")\nax.set_ylim(-1.5, 1.5)\nax.annotate(\" \", (X[200], Y[200]), (X[250], -1), ha=\"center\", va=\"center\",\n            arrowprops=dict(arrowstyle=\"->\", color=\"C1\", linewidth=0.5, patchA=None, shrinkA=4, shrinkB=0.5))\nax.annotate(\"A\", (X[250], Y[250]), (X[250], -1), ha=\"center\", va=\"center\",\n            arrowprops=dict(arrowstyle=\"->\", color=\"C1\", linewidth=0.5, patchA=None, shrinkA=4, shrinkB=0.5))\nax.annotate(\" \", (X[300], Y[300]), (X[250], -1), ha=\"center\", va=\"center\",\n            arrowprops=dict(arrowstyle=\"->\", color=\"C1\", linewidth=0.5, patchA=None, shrinkA=4, shrinkB=0.5))\nfig.savefig(ROOT_DIR / \"figures/sine-annotate.pdf\")\n"
  },
  {
    "path": "scripts/styles.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfor style in ['default'] + plt.style.available:\n    with plt.style.context(style):\n        fig = plt.figure(figsize=(5, 3), dpi=100)\n        ax = plt.subplot(1, 1, 1)\n        X = np.linspace(0, 2*np.pi, 256)\n        Y = np.cos(X)\n        ax.plot(X, Y)\n        plt.title(style, family=\"Source Serif Pro\", size=32)\n        plt.tight_layout()\n        fig.savefig(ROOT_DIR / f\"figures/style-{style}.pdf\")\n        plt.close(fig)\n"
  },
  {
    "path": "scripts/text-alignments.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\ndpi = 100\nfig = plt.figure(figsize=(4.25, 1.5), dpi=dpi)\nax = fig.add_axes([0, 0, 1, 1], frameon=False,\n                  xlim=(0, 4.25), ylim=(0, 1.5), xticks=[], yticks=[])\n\nfontsize = 48\nrenderer = fig.canvas.get_renderer()\nhorizontalalignment = \"left\"\nverticalalignment = \"center\"\nposition = (0.25, 1.5/2)\ncolor = \"0.25\"\n\n# Compute vertical and horizontal alignment offsets\ntext = ax.text(0, 0, \"Matplotlib\", fontsize=fontsize)\nyoffset = {}\nfor alignment in [\"top\", \"center\", \"baseline\", \"bottom\"]:\n    text.set_verticalalignment(alignment)\n    y = text.get_window_extent(renderer).y0/dpi\n    yoffset[alignment] = y\n\nxoffset = {}\nfor alignment in [\"left\", \"center\", \"right\"]:\n    text.set_horizontalalignment(alignment)\n    x = text.get_window_extent(renderer).x0/dpi\n    xoffset[alignment] = x\n\n# Actual positioning of the text\ntext.set_horizontalalignment(horizontalalignment)\ntext.set_verticalalignment(verticalalignment)\ntext.set_position(position)\n\n\nfor name, y in yoffset.items():\n    y = position[1] - y + yoffset[verticalalignment]\n    plt.plot([0.1, 3.75], [y, y], linewidth=0.5, color=color)\n    plt.text(3.75, y, \" \"+name, color=color,\n             ha=\"left\", va=\"center\", size=\"x-small\")\n\nfor name, x in xoffset.items():\n    x = position[0] - x + xoffset[horizontalalignment]\n    plt.plot([x, x], [0.25, 1.25], linewidth=0.5, color=color)\n    plt.text(x, 0.24, name, color=color,\n             ha=\"center\", va=\"top\", size=\"x-small\")\n\nP = []\nfor x in xoffset.values():\n    x = position[0] - x + xoffset[horizontalalignment]\n    for y in yoffset.values():\n        y = position[1] - y + yoffset[verticalalignment]\n        P.append((x, y))\nP = np.array(P)\n\nax.scatter(P[:, 0], P[:, 1], s=10, zorder=10,\n           facecolor=\"white\", edgecolor=color, linewidth=0.75)\n\nepsilon = 0.05\nplt.text(P[3, 0]+epsilon, P[3, 1]-epsilon, \"(0,0)\",\n         color=color, ha=\"left\", va=\"top\", size=\"x-small\")\nplt.text(P[8, 0]-epsilon, P[8, 1]+epsilon, \"(1,1)\",\n         color=color, ha=\"right\", va=\"bottom\", size=\"x-small\")\n\nfig.savefig(ROOT_DIR / \"figures/text-alignments.pdf\")\n# plt.show()\n"
  },
  {
    "path": "scripts/tick-formatters.py",
    "content": "# ----------------------------------------------------------------------------\n# Title:   Scientific Visualisation - Python & Matplotlib\n# Author:  Nicolas P. Rougier\n# License: BSD\n# ----------------------------------------------------------------------------\nimport pathlib\n\nimport matplotlib.pyplot as plt\nimport matplotlib.ticker as ticker\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\n\n# Setup a plot such that only the bottom spine is shown\ndef setup(ax):\n    \"\"\"Set up Axes with just an x-Axis.\"\"\"\n    ax.spines['right'].set_color('none')\n    ax.spines['left'].set_color('none')\n    ax.yaxis.set_major_locator(ticker.NullLocator())\n    ax.spines['top'].set_color('none')\n    ax.xaxis.set_ticks_position('bottom')\n    ax.tick_params(which='major', width=1.00, length=5)\n    ax.tick_params(which='minor', width=0.75, length=2.5, labelsize=10)\n    ax.set_xlim(0, 5)\n    ax.set_ylim(0, 1)\n    ax.patch.set_alpha(0.0)\n\n\nfig = plt.figure(figsize=(8, 5))\nfig.patch.set_alpha(0.0)\nn = 7\n\nfontsize = 18\nfamily = \"Source Code Pro\"\n\n# Null formatter\nax = fig.add_subplot(n, 1, 1)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.MultipleLocator(1.00))\nax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25))\nax.xaxis.set_major_formatter(ticker.NullFormatter())\nax.xaxis.set_minor_formatter(ticker.NullFormatter())\nax.text(0.0, 0.1, \"ticker.NullFormatter()\", family=family,\n        fontsize=fontsize, transform=ax.transAxes)\n\n# Fixed formatter\nax = fig.add_subplot(n, 1, 2)\nsetup(ax)\nax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25))\nax.xaxis.set_major_locator(ticker.FixedLocator(range(6)))\nmajors = [\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\"]\nax.xaxis.set_major_formatter(ticker.FixedFormatter(majors))\nax.text(0.0, 0.1, \"ticker.FixedFormatter(['zero', 'one', 'two', …])\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n\n# FuncFormatter can be used as a decorator\n@ticker.FuncFormatter\ndef major_formatter(x, pos):\n    \"\"\"Return formatted value with 2 decimal places.\"\"\"\n    return \"[%.2f]\" % x\n\n\nax = fig.add_subplot(n, 1, 3)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.MultipleLocator(1.00))\nax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25))\nax.xaxis.set_major_formatter(major_formatter)\nax.text(0.0, 0.1, 'ticker.FuncFormatter(lambda x, pos: \"[%.2f]\" % x)',\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n\n# FormatStr formatter\nax = fig.add_subplot(n, 1, 4)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.MultipleLocator(1.00))\nax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25))\nax.xaxis.set_major_formatter(ticker.FormatStrFormatter(\">%d<\"))\nax.text(0.0, 0.1, \"ticker.FormatStrFormatter('>%d<')\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# Scalar formatter\nax = fig.add_subplot(n, 1, 5)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.AutoLocator())\nax.xaxis.set_minor_locator(ticker.AutoMinorLocator())\nax.xaxis.set_major_formatter(ticker.ScalarFormatter(useMathText=True))\nax.text(0.0, 0.1, \"ticker.ScalarFormatter()\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# StrMethod formatter\nax = fig.add_subplot(n, 1, 6)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.MultipleLocator(1.00))\nax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25))\nax.xaxis.set_major_formatter(ticker.StrMethodFormatter(\"{x}\"))\nax.text(0.0, 0.1, \"ticker.StrMethodFormatter('{x}')\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# Percent formatter\nax = fig.add_subplot(n, 1, 7)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.MultipleLocator(1.00))\nax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25))\nax.xaxis.set_major_formatter(ticker.PercentFormatter(xmax=5))\nax.text(0.0, 0.1, \"ticker.PercentFormatter(xmax=5)\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# Push the top of the top axes outside the figure because we only show the\n# bottom spine.\nfig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=1.05)\n\nfig.savefig(ROOT_DIR / \"figures/tick-formatters.pdf\", transparent=True)\n# plt.show()\n"
  },
  {
    "path": "scripts/tick-locators.py",
    "content": "# ----------------------------------------------------------------------------\n# Title:   Scientific Visualisation - Python & Matplotlib\n# Author:  Nicolas P. Rougier\n# License: BSD\n# ----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.ticker as ticker\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\n\n# Setup a plot such that only the bottom spine is shown\ndef setup(ax):\n    ax.spines['right'].set_color('none')\n    ax.spines['left'].set_color('none')\n    ax.yaxis.set_major_locator(ticker.NullLocator())\n    ax.spines['top'].set_color('none')\n    ax.xaxis.set_ticks_position('bottom')\n    ax.tick_params(which='major', width=1.00)\n    ax.tick_params(which='major', length=5)\n    ax.tick_params(which='minor', width=0.75)\n    ax.tick_params(which='minor', length=2.5)\n    ax.set_xlim(0, 5)\n    ax.set_ylim(0, 1)\n    ax.patch.set_alpha(0.0)\n\n\nfig = plt.figure(figsize=(8, 5))\nfig.patch.set_alpha(0.0)\nn = 8\n\nfontsize = 18\nfamily = \"Source Code Pro\"\n\n# Null Locator\nax = plt.subplot(n, 1, 1)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.NullLocator())\nax.xaxis.set_minor_locator(ticker.NullLocator())\nax.text(0.0, 0.1, \"ticker.NullLocator()\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# Multiple Locator\nax = plt.subplot(n, 1, 2)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.MultipleLocator(0.5))\nax.xaxis.set_minor_locator(ticker.MultipleLocator(0.1))\nax.text(0.0, 0.1, \"ticker.MultipleLocator(0.5)\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# Fixed Locator\nax = plt.subplot(n, 1, 3)\nsetup(ax)\nmajors = [0, 1, 5]\nax.xaxis.set_major_locator(ticker.FixedLocator(majors))\nminors = np.linspace(0, 1, 11)[1:-1]\nax.xaxis.set_minor_locator(ticker.FixedLocator(minors))\nax.text(0.0, 0.1, \"ticker.FixedLocator([0, 1, 5])\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# Linear Locator\nax = plt.subplot(n, 1, 4)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.LinearLocator(3))\nax.xaxis.set_minor_locator(ticker.LinearLocator(31))\nax.text(0.0, 0.1, \"ticker.LinearLocator(numticks=3)\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# Index Locator\nax = plt.subplot(n, 1, 5)\nsetup(ax)\nax.plot(range(0, 5), [0]*5, color='white')\nax.xaxis.set_major_locator(ticker.IndexLocator(base=.5, offset=.25))\nax.text(0.0, 0.1, \"ticker.IndexLocator(base=0.5, offset=0.25)\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# Auto Locator\nax = plt.subplot(n, 1, 6)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.AutoLocator())\nax.xaxis.set_minor_locator(ticker.AutoMinorLocator())\nax.text(0.0, 0.1, \"ticker.AutoLocator()\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# MaxN Locator\nax = plt.subplot(n, 1, 7)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.MaxNLocator(4))\nax.xaxis.set_minor_locator(ticker.MaxNLocator(40))\nax.text(0.0, 0.1, \"ticker.MaxNLocator(n=4)\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# Log Locator\nax = plt.subplot(n, 1, 8)\nsetup(ax)\nax.set_xlim(10**3, 10**10)\nax.set_xscale('log')\nax.xaxis.set_major_locator(ticker.LogLocator(base=10.0, numticks=15))\nax.text(0.0, 0.1, \"ticker.LogLocator(base=10, numticks=15)\",\n        family=family, fontsize=fontsize, transform=ax.transAxes)\n\n# Push the top of the top axes outside the figure because we only show the\n# bottom spine.\nplt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=1.05)\n\nfig.savefig(ROOT_DIR / \"figures/tick-locators.pdf\", transparent=True)\n# plt.show()\n"
  },
  {
    "path": "scripts/tick-multiple-locator.py",
    "content": "# ----------------------------------------------------------------------------\n# Title:   Scientific Visualisation - Python & Matplotlib\n# Author:  Nicolas P. Rougier\n# License: BSD\n# ----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nimport matplotlib.ticker as ticker\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.style.use([\n    ROOT_DIR / 'styles/base.mplstyle',\n    ROOT_DIR / 'styles/ticks.mplstyle',\n])\n\n\nsubplots_kw = dict(\n    figsize=(5.7/2.54, 0.4/2.54),\n    subplot_kw=dict(xlim=(0, 5), ylim=(0, 1)),\n)\n\n(fig, ax) = plt.subplots(**subplots_kw)\nax.xaxis.set_major_locator(ticker.MultipleLocator(1.0))\nax.xaxis.set_minor_locator(ticker.MultipleLocator(0.2))\nax.xaxis.set_major_formatter(ticker.ScalarFormatter())\nax.xaxis.set_minor_formatter(ticker.ScalarFormatter())\nax.tick_params(axis='both', which='major', labelsize=5)\nax.tick_params(axis='x', which='minor', rotation=90)\n\nfig.savefig(ROOT_DIR / \"figures/tick-multiple-locator.pdf\", transparent=True)\n"
  },
  {
    "path": "scripts/tip-color-range.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\n\n# Scripts to generate all the basic plots\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfig = plt.figure(figsize=(2, 2))\nmpl.rcParams['axes.linewidth'] = 1.5\nd = 0.01\n\nax = fig.add_axes([d, d, 1-2*d, 1-2*d], xticks=[], yticks=[])\n\nX = np.random.seed(1)\nX = np.random.randn(1000, 4)\ncmap = plt.get_cmap(\"Oranges\")\ncolors = [cmap(i) for i in [.1, .3, .5, .7]]\nax.hist(X, 2, density=True, histtype='bar', color=colors)\n\nfig.savefig(ROOT_DIR / \"figures/tip-color-range.pdf\")\n# plt.show()\n"
  },
  {
    "path": "scripts/tip-colorbar.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\n\n# Scripts to generate all the basic plots\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nimport matplotlib.patheffects as path_effects\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfig = plt.figure(figsize=(2.15, 2))\nmpl.rcParams['axes.linewidth'] = 1.5\nd = 0.01\nax = fig.add_axes([d, d, 1-2*d, 1-2*d], xticks=[], yticks=[])\n\nnp.random.seed(1)\nZ = np.random.uniform(0, 1, (8, 8))\ncmap = plt.get_cmap(\"Oranges\")\nim = ax.imshow(Z, interpolation=\"nearest\", cmap=cmap, vmin=0, vmax=2)\ncb = fig.colorbar(im, fraction=0.046, pad=0.04)\ncb.set_ticks([])\n\nfig.savefig(ROOT_DIR / \"figures/tip-colorbar.pdf\")\n# plt.show()\n"
  },
  {
    "path": "scripts/tip-dotted.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\n\n# Scripts to generate all the basic plots\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfig = plt.figure(figsize=(5, .25))\n\nax = fig.add_axes([0, 0, 1, 1], frameon=False,\n                  xticks=[], yticks=[], xlim=[0, 1], ylim=[-.5, 1.5])\n\nepsilon=1e-12\nplt.plot([0, 1], [0, 0], \"black\", clip_on=False, lw=8,\n         ls=(.5, (epsilon, 1)), dash_capstyle=\"round\")\nplt.plot([0, 1], [1, 1], \"black\", clip_on=False, lw=8,\n         ls=(-.5, (epsilon, 2)), dash_capstyle=\"round\")\nfig.savefig(ROOT_DIR / \"figures/tip-dotted.pdf\")\n# plt.show()\n"
  },
  {
    "path": "scripts/tip-dual-axis.py",
    "content": "import pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.rcParams['axes.linewidth'] = 1.5\n\nfig = plt.figure(figsize=(2, 2))\nd = 0.01\nax1 = fig.add_axes([d, d, 1-2*d, 1-2*d], label=\"cartesian\")\nax2 = fig.add_axes([d, d, 1-2*d, 1-2*d], projection=\"polar\", label=\"polar\")\n\nax1.set_xticks([])  # np.linspace(0.0, 0.4, 5))\nax1.set_yticks([])  # np.linspace(0.0, 1.0, 11))\n\nax2.set_rorigin(0)\nax2.set_thetamax(90)\nax2.set_ylim(0.5, 1.0)\nax2.set_xticks(np.linspace(0, np.pi/2, 10))\nax2.set_yticks(np.linspace(0.5, 1.0, 5))\n\nax2.set_xticklabels([])\nax2.set_yticklabels([])\n\nfig.savefig(ROOT_DIR / \"figures/tip-dual-axis.pdf\")\n# plt.show()\n"
  },
  {
    "path": "scripts/tip-font-family.py",
    "content": "# ----------------------------------------------------------------------------\n# Title:   Scientific Visualisation - Python & Matplotlib\n# Author:  Nicolas P. Rougier\n# License: BSD\n# ----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.ticker as ticker\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\n\n# Setup a plot such that only the bottom spine is shown\ndef setup(ax):\n    ax.spines['right'].set_color('none')\n    ax.spines['left'].set_color('none')\n    ax.yaxis.set_major_locator(ticker.NullLocator())\n    ax.spines['top'].set_color('none')\n\n    ax.spines['bottom'].set_position(\"center\")\n\n    ax.xaxis.set_ticks_position('bottom')\n    ax.tick_params(which='major', width=1.00)\n    ax.tick_params(which='major', length=5)\n    ax.tick_params(which='minor', width=0.75)\n    ax.tick_params(which='minor', length=2.5)\n    ax.set_xlim(0, 5)\n    ax.set_ylim(0, 1)\n    ax.patch.set_alpha(0.0)\n\n\nfig = plt.figure(figsize=(5, .5))\nfig.patch.set_alpha(0.0)\nn = 1\n\nfontsize = 18\nax = plt.subplot(n, 1, 1)\nax.tick_params(axis='both', which='minor', labelsize=6)\nsetup(ax)\nax.xaxis.set_major_locator(ticker.MultipleLocator(1.0))\nax.xaxis.set_minor_locator(ticker.MultipleLocator(0.2))\nax.xaxis.set_major_formatter(ticker.ScalarFormatter())\nax.xaxis.set_minor_formatter(ticker.ScalarFormatter())\nax.tick_params(axis='x', which='minor', rotation=0)\n\nfor tick in ax.get_xticklabels(which='both'):\n    tick.set_fontname(\"Roboto Condensed\")\n\nplt.tight_layout()\nfig.savefig(ROOT_DIR / \"figures/tip-font-family.pdf\", transparent=True)\n# plt.show()\n"
  },
  {
    "path": "scripts/tip-hatched.py",
    "content": "import pathlib\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\ncmap = plt.get_cmap(\"Oranges\")\ncolor1, color2 = cmap(0.3), cmap(0.5)\n\nplt.rcParams['hatch.color'] = color1\nplt.rcParams['hatch.linewidth'] = 8\n\nfig = plt.figure(figsize=(2, 2))\nax = plt.subplot()\nnp.random.seed(123)\n\nx1, y1 = 3*np.arange(2), np.random.randint(25, 50, 2)\nx2, y2 = x1+1, np.random.randint(25, 75, 2)\n\nax.bar(x1, y1, color=color2)\nfor x, y in zip(x1, y1):\n    plt.annotate(f\"{y:d}%\", (x, y), xytext=(0, 1),\n                 fontsize=\"x-small\", color=color2,\n                 textcoords=\"offset points\", va=\"bottom\", ha=\"center\")\n\nax.bar(x2, y2, color=color2, hatch=\"/\" )\nfor x, y in zip(x2, y2):\n    plt.annotate(f\"{y:d}%\", (x, y), xytext=(0, 1),\n                 fontsize=\"x-small\", color=color2,\n                 textcoords=\"offset points\", va=\"bottom\", ha=\"center\")\n\nax.set_yticks([])\nax.set_xticks(0.5+np.arange(0, 6, 3))\nax.set_xticklabels([\"2018\", \"2019\"])\nax.tick_params('x', length=0, labelsize=\"small\", which='major')\n\nax.spines['right'].set_visible(False)\nax.spines['left'].set_visible(False)\nax.spines['top'].set_visible(False)\n\nplt.tight_layout()\nfig.savefig(ROOT_DIR / \"figures/tip-hatched.pdf\")\n# plt.show()\n"
  },
  {
    "path": "scripts/tip-multiline.py",
    "content": "# ----------------------------------------------------------------------------\n# Author:  Nicolas P. Rougier\n# License: BSD\n# ----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.rcParams['axes.linewidth'] = 1.5\n\nfig = plt.figure(figsize=(8, 1.5))\ndx, dy = 0.0025, 0.01\nax = fig.add_axes([dx, dy, 1-2*dx, 1-2*dy], frameon=False)\nX, Y = [], []\nfor x in np.linspace(0.01, 10*np.pi-0.01, 100):\n    X.extend([x, x, None])\n    Y.extend([0, np.sin(x), None])\nprint(X[:10], Y[:10])\nplt.plot(X, Y, \"black\")\nplt.xticks([]), plt.yticks([])\nplt.xlim(-0.25, 10*np.pi+.25)\nplt.ylim(-1.5, 1.5)\nplt.tight_layout()\nfig.savefig(ROOT_DIR / \"figures/tip-multiline.pdf\", dpi=100)\n# plt.show()\n"
  },
  {
    "path": "scripts/tip-outline.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\n\n# Scripts to generate all the basic plots\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nimport matplotlib.patheffects as path_effects\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nfig = plt.figure(figsize=(2, 2))\nmpl.rcParams['axes.linewidth'] = 1.5\nd = 0.01\n\nax = fig.add_axes([d, d, 1-2*d, 1-2*d], xticks=[], yticks=[])\n\nnp.random.seed(1)\nZ = np.random.uniform(0, 1, (8, 8))\ncmap = plt.get_cmap(\"Oranges\")\nax.imshow(Z, interpolation=\"nearest\", cmap=cmap, vmin=0, vmax=2)\n\ntext = ax.text(0.5, 0.1, \"Label\", transform=ax.transAxes,\n               color=cmap(0.9), size=32, weight=\"bold\", ha=\"center\", va=\"bottom\")\ntext.set_path_effects([path_effects.Stroke(linewidth=5, foreground='white'),\n                       path_effects.Normal()])\nfig.savefig(ROOT_DIR / \"figures/tip-outline.pdf\")\n"
  },
  {
    "path": "scripts/tip-post-processing.py",
    "content": "import pathlib\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.figure import Figure\nfrom matplotlib.backends.backend_agg import FigureCanvas\nfrom scipy.ndimage import gaussian_filter\n\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\n# First pass for drop-shadow\nfig = Figure(figsize=(6, 1.5))\ncanvas = FigureCanvas(fig)\nax = fig.add_axes([0, 0, 1, 1], frameon=False,\n                  xlim=[0, 1], xticks=[], ylim=[0, 1], yticks=[])\nax.text(0.5, 0.5, \"Matplotlib\", transform=ax.transAxes,\n        ha=\"center\", va=\"center\", size=64, color=\"black\")\ncanvas.draw()\nZ = np.array(canvas.renderer.buffer_rgba())[:, :, 0]\nZ = gaussian_filter(Z, sigma=9)\n\n# Second pass for text + drop-shadow\nfig = plt.figure(figsize=(6, 1.5))\nax = fig.add_axes([0, 0, 1, 1], frameon=False,\n                  xlim=[0, 1], xticks=[], ylim=[0, 1], yticks=[])\nax.imshow(Z, extent=[0, 1, 0, 1], cmap=plt.cm.gray, alpha=0.65, aspect='auto')\nax.text(0.5, 0.5, \"Matplotlib\", transform=ax.transAxes,\n        ha=\"center\", va=\"center\", size=64, color=\"black\")\n\nfig.savefig(ROOT_DIR / \"figures/tip-post-processing.pdf\", dpi=600)\n# plt.show()\n"
  },
  {
    "path": "scripts/tip-transparency.py",
    "content": "# -----------------------------------------------------------------------------\n# Matplotlib cheat sheet\n# Released under the BSD License\n# -----------------------------------------------------------------------------\nimport pathlib\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\nROOT_DIR = pathlib.Path(__file__).parent.parent\n\nmpl.rc('axes', linewidth=1.5)\n\nnp.random.seed(123)\n\nfig = plt.figure(figsize=(2, 2), dpi=100)\nmargin = 0.01\nax = fig.add_axes([margin, margin, 1-2*margin, 1-2*margin])\nn = 500\nX = np.random.normal(0, 0.25, n)\nY = np.random.normal(0, 0.25, n)\nax.scatter(X, Y, s=50, c=\"k\", lw=2)\nax.scatter(X, Y, s=50, c=\"w\", lw=0)\nax.scatter(X, Y, s=40, c=\"C1\", lw=0, alpha=0.1)\n\nax.set_xlim([-1, 1]), ax.set_xticks([]),\nax.set_ylim([-1, 1]), ax.set_yticks([])\nfig.savefig(ROOT_DIR / \"figures/tip-transparency.pdf\")\n# plt.show()\n"
  },
  {
    "path": "styles/base.mplstyle",
    "content": "figure.constrained_layout.use: True\nfigure.constrained_layout.h_pad:  0.01\nfigure.constrained_layout.w_pad:  0.01\nfigure.constrained_layout.hspace: 0.1\nfigure.constrained_layout.wspace: 0.1\n"
  },
  {
    "path": "styles/plotlet-grid.mplstyle",
    "content": "font.family: Source Code Pro\nfont.size: 5\n\naxes.linewidth: 0.5\n\nxtick.major.size: 0.0\nytick.major.size: 0.0\n"
  },
  {
    "path": "styles/plotlet.mplstyle",
    "content": "figure.figsize: 0.4, 0.4\n\nfigure.constrained_layout.h_pad:  0.01\nfigure.constrained_layout.w_pad:  0.01\nfigure.constrained_layout.hspace: 0.01\nfigure.constrained_layout.wspace: 0.01\n\naxes.linewidth: 0.5\n\ngrid.linewidth: 0.2\n\nlines.linewidth: 0.75\n\nxtick.major.size: 0.0\nytick.major.size: 0.0\n\nxtick.labeltop: False\nxtick.labelbottom: False\n\nytick.labelleft: False\nytick.labelright: False\n"
  },
  {
    "path": "styles/sine-plot.mplstyle",
    "content": "font.size: 4\n\naxes.titlesize: 4\naxes.titlepad: 2\naxes.linewidth: 0.2\n\nlines.linewidth: 0.5\nlines.markersize: 3\n\nxtick.labelsize: 3\nxtick.major.pad: 1\nxtick.major.width: 0.2\nxtick.major.size: 1\nxtick.minor.width: 0.1\nxtick.minor.size: 0.5\n\nytick.labelsize: 3\nytick.major.pad: 1\nytick.major.width: 0.2\nytick.major.size: 1\nytick.minor.width: 0.1\nytick.minor.size: 0.5\n\nlegend.fontsize: 3\n"
  },
  {
    "path": "styles/ticks.mplstyle",
    "content": "savefig.transparent: True\n\nfont.size: 5\n\naxes.linewidth: 0.5\naxes.spines.right:  False\naxes.spines.top:    False\naxes.spines.left:   False\naxes.spines.bottom: True\n\nxtick.labelsize: 3\nxtick.major.size: 2\nxtick.major.width: 0.2\nxtick.major.pad: 2\nxtick.minor.size: 1\nxtick.minor.width: 0.2\nxtick.minor.pad: 2\n\nytick.left: False\nytick.labelleft: False\n"
  }
]