Skip to main content

Clean matplotlib plots

Project description

dufte-logo

Da kiekste, wa?

PyPi Version Anaconda Cloud PyPI pyversions GitHub stars PyPi downloads

gh-actions codecov LGTM Code style: black

This package creates clean and beautiful plots that work on light and dark backgrounds. Inspired by the work of Edward Tufte.

To use, simply select the dufte style. Check out dufte.legend() and dufte.ylabel() for more duftness.

import matplotlib.pyplot as plt
import dufte
import numpy as np

plt.style.use(dufte.style)

rng = np.random.default_rng(0)

x0 = np.linspace(0.0, 3.0, 100)
y0 = x0 / (x0 + 1)
y0 += 0.1 * rng.random(len(y0))
plt.plot(x0, y0, label="no balacing")

x1 = np.linspace(0.0, 3.0, 100)
y1 = 1.5 * x1 / (x1 + 1)
y1 += 0.1 * rng.random(len(y1))
plt.plot(x1, y1, label="CRV-27")

x2 = np.linspace(0.0, 3.0, 100)
y2 = 1.6 * x2 / (x2 + 1)
y2 += 0.1 * rng.random(len(y2))
plt.plot(x2, y2, label="CRV-27*")

dufte.ylabel("ylabel")
dufte.legend()

plt.show()

The bar plot is created with dufte.style_bar here and dufte.show_bar_values(). Note the use of context instead of style.use(); both are appropriate.

import matplotlib.pyplot as plt
import dufte


with plt.style.context(dufte.style_bar):
    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))
    plt.bar(xpos, vals)
    plt.xticks(xpos, labels)
    dufte.show_bar_values("{:.2f}")
    plt.title("average temperature [°C]")
    plt.show()

Further reading:

Projects using dufte:

Background

xdoc

The position $x_i$ of the line annotations is computed as the solution of a non-negative least-squares problem

\begin{align}
\frac{1}{2}\sum_i (x_i - t_i)^2 \to \min_x,\\
(x_i - x_j)^2 \ge a^2 \quad \forall i,j.
\end{align}

where $a$ is the minimum distance between two entries and $t_i$ is the target position.

Testing

To run the dufte unit tests, check out this repository and type

pytest

License

This software is published under the GPLv3 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dufte-0.2.24.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dufte-0.2.24-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file dufte-0.2.24.tar.gz.

File metadata

  • Download URL: dufte-0.2.24.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for dufte-0.2.24.tar.gz
Algorithm Hash digest
SHA256 25192f655053f1b04ba04e85e23b9dcefaacdd9a01c00c22e6b321c35531ecb0
MD5 1b66419a3bf38d7a0bd2e2cbc7d1d654
BLAKE2b-256 69fa09f3575b033639ea4120ac31c2408ffcda6485d8b567b46229eb8682ab44

See more details on using hashes here.

File details

Details for the file dufte-0.2.24-py3-none-any.whl.

File metadata

  • Download URL: dufte-0.2.24-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for dufte-0.2.24-py3-none-any.whl
Algorithm Hash digest
SHA256 c6c45f296130f4fdc83d87efea6e849113bf87d70d1597bd2d85725c1d1cf163
MD5 94b299e5059deccc3ea0f09c564bb8ec
BLAKE2b-256 9b93e2ad66ef50df6836168189931f37604b9e5ebb446bed96afbd7ae0d5d0d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page