{"id":13689030,"url":"https://github.com/nschloe/matplotx","last_synced_at":"2025-04-08T06:36:31.667Z","repository":{"id":37887736,"uuid":"420713814","full_name":"nschloe/matplotx","owner":"nschloe","description":":bar_chart: More styles and useful extensions for Matplotlib","archived":false,"fork":false,"pushed_at":"2023-01-05T14:22:45.000Z","size":989,"stargazers_count":808,"open_issues_count":10,"forks_count":32,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-01T04:53:34.470Z","etag":null,"topics":["color-scheme","dracula","gruvbox","matplotlib","matplotlib-style-sheets","python","solarized"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nschloe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null}},"created_at":"2021-10-24T14:54:58.000Z","updated_at":"2025-03-25T08:58:11.000Z","dependencies_parsed_at":"2023-02-04T06:31:27.836Z","dependency_job_id":null,"html_url":"https://github.com/nschloe/matplotx","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Fmatplotx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Fmatplotx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Fmatplotx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Fmatplotx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nschloe","download_url":"https://codeload.github.com/nschloe/matplotx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247792892,"owners_count":20996891,"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":["color-scheme","dracula","gruvbox","matplotlib","matplotlib-style-sheets","python","solarized"],"created_at":"2024-08-02T15:01:31.123Z","updated_at":"2025-04-08T06:36:31.623Z","avatar_url":"https://github.com/nschloe.png","language":"Python","readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/nschloe/matplotx\"\u003e\u003cimg alt=\"matplotx\" src=\"https://nschloe.github.io/matplotx/matplotx-logo.svg\" width=\"55%\"\u003e\u003c/a\u003e\n  \u003cp align=\"center\"\u003eSome useful extensions for \u003ca href=\"https://matplotlib.org/\"\u003eMatplotlib\u003c/a\u003e.\u003c/p\u003e\n\u003c/p\u003e\n\n[![PyPi Version](https://img.shields.io/pypi/v/matplotx.svg?style=flat-square)](https://pypi.org/project/matplotx/)\n[![Anaconda Cloud](https://anaconda.org/conda-forge/matplotx/badges/version.svg?=style=flat-square)](https://anaconda.org/conda-forge/matplotx/)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/matplotx.svg?style=flat-square)](https://pypi.org/project/matplotx/)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5985269.svg)](https://doi.org/10.5281/zenodo.5985269)\n[![GitHub stars](https://img.shields.io/github/stars/nschloe/matplotx.svg?style=flat-square\u0026logo=github\u0026label=Stars\u0026logoColor=white)](https://github.com/nschloe/matplotx)\n[![Downloads](https://pepy.tech/badge/matplotx/month)](https://pepy.tech/project/matplotx)\n\n[![gh-actions](https://img.shields.io/github/actions/workflow/status/nschloe/matplotx/tests.yml?branch=main\u0026style=flat-square)](https://github.com/nschloe/matplotx/actions?query=workflow%3Aci)\n[![codecov](https://img.shields.io/codecov/c/github/nschloe/matplotx.svg?style=flat-square)](https://codecov.io/gh/nschloe/matplotx)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black)\n\nThis package includes some useful or beautiful extensions to\n[Matplotlib](https://matplotlib.org/). Most of those features could be in\nMatplotlib itself, but I haven't had time to PR yet. If you're eager, let me\nknow and I'll support the effort.\n\nInstall with\n\n```sh\npip install matplotx[all]\n```\n\nand use in Python with\n\n```python\nimport matplotx\n```\n\nSee below for what matplotx can do.\n\n### Clean line plots (dufte)\n\n\u003ca href=\"tests/dufte_comparison.py\"\u003e\n\u003ctable width=\"100%\"\u003e\n  \u003ctr\u003e\n  \u003ctd width=\"33%\"\u003e\u003cimg src=\"https://nschloe.github.io/matplotx/ex1-mpl.svg\"/\u003e\u003c/td\u003e\n  \u003ctd width=\"33%\"\u003e\u003cimg src=\"https://nschloe.github.io/matplotx/ex1-dufte.svg\"/\u003e\u003c/td\u003e\n  \u003ctd width=\"33%\"\u003e\u003cimg src=\"https://nschloe.github.io/matplotx/ex1-dufte-dracula.svg\"/\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ematplotlib\u003c/td\u003e\n    \u003ctd\u003e\n    \u003ccode\u003ematplotx.styles.dufte\u003c/code\u003e,\n    \u003ccode\u003ematplotx.ylabel_top\u003c/code\u003e,\n    \u003ccode\u003ematplotx.line_labels\u003c/code\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n    \u003ccode\u003ematplotx.styles.duftify(matplotx.styles.dracula)\u003c/code\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/a\u003e\n\nThe middle plot is created with\n\n```python\nimport matplotlib.pyplot as plt\nimport matplotx\nimport numpy as np\n\n# create data\nrng = np.random.default_rng(0)\noffsets = [1.0, 1.50, 1.60]\nlabels = [\"no balancing\", \"CRV-27\", \"CRV-27*\"]\nx0 = np.linspace(0.0, 3.0, 100)\ny = [offset * x0 / (x0 + 1) + 0.1 * rng.random(len(x0)) for offset in offsets]\n\n# plot\nwith plt.style.context(matplotx.styles.dufte):\n    for yy, label in zip(y, labels):\n        plt.plot(x0, yy, label=label)\n    plt.xlabel(\"distance [m]\")\n    matplotx.ylabel_top(\"voltage [V]\")  # move ylabel to the top, rotate\n    matplotx.line_labels()  # line labels to the right\n    plt.show()\n```\n\nThe three matplotx ingredients are:\n\n- `matplotx.styles.dufte`: A minimalistic style\n- `matplotx.ylabel_top`: Rotate and move the the y-label\n- `matplotx.line_labels`: Show line labels to the right, with the line color\n\nYou can also \"duftify\" any other style (see below) with\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nmatplotx.styles.duftify(matplotx.styles.dracula)\n```\n\nFurther reading and other styles:\n\n- [Remove to improve: data-ink ratio](https://www.darkhorseanalytics.com/blog/data-looks-better-naked)\n\n  \u003cimg src=\"https://nschloe.github.io/matplotx/data-ink.webp\" width=\"50%\"/\u003e\n\n- [Cereblog, _Remove to improve: Line Graph Edition_](https://youtu.be/bDbJBWvonVI)\n- [Show the Data - Maximize the Data Ink Ratio](https://youtu.be/pCp0a5_YIWE)\n- [Randal S. Olson's blog entry](http://www.randalolson.com/2014/06/28/how-to-make-beautiful-data-visualizations-in-python-with-matplotlib/)\n- [prettyplotlib](https://github.com/olgabot/prettyplotlib)\n- [Wikipedia: Chartjunk](https://en.wikipedia.org/wiki/Chartjunk)\n\n### Clean bar plots\n\n\u003ca href=\"tests/dufte_comparison.py\"\u003e\n\u003ctable width=\"100%\"\u003e\n  \u003ctr\u003e\n  \u003ctd width=\"33%\"\u003e\u003cimg src=\"https://nschloe.github.io/matplotx/bars-mpl.svg\"/\u003e\u003c/td\u003e\n  \u003ctd width=\"33%\"\u003e\u003cimg src=\"https://nschloe.github.io/matplotx/bars-dufte1.svg\"/\u003e\u003c/td\u003e\n  \u003ctd width=\"33%\"\u003e\u003cimg src=\"https://nschloe.github.io/matplotx/bars-dufte2.svg\"/\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ematplotlib\u003c/td\u003e\n    \u003ctd\u003edufte\u003c/td\u003e\n    \u003ctd\u003edufte with \u003ccode\u003ematplotx.show_bar_values()\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/a\u003e\n\nThe right plot is created with\n\n```python\nimport matplotlib.pyplot as plt\nimport matplotx\n\nlabels = [\"Australia\", \"Brazil\", \"China\", \"Germany\", \"Mexico\", \"United\\nStates\"]\nvals = [21.65, 24.5, 6.95, 8.40, 21.00, 8.55]\nxpos = range(len(vals))\n\nwith plt.style.context(matplotx.styles.dufte_bar):\n    plt.bar(xpos, vals)\n    plt.xticks(xpos, labels)\n    matplotx.show_bar_values(\"{:.2f}\")\n    plt.title(\"average temperature [°C]\")\n    plt.show()\n```\n\nThe two matplotx ingredients are:\n\n- `matplotx.styles.dufte_bar`: A minimalistic style for bar plots\n- `matplotx.show_bar_values`: Show bar values directly at the bars\n\n### Extra styles\n\nmatplotx contains numerous extra color schemes, e.g.,\n[Dracula](https://draculatheme.com/), [Nord](https://www.nordtheme.com/),\n[gruvbox](https://github.com/morhetz/gruvbox), and\n[Solarized](https://ethanschoonover.com/solarized/),\n[the revised Tableau colors](https://www.tableau.com/about/blog/2016/7/colors-upgrade-tableau-10-56782).\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nimport matplotlib.pyplot as plt\nimport matplotx\n\n# use everywhere:\nplt.style.use(matplotx.styles.dracula)\n\n# use with context:\nwith plt.style.context(matplotx.styles.dracula):\n    pass\n```\n\n|    \u003cimg src=\"https://nschloe.github.io/matplotx/aura-dark-soft.svg\" width=\"100%\"\u003e    |\n| :----------------------------------------------------------------------------------: |\n|       \u003cimg src=\"https://nschloe.github.io/matplotx/dracula.svg\" width=\"100%\"\u003e        |\n|     \u003cimg src=\"https://nschloe.github.io/matplotx/gruvbox-dark.svg\" width=\"100%\"\u003e     |\n| \u003cimg src=\"https://nschloe.github.io/matplotx/pitaya-smoothie-dark.svg\" width=\"100%\"\u003e |\n\n\u003cdetails\u003e\n\u003csummary\u003eMany more styles here...\u003c/summary\u003e\n\n|       \u003cimg src=\"https://nschloe.github.io/matplotx/aura-dark.svg\" width=\"100%\"\u003e       |\n| :-----------------------------------------------------------------------------------: |\n|       \u003cimg src=\"https://nschloe.github.io/matplotx/ayu-dark.svg\" width=\"100%\"\u003e        |\n|       \u003cimg src=\"https://nschloe.github.io/matplotx/ayu-light.svg\" width=\"100%\"\u003e       |\n|      \u003cimg src=\"https://nschloe.github.io/matplotx/ayu-mirage.svg\" width=\"100%\"\u003e       |\n|    \u003cimg src=\"https://nschloe.github.io/matplotx/challenger-deep.svg\" width=\"100%\"\u003e    |\n|      \u003cimg src=\"https://nschloe.github.io/matplotx/github-dark.svg\" width=\"100%\"\u003e      |\n|     \u003cimg src=\"https://nschloe.github.io/matplotx/github-dimmed.svg\" width=\"100%\"\u003e     |\n|     \u003cimg src=\"https://nschloe.github.io/matplotx/github-light.svg\" width=\"100%\"\u003e      |\n|     \u003cimg src=\"https://nschloe.github.io/matplotx/gruvbox-light.svg\" width=\"100%\"\u003e     |\n|         \u003cimg src=\"https://nschloe.github.io/matplotx/nord.svg\" width=\"100%\"\u003e          |\n|       \u003cimg src=\"https://nschloe.github.io/matplotx/one-dark.svg\" width=\"100%\"\u003e        |\n|        \u003cimg src=\"https://nschloe.github.io/matplotx/pacoty.svg\" width=\"100%\"\u003e         |\n| \u003cimg src=\"https://nschloe.github.io/matplotx/pitaya-smoothie-light.svg\" width=\"100%\"\u003e |\n|    \u003cimg src=\"https://nschloe.github.io/matplotx/solarized-dark.svg\" width=\"100%\"\u003e     |\n|    \u003cimg src=\"https://nschloe.github.io/matplotx/solarized-light.svg\" width=\"100%\"\u003e    |\n|      \u003cimg src=\"https://nschloe.github.io/matplotx/tableau-10.svg\" width=\"100%\"\u003e       |\n|      \u003cimg src=\"https://nschloe.github.io/matplotx/tableau-20.svg\" width=\"100%\"\u003e       |\n|    \u003cimg src=\"https://nschloe.github.io/matplotx/tokyo-night-day.svg\" width=\"100%\"\u003e    |\n|   \u003cimg src=\"https://nschloe.github.io/matplotx/tokyo-night-night.svg\" width=\"100%\"\u003e   |\n|   \u003cimg src=\"https://nschloe.github.io/matplotx/tokyo-night-storm.svg\" width=\"100%\"\u003e   |\n\n\u003c/details\u003e\n\nOther styles:\n\n- [John Garrett, _Science Plots_](https://github.com/garrettj403/SciencePlots)\n- [Dominik Haitz, _Cyberpunk style_](https://github.com/dhaitz/mplcyberpunk)\n- [Dominik Haitz, _Matplotlib stylesheets_](https://github.com/dhaitz/matplotlib-stylesheets)\n- [Carlos da Costa, _The Grand Budapest Hotel_](https://github.com/cako/mpl_grandbudapest)\n- [Danny Antaki, _vaporwave aesthetics_](https://github.com/dantaki/vapeplot)\n- [QuantumBlack Labs, _QuantumBlack_](https://github.com/quantumblacklabs/qbstyles)\n\n### Smooth contours\n\n| \u003cimg src=\"https://nschloe.github.io/matplotx/mpl-contourf.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://nschloe.github.io/matplotx/matplotx-contours.svg\" width=\"100%\"\u003e |\n| :--------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: |\n|                                `plt.contourf`                                |                               `matplotx.contours()`                               |\n\nSometimes, the sharp edges of `contour[f]` plots don't accurately represent the\nsmoothness of the function in question. Smooth contours, `contours()`, serves as a drop-in replacement.\n\n```python\nimport matplotlib.pyplot as plt\nimport matplotx\n\n\ndef rosenbrock(x):\n    return (1.0 - x[0]) ** 2 + 100.0 * (x[1] - x[0] ** 2) ** 2\n\n\nim = matplotx.contours(\n    rosenbrock,\n    (-3.0, 3.0, 200),\n    (-1.0, 3.0, 200),\n    log_scaling=True,\n    cmap=\"viridis\",\n    outline=\"white\",\n)\nplt.gca().set_aspect(\"equal\")\nplt.colorbar(im)\nplt.show()\n```\n\n### Contour plots for functions with discontinuities\n\n| \u003cimg src=\"https://nschloe.github.io/matplotx/contour-mpl.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://nschloe.github.io/matplotx/contour-matplotx.svg\" width=\"100%\"\u003e |\n| :-------------------------------------------------------------------------: | :------------------------------------------------------------------------------: |\n|                                `plt.contour`                                |                         `matplotx.contour(max_jump=1.0)`                         |\n\nMatplotlib has problems with contour plots of functions that have discontinuities. The\nsoftware has no way to tell discontinuities and very sharp, but continuous cliffs apart,\nand contour lines will be drawn along the discontinuity.\n\nmatplotx improves upon this by adding the parameter `max_jump`. If the difference between\ntwo function values in the grid is larger than `max_jump`, a discontinuity is assumed\nand no line is drawn. Similarly, `min_jump` can be used to highlight the discontinuity.\n\nAs an example, take the function `imag(log(Z))` for complex values Z. Matplotlib's\ncontour lines along the negative real axis are wrong.\n\n```python\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nimport matplotx\n\nx = np.linspace(-2.0, 2.0, 100)\ny = np.linspace(-2.0, 2.0, 100)\n\nX, Y = np.meshgrid(x, y)\nZ = X + 1j * Y\n\nvals = np.imag(np.log(Z))\n\n# plt.contour(X, Y, vals, levels=[-2.0, -1.0, 0.0, 1.0, 2.0])  # draws wrong lines\n\nmatplotx.contour(X, Y, vals, levels=[-2.0, -1.0, 0.0, 1.0, 2.0], max_jump=1.0)\nmatplotx.discontour(X, Y, vals, min_jump=1.0, linestyle=\":\", color=\"r\")\n\nplt.gca().set_aspect(\"equal\")\nplt.show()\n```\n\nRelevant discussions:\n\n- [matplotlib/issues/21348](https://github.com/matplotlib/matplotlib/issues/21348)\n\n### spy plots (betterspy)\n\nShow sparsity patterns of sparse matrices or write them to image files.\n\nExample:\n\n```python\nimport matplotx\nfrom scipy import sparse\n\nA = sparse.rand(20, 20, density=0.1)\n\n# show the matrix\nplt = matplotx.spy(\n    A,\n    # border_width=2,\n    # border_color=\"red\",\n    # colormap=\"viridis\"\n)\nplt.show()\n\n# or save it as png\nmatplotx.spy(A, filename=\"out.png\")\n```\n\n| \u003cimg src=\"https://nschloe.github.io/matplotx/spy-plain.png\"\u003e | \u003cimg src=\"https://nschloe.github.io/matplotx/spy-viridis.png\"\u003e |\n| :----------------------------------------------------------: | :------------------------------------------------------------: |\n|                         no colormap                          |                            viridis                             |\n\nThere is a command-line tool that can be used to show\n[matrix-market](https://math.nist.gov/MatrixMarket/) or\n[Harwell-Boeing](https://en.wikipedia.org/wiki/Harwell-Boeing_file_format) files:\n\n```\nmatplotx spy msc00726.mtx [out.png]\n```\n\nSee `matplotx spy -h` for all options.\n\n### License\n\nThis software is published under the [MIT license](LICENSE).\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnschloe%2Fmatplotx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnschloe%2Fmatplotx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnschloe%2Fmatplotx/lists"}