matplotx
:bar_chart: More styles and useful extensions for Matplotlib
Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 3 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.6%) to scientific vocabulary
Keywords
Repository
:bar_chart: More styles and useful extensions for Matplotlib
Basic Info
Statistics
- Stars: 821
- Watchers: 5
- Forks: 32
- Open Issues: 10
- Releases: 25
Topics
Metadata Files
README.md
Some useful extensions for Matplotlib.
This package includes some useful or beautiful extensions to Matplotlib. Most of those features could be in Matplotlib itself, but I haven't had time to PR yet. If you're eager, let me know and I'll support the effort.
Install with
sh
pip install matplotx[all]
and use in Python with
python
import matplotx
See below for what matplotx can do.
Clean line plots (dufte)
| matplotlib |
matplotx.styles.dufte,
matplotx.ylabeltop,
matplotx.linelabels
|
matplotx.styles.duftify(matplotx.styles.dracula)
|
The middle plot is created with
```python import matplotlib.pyplot as plt import matplotx import numpy as np
create data
rng = np.random.default_rng(0) offsets = [1.0, 1.50, 1.60] labels = ["no balancing", "CRV-27", "CRV-27*"] x0 = np.linspace(0.0, 3.0, 100) y = [offset * x0 / (x0 + 1) + 0.1 * rng.random(len(x0)) for offset in offsets]
plot
with plt.style.context(matplotx.styles.dufte): for yy, label in zip(y, labels): plt.plot(x0, yy, label=label) plt.xlabel("distance [m]") matplotx.ylabeltop("voltage [V]") # move ylabel to the top, rotate matplotx.linelabels() # line labels to the right plt.show() ```
The three matplotx ingredients are:
matplotx.styles.dufte: A minimalistic stylematplotx.ylabel_top: Rotate and move the the y-labelmatplotx.line_labels: Show line labels to the right, with the line color
You can also "duftify" any other style (see below) with
python
matplotx.styles.duftify(matplotx.styles.dracula)
Further reading and other styles:

