Clean matplotlib plots
Project description
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:
- Remove to improve: data-ink ratio
- Remove to improve: Line Graph Edition
- Show the Data - Maximize the Data Ink Ratio
- Randal S. Olson's blog entry
- prettyplotlib
- Wikipedia: Chartjunk
Projects using dufte:
Background
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25192f655053f1b04ba04e85e23b9dcefaacdd9a01c00c22e6b321c35531ecb0
|
|
| MD5 |
1b66419a3bf38d7a0bd2e2cbc7d1d654
|
|
| BLAKE2b-256 |
69fa09f3575b033639ea4120ac31c2408ffcda6485d8b567b46229eb8682ab44
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6c45f296130f4fdc83d87efea6e849113bf87d70d1597bd2d85725c1d1cf163
|
|
| MD5 |
94b299e5059deccc3ea0f09c564bb8ec
|
|
| BLAKE2b-256 |
9b93e2ad66ef50df6836168189931f37604b9e5ebb446bed96afbd7ae0d5d0d5
|