{"id":13856713,"url":"https://github.com/alopezrivera/mpl_plotter","last_synced_at":"2025-04-07T07:03:45.904Z","repository":{"id":45284625,"uuid":"280358473","full_name":"alopezrivera/mpl_plotter","owner":"alopezrivera","description":"Publication-quality data representation library based on Matplotlib.","archived":false,"fork":false,"pushed_at":"2022-11-11T19:48:14.000Z","size":216965,"stargazers_count":167,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T06:01:45.419Z","etag":null,"topics":["matplotlib","python","visualization"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alopezrivera.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-17T07:34:37.000Z","updated_at":"2024-10-21T14:21:43.000Z","dependencies_parsed_at":"2022-07-14T13:20:32.394Z","dependency_job_id":null,"html_url":"https://github.com/alopezrivera/mpl_plotter","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alopezrivera%2Fmpl_plotter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alopezrivera%2Fmpl_plotter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alopezrivera%2Fmpl_plotter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alopezrivera%2Fmpl_plotter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alopezrivera","download_url":"https://codeload.github.com/alopezrivera/mpl_plotter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608150,"owners_count":20965952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["matplotlib","python","visualization"],"created_at":"2024-08-05T03:01:10.206Z","updated_at":"2025-04-07T07:03:45.857Z","avatar_url":"https://github.com/alopezrivera.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# MPL Plotter \n\n![.coverage available in tests/coverage/](tests/coverage/coverage.svg) [![Monthly downloads](https://pepy.tech/badge/mpl-plotter/month)](https://pepy.tech/project/mpl_plotter)\n\nMPL Plotter is a Python plotting library built on top of Matplotlib with the goal of delivering publication-quality plots \nconcisely. [The full API documentation is available here](https://mpl-plotter-docs.github.io/). Read on to get started.\n\n[![Putting it all together.](demo/gallery/showcase/demo.png)](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/demo.py)\n\n### Table of Contents\n\n[ **1. Introduction** ](#1-introduction)\n\n[ **2. Install**  ](#2-install)\n\n[ **3. Map of the library** ](#3-map-of-the-library)\n\n[ **4. Getting started** ](#4-getting-started)\n\n[ 4.1 2D ](#41-2d)\n\n[ 4.2 3D ](#42-3d)    \n\n[ **5. Comparisons and side by side plots** ](#5-curve-comparisons-and-multiple-pane-plots)\n\n[ _5.1_ `comparison` ](#51-comparison)\n\n[ _5.2_ `panes` ](#52-panes)\n\n[ **6. Presets** ](#6-presets)\n\n[ 6.1 Standard presets ](#61-standard-presets)\n\n[ 6.2 Custom presets ](#62-custom-presets)\n\n[ **7. Matplotlib** ](#7-matplotlib)\n\n[ 7.1 Retrieving axes, figures ](#71-retrieving-axes-figures)\n\n[ 7.2 Using Matplotlib's axis tiling ](#72-using-matplotlibs-axis-tiling)\n\n# 1. Introduction \n\nMaking plots for technical documents can be a time sink. MPL Plotter aims to \nreduce that overhead by allowing you to effortlessly and concisely\n- Generate publication quality plots with a single call\n- Plot curve [comparisons](#51-comparison)\n- Create figures with [many plots](#52-panes)\n\nIt is opinionated but built with flexibility in mind, which means that\n- No default can't be changed\n- Any and all further customization with Matplotlib is compatible. From ticks to legends to extra axes to whatever suits your needs\n\nThere's two ways to use MPL Plotter (plus any Matplotlib before or after):\n- Calls to the 2D and 3D [plotting methods](#4-getting-started)\n- Using [presets](#6-presets), either those shipped with the library, or custom ones\n\nIt does the job for me and I expand it when it can't. Hope you find some use in it!\n\n# 2. Install\n\n`pip install mpl_plotter`\n\nAll dependencies will be checked for and installed automatically. They can be found in `setup.py` \nunder `install_requires`.\n\n# 3. Map of the library\n\nThis is the map of the library for import reference. \n\n| module | class | function |\n| --- | --- | --- |\n| **module** | `class` | function |\n\n- **mpl_plotter**\n    - figure\n    - get_available_fonts\n    - `markers`\n    - **two_d**\n        - `line`\n        - `scatter`\n        - `heatmap`\n        - `quiver`\n        - `streamline`\n        - `fill_area`\n        - `comparison`\n        - `panes`\n    - **three_d**\n        - `line`\n        - `scatter`\n        - `surface`\n    - **presets**\n        - **publication**\n            - `two_d`\n            - `three_d`\n        - **precision**\n            - `two_d`\n            - `three_d`\n        - **preset**\n\t        - `preset`\n            - `two_d`\n            - `three_d`\n    - **color**\n        - **schemes**\n            - colorscheme_one\n\t    - **functions**\n           - complementary\n           - delta\n\t    - **maps**\n\t        - custom\n           - mapstack\n\n# 4. Getting started\n\nIn this section we'll go from the the most basic plot to a fairly customized version in 2 and 3 dimensions. \nThe line demo scripts can be found in `demo/scripts/line_demos/`.\n\n### 4.1 2D\n\nFor this example I'll use the 2D `line` class. Except for plot-specific arguments (line width etc. in this case), \nyou can use the same inputs in this example with any of the other 2D plotting classes. Check the [API reference](https://mpl-plotter-docs.github.io/)\nfor all general and specific arguments, or call `help(\u003cplotting class\u003e)` in your shell to access the docstrings. \n\nAs follows from the map above, the import to use the 2D `line` class is:\n\n    from mpl_plotter.two_d import line\n\nAnd the following is the most basic MPL Plotter call, which will generate the image below (no input, and sin wave \nrespectively).\n    \n| `line(show=True)` | `x = np.linspace(0, 2*np.pi, 100)`\u003cbr\u003e`y = np.sin(x)`\u003cbr\u003e`line(x=x, y=y, show=True)` |\n| --- | :--- |\n| ![alt text](demo/gallery/2d/basic_line.png \"Base output\") | ![alt text](demo/gallery/2d/line_input.png \"sin wave\") \n\nTwo important features are apparent:\n1. MPL Plotter provides mock plots for every plotting class, so you can get straight into action and see what each does\n2. MPL Plotter is somewhat \"opinionated\" and sets up quite a few parameters by default. This is based purely on my \npreference. You may not agree and you're more than welcome to play around with them!\n\n---\n\nTwo more examples (results in the table below):\n\n1. We can add some customization to make our line look a bit better:\n\n        line(show=True, pad_demo=True, spines_removed=None)\n\n    Our line has now some margins to breathe while the ticks are placed at the maximum and minimums of our curve, \n    and no spines are removed.\n\n2. Lastly, an example using some of the parameters you can change:\n\n        line(norm=True, line_width=4,\n         \n             title=\"Custom Line\", title_font=\"Pump Triline\", title_size=40, title_color=\"orange\",\n \n             label_x=\"x\", label_y=\"$\\Psi$\",\n             label_size_x=30, label_size_y=20,\n             label_pad_x=-0.05, label_pad_y=10,\n             label_rotation_y=0,\n \n             aspect=1,\n             pad_demo=True,\n             workspace_color=\"darkred\",\n             grid=True, grid_color=\"grey\",\n             \n             tick_color=\"darkgrey\", tick_decimals=4,\n             tick_number_x=12, tick_number_y=12,\n             tick_rotation_x=35,\n \n             color_bar=True, cb_tick_number=5, cb_pad=0.05,\n \n             show=True)\n\n| [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L13) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L21) |\n| --- | --- |\n| ![alt text](demo/gallery/2d/medium_line.png \"Some customization\") | ![alt text](demo/gallery/2d/custom_line.png \"Showcase\") |\n\n### 4.2 3D\n\nSame applies in 3D.\n\n| [0](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L5) | [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L15) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L31) |\n|---|---|---|\n|![alt text](demo/gallery/3d/basic_line.png \"Basic\")|![alt text](demo/gallery/3d/medium_line.png \"Some customization\")|![alt text](demo/gallery/3d/custom_line.png \"Showcase\")|\n\n# 5. Curve comparisons and multiple pane plots\n\n`from mpl_plotter.two_d import comparison, panes`\n\n### 5.1 `comparison`\n\nPlot any number of curves in a single plot. Axis limits will be set to the maximum and minimum of all your curves. \nNo data will be left out, among other niceties.\n\n#### Data input\n\nInputs must match (2 `x`s and 3 `y`s won't work), BUT the following inputs are all valid:\n|   x                      |   y                       |  result  |  notes               |\n|  ---                     |  ---                      |  ---     |  ---                 |\n|  array                   |  array                    |  1       |                      |\n|  array                   |  [array, array]           |  2       |  Both `y`s share `x` |\n|  [array, array]          |  [array, array]           |  2       |  Each `y` has an `x` |\n|  [n*[array]]             |  [n*[array]]              |  n       |  Each `y` has an `x` |\n\n#### Plotting methods\n\nYou can specify **different plotting methods for each curve in the plot**, a custom one for all curves, \nor not specify any (defaulting to lines). How? Check the code block below. \n\nThis is nice as it allows you to crisply combine lines, scatter plots and any other of the MPL Plotter\nplotting methods.\n\n#### Other arguments\n\nAs to any and all other arguments:\n- **Singular arguments**: the regular MPL Plotter plotting class arguments. Apply to all curves in the plot.\n- **Plural arguments**: pass a list of arguments, one for each curve. The result is as you'd imagine.\n\n```\nfrom mpl_plotter.two_d import comparison, line, scatter\n        \ndef f(x, y, **kwargs):\n    line(x, y,\n         line_width=2,\n         **kwargs)\ndef g(x, y, **kwargs):\n    scatter(x, y,\n            marker=\"D\",\n            point_size=10,\n            **kwargs)\ndef h(x, y, **kwargs):\n    scatter(x, y,\n            marker=\"s\",\n            point_size=5,\n            **kwargs)\n\ncomparison([x, x, x],\n           [u, v, w],\n           [f, g, h],\n           plot_labels=[\"sin\", \"cos\", \"tan\"],\n           zorders=[1, 2, 3],\n           colors=['C1', 'C2', 'C3'],\n           alphas=[0.5, 0.5, 1],\n           x_custom_tick_labels=[0, r\"$\\frac{\\pi}{8}$\", r\"$\\frac{\\pi}{4}$\"],\n           show=show, backend=backend\n           )\n```\n\n![alt text](demo/gallery/2d/comparison_custom.png \"Curve comparison\")\n \n\n### 5.2 `panes`\n \nThe panes function allows for the plotting of a series of graphs in side-by-side panes. As to data input, the table below applies. \nIt uses the `comparison`, function under the hood so the same input guidelines apply for all other inputs.\n\n|   x                              |   y                               |  result  |  notes                                          |\n|  ---                             |  ---                              |  ---     |  ---                                            |\n|  array                           |  array                            |  11      |                                                 |\n|  array                           |  [array, array]                   |  12      |  Both `y`s share `x`                            |\n|  [n*[array]]                     |  [n*[array]]                      |  1n      |  Each `y` has an `x`                            |\n|  array                           |  [array, array]                   |  21      |  Both `y`s share `x`                            |\n|  [array, array]                  |  [array, array]                   |  21      |  Each `y` has an `x`                            |\n|  array                           |  [n*[array], n*[array]]           |  2n      |  All curves in all (2) panes share a single `x` |\n|  [array, array]                  |  [n*[array], n*[array]]           |  2n      |  All curves in each pane share an `x`           |\n|  [n*[array], n*[array]]          |  [n*[array], n*[array]]           |  2n      |  All curves in all (2) panes have their own `x` |\n|  [n*[array], ... up to m]        |  [n*[array], ... up to m]         |  mn      |  All curves in all panes have their own `x`     |\n\n### Code\n\nThe following plots one curve per pane (3 in total):\n     \n```\npanes(x,                   # Horizontal vector\n      [u, v, y],           # List of curves to be plotted\n      [\"u\", \"v\", \"y\"],     # List of vertical axis labels\n      [\"a\", \"b\", \"c\"]      # List of legend labels \n      )\n```\n\n![alt text](demo/gallery/2d/pane_single.png \"Single-curve panes\")\n\nAnd the following plots an arbitrary number of curves per pane. As you can see, you just need to input \n`n` **lists** of `m` curves (where `m`=2 in the example below), and you will get a plot with `n` panes, with `m`\ncurves in each.\n\n```\npanes(x,                               # Horizontal vector\n      [[u, uu], [v, vv], [y, yy]],     # List of pairs of curves to be compared\n      [\"u\", \"v\", \"y\"],                 # List of vertical axis labels\n      [\"a\", \"b\"]                       # List of legend labels\n      )\n```\n\n![alt text](demo/gallery/2d/pane_comparison.png \"Multiple-curve comparison panes\")\n\n### Demo\n\nPreposterous demonstration to illustrate the **n** panes, **m** curves concept. The code for these is\navailable in `tests/test_panes.py`.\n\n![alt text](demo/gallery/2d/pane_alot.png \"There's a lot\")\n\n![alt text](demo/gallery/2d/pane_alot_comparison.png \"Lots of triplets\") \n\n# 6. Presets\n\nTL;DR: Take a parameter `toml` and forget about function inputs.\n\n### 6.1 Standard presets\n\nStandard presets are available to remove overhead. They're tailored for my use cases but you may find them useful anyway.\n\n| ![alt text](demo/gallery/2d/preset_publication_scatter.png \"Publication preset\")| ![alt text](demo/gallery/2d/preset_publication_heatmap.png \"Publication preset\") | ![alt text](demo/gallery/2d/preset_publication_quiver.png \"Publication preset\") | ![alt text](demo/gallery/2d/preset_publication_streamline.png \"Publication preset\") | ![alt text](demo/gallery/2d/preset_publication_fill.png \"Publication preset\") | ![alt text](demo/gallery/3d/preset_publication_line.png \"Publication preset\") | ![alt text](demo/gallery/3d/preset_publication_scatter.png \"Publication preset\") | ![alt text](demo/gallery/3d/preset_publication_surface.png \"Publication preset\") |\n| --- | --- | --- | --- | --- | --- | --- | --- |\n| ![alt text](demo/gallery/2d/preset_precision_scatter.png \"Precision preset\")| ![alt text](demo/gallery/2d/preset_precision_heatmap.png \"Precision preset\") | ![alt text](demo/gallery/2d/preset_precision_quiver.png \"Precision preset\") | ![alt text](demo/gallery/2d/preset_precision_streamline.png \"Precision preset\") | ![alt text](demo/gallery/2d/preset_precision_fill.png \"Precision preset\") | ![alt text](demo/gallery/3d/preset_precision_line.png \"Precision preset\") | ![alt text](demo/gallery/3d/preset_precision_scatter.png \"Precision preset\") | ![alt text](demo/gallery/3d/preset_precision_surface.png \"Precision preset\") | \n\n#### _Publication_\nIt is a common mistake to make a figure for a paper with unreadable labels. This preset tries to solve that, \ngenerating plots optimized to be printed on a small format, in side-by-side plots or embedded in a column of text.\n\n    from mpl_plotter.presets.precision import two_d\n    from mpl_plotter.color.schemes import one           # Custom colorscheme\n\n    x = np.linspace(0, 4, 1000)\n    y = np.exp(x)\n    z = abs(np.sin(x)*np.exp(x))\n    \n    two_d.line(x, z, aspect=0.05, color=one()[-2], show=True)\n    \n![alt text](demo/gallery/2d/preset_publication_line.png \"Publication preset\")\n\n#### _Precision_\n\nMade to plot functions large on the screen, with equal x and y scales to avoid skewing the variables, and \nmany ticks to visually inspect a signal.\n\n    from mpl_plotter.presets.precision import two_d\n    \n    two_d.line(x, z, aspect=0.05, color=one()[-2], show=True)\n\n![alt text](demo/gallery/2d/preset_precision_line.png \"Precision preset\")\n\n### 6.2 Custom presets\n\nExample workflow follows. For further reference check [the preset tests](https://github.com/alopezrivera/mpl_plotter/blob/master/tests/test_presets.py).\n\n1. Import the preset creation function\n      ```\n      from mpl_plotter.presets import preset\n      ```\n\n2. Create a preset, either from a plotter,\n      ```\n      from mpl_plotter.two_d import line\n\n      _preset = preset(line)\n      ```\n   \n   or from a dimension. In this case, the preset will contain all common parameters to all plots\n   in 2 or 3 dimensions.\n      ```\n      _preset = preset(dim=2)\n      ```\n\t\n   The preset is a dictionary. You can edit its parameters as you would expect. However, it is more convenient to\n\n3. Save your preset in a `toml` file. This will yield you a `toml` file containing all parameters for your plot or dimension, allowing you to easily inspect defaults and tailor settings to your liking. You may edit this file as you please, as long as you do not infringe on its syntax.\n      ```\n      _preset.save('tests/presets/test.toml')\n      ```\n\n4. Load the file in the same -or a different session.\n      ```\n      from mpl_plotter.presets import preset\n\n      _preset = preset.load('tests/presets/test.toml')\n      ```\n\n5. Import an MPL Plotter preset plotter and load it with your preset\n      ```\n      from mpl_plotter.presets import two_d\n\n      _two_d = two_d(preset=_preset)\n      ```\n\n6. Plot as you wish\n      ```\n      _two_d.line(show=True)\n      _two_d.scatter(show=True)\n      _two_d.\u003c...\u003e\n      ```\n\n# 7. Matplotlib\n### 7.1 Retrieving axes, figures\n\nThe axis and figure on which each class draws are instance attributes. To retrieve them and continue modifications \nusing standard Matplotlib:\n    \n    from mpl_plotter.two_d import line\n    \n    my_plot = line()\n    ax, fig = my_plot.ax, my_plot.fig\n    \nWith the axis and figure, most Matplotlib functions out there can be used to further modify your plots. \n\n### 7.2 Using Matplotlib's axis tiling\n\nMatplotlib allows for subplot composition using `subplot2grid`. This can be used in combination with MPL Plotter:\n\nImportantly:\n- The auxiliary function `figure` (`from mpl_plotter figure`) sets up a figure in a chosen backend. \nThis is convenient, as if the figure is created with `plt.figure()`, only the default non-interactive Matplotlib \nbackend will be available, unless `matplotlib.use(\u003cbackend\u003e)` is specified before importing `pyplot`.\n\n```\nfrom mpl_plotter import figure\nfrom mpl_plotter.two_d import line, quiver, streamline, fill_area\n\nbackend = \"Qt5Agg\"  # None -\u003e regular non-interactive matplotlib output\n\nfigure(figsize=(10, 10), backend=backend)\n\nax0 = plt.subplot2grid((2, 2), (0, 0), rowspan=1)\nax1 = plt.subplot2grid((2, 2), (1, 0), rowspan=1)\nax2 = plt.subplot2grid((2, 2), (0, 1), rowspan=1)\nax3 = plt.subplot2grid((2, 2), (1, 1), rowspan=1)\n\naxes = [ax0, ax1, ax2, ax3]\nplots = [line, quiver, streamline, fill_area]\n\nfor i in range(len(plots)):\n    plots[i](ax=axes[i])\n\nplt.show()\n```\n\n![alt text](demo/gallery/2d/grid.png \"Grid sample\")       \n\n---\n\n[Back to top](#mpl-plotter)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falopezrivera%2Fmpl_plotter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falopezrivera%2Fmpl_plotter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falopezrivera%2Fmpl_plotter/lists"}