- Cereblog, Remove to improve: Line Graph Edition
- Show the Data - Maximize the Data Ink Ratio
- Randal S. Olson's blog entry
- prettyplotlib
- Wikipedia: Chartjunk
Clean bar plots
| matplotlib | dufte | dufte with matplotx.showbarvalues() |
The right plot is created with
```python import matplotlib.pyplot as plt import matplotx
labels = ["Australia", "Brazil", "China", "Germany", "Mexico", "United\nStates"] vals = [21.65, 24.5, 6.95, 8.40, 21.00, 8.55] xpos = range(len(vals))
with plt.style.context(matplotx.styles.duftebar): plt.bar(xpos, vals) plt.xticks(xpos, labels) matplotx.showbar_values("{:.2f}") plt.title("average temperature [°C]") plt.show() ```
The two matplotx ingredients are:
matplotx.styles.dufte_bar: A minimalistic style for bar plotsmatplotx.show_bar_values: Show bar values directly at the bars
Extra styles
matplotx contains numerous extra color schemes, e.g., Dracula, Nord, gruvbox, and Solarized, the revised Tableau colors.
```python import matplotlib.pyplot as plt import matplotx
use everywhere:
plt.style.use(matplotx.styles.dracula)
use with context:
with plt.style.context(matplotx.styles.dracula): pass ```
| |
| :----------------------------------------------------------------------------------: |
|
|
|
|
|
|
Many more styles here...
|Other styles:
- John Garrett, Science Plots
- Dominik Haitz, Cyberpunk style
- Dominik Haitz, Matplotlib stylesheets
- Carlos da Costa, The Grand Budapest Hotel
- Danny Antaki, vaporwave aesthetics
- QuantumBlack Labs, QuantumBlack
Smooth contours
| |
|
| :--------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: |
|
plt.contourf | matplotx.contours() |
Sometimes, the sharp edges of contour[f] plots don't accurately represent the
smoothness of the function in question. Smooth contours, contours(), serves as a drop-in replacement.
```python import matplotlib.pyplot as plt import matplotx
def rosenbrock(x): return (1.0 - x[0]) ** 2 + 100.0 * (x[1] - x[0] ** 2) ** 2
im = matplotx.contours( rosenbrock, (-3.0, 3.0, 200), (-1.0, 3.0, 200), logscaling=True, cmap="viridis", outline="white", ) plt.gca().setaspect("equal") plt.colorbar(im) plt.show() ```
Contour plots for functions with discontinuities
| |
|
| :-------------------------------------------------------------------------: | :------------------------------------------------------------------------------: |
|
plt.contour | matplotx.contour(max_jump=1.0) |
Matplotlib has problems with contour plots of functions that have discontinuities. The software has no way to tell discontinuities and very sharp, but continuous cliffs apart, and contour lines will be drawn along the discontinuity.
matplotx improves upon this by adding the parameter max_jump. If the difference between
two function values in the grid is larger than max_jump, a discontinuity is assumed
and no line is drawn. Similarly, min_jump can be used to highlight the discontinuity.
As an example, take the function imag(log(Z)) for complex values Z. Matplotlib's
contour lines along the negative real axis are wrong.
```python import matplotlib.pyplot as plt import numpy as np
import matplotx
x = np.linspace(-2.0, 2.0, 100) y = np.linspace(-2.0, 2.0, 100)
X, Y = np.meshgrid(x, y) Z = X + 1j * Y
vals = np.imag(np.log(Z))
plt.contour(X, Y, vals, levels=[-2.0, -1.0, 0.0, 1.0, 2.0]) # draws wrong lines
matplotx.contour(X, Y, vals, levels=[-2.0, -1.0, 0.0, 1.0, 2.0], maxjump=1.0) matplotx.discontour(X, Y, vals, minjump=1.0, linestyle=":", color="r")
plt.gca().set_aspect("equal") plt.show() ```
Relevant discussions:
spy plots (betterspy)
Show sparsity patterns of sparse matrices or write them to image files.
Example:
```python import matplotx from scipy import sparse
A = sparse.rand(20, 20, density=0.1)
show the matrix
plt = matplotx.spy( A, # borderwidth=2, # bordercolor="red", # colormap="viridis" ) plt.show()
or save it as png
matplotx.spy(A, filename="out.png") ```
|
|
|
| :----------------------------------------------------------: | :------------------------------------------------------------: |
| no colormap | viridis |
There is a command-line tool that can be used to show matrix-market or Harwell-Boeing files:
matplotx spy msc00726.mtx [out.png]
See matplotx spy -h for all options.
License
This software is published under the MIT license.
Owner
- Name: Nico Schlömer
- Login: nschloe
- Kind: user
- Location: Berlin, Germany
- Company: Monday Tech
- Repositories: 97
- Profile: https://github.com/nschloe
Mathematics, numerical analysis, scientific computing, Python. Always interested in new problems.
Citation (CITATION.cff)
cff-version: 1.2.0 message: "If you use this software, please cite it as below." authors: - family-names: "Schlömer" given-names: "Nico" orcid: "https://orcid.org/0000-0001-5228-0946" title: "matplotx: Extensions for Matplotlib" doi: 10.5281/zenodo.5985269 url: https://github.com/nschloe/matplotx license: MIT
GitHub Events
Total
- Watch event: 38
Last Year
- Watch event: 38
Committers
Last synced: 8 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Nico Schlömer | n****r@g****m | 128 |
| RemDelaporteMathurin | r****n@g****m | 7 |
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 14
- Total pull requests: 40
- Average time to close issues: 5 days
- Average time to close pull requests: 2 days
- Total issue authors: 9
- Total pull request authors: 4
- Average comments per issue: 1.0
- Average comments per pull request: 0.15
- Merged pull requests: 37
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 0
- Average comments per issue: 0.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- RemDelaporteMathurin (6)
- joooeey (1)
- adeak (1)
- floringogianu (1)
- ProV1denCEX (1)
- markmbaum (1)
- mitchellvanzuijlen (1)
- nschloe (1)
- exc4l (1)
Pull Request Authors
- nschloe (36)
- RemDelaporteMathurin (2)
- mitchellvanzuijlen (1)
- Philistino (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 3
-
Total downloads:
- pypi 27,586 last-month
-
Total dependent packages: 10
(may contain duplicates) -
Total dependent repositories: 8
(may contain duplicates) - Total versions: 55
- Total maintainers: 1
pypi.org: matplotx
Useful styles and extensions for Matplotlib
- Documentation: https://matplotx.readthedocs.io/
- License: The MIT License (MIT) Copyright (c) 2021-2022 Nico Schlömer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
Latest release: 0.3.10
published over 3 years ago
Rankings
Maintainers (1)
Funding
- https://github.com/sponsors/nschloe
proxy.golang.org: github.com/nschloe/matplotx
- Documentation: https://pkg.go.dev/github.com/nschloe/matplotx#section-documentation
- License: mit
-
Latest release: v0.3.10
published over 3 years ago
Rankings
conda-forge.org: matplotx
- Homepage: https://github.com/nschloe/matplotx
- License: MIT
-
Latest release: 0.3.10
published over 3 years ago
Rankings
Dependencies
- actions/checkout v3 composite
- actions/setup-python v4 composite
- codecov/codecov-action v1 composite
- nschloe/action-cached-lfs-checkout v1 composite
- pre-commit/action v3.0.0 composite