brokenaxes
brokenaxes makes matplotlib plots with breaks in the axes for showing data across a discontinuous range.
Features
- Break x and y axes.
- Supports multiple breaks on a single axis.
- Automatically scales axes according to relative ranges.
- Plot multiple lines.
- Legend with positioning relative to entire broken axes object
- x and y label centered to entire plot
- Make brokenaxes object a subplot itself with
matplotlib.GridSpec.subplot_spec. - xlims and ylims may be
datetime.datetimeobjects - Supports log scales.
Installation
I recommend the Anaconda python distribution and this package is availably via pypi:
pip install brokenaxes
Usage
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
import numpy as np
fig = plt.figure(figsize=(5,2))
bax = brokenaxes(xlims=((0, .1), (.4, .7)), ylims=((-1, .7), (.79, 1)), hspace=.05)
x = np.linspace(0, 1, 100)
bax.plot(x, np.sin(10 * x), label='sin')
bax.plot(x, np.cos(10 * x), label='cos')
bax.legend(loc=3)
bax.set_xlabel('time')
bax.set_ylabel('value')
Create subplots
from brokenaxes import brokenaxes
from matplotlib.gridspec import GridSpec
import numpy as np
sps1, sps2 = GridSpec(2,1)
bax = brokenaxes(xlims=((.1, .3),(.7, .8)), subplot_spec=sps1)
x = np.linspace(0, 1, 100)
bax.plot(x, np.sin(x*30), ls=':', color='m')
x = np.random.poisson(3, 1000)
bax = brokenaxes(xlims=((0, 2.5), (3, 6)), subplot_spec=sps2)
bax.hist(x, histtype='bar')
Log scales
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
import numpy as np
fig = plt.figure(figsize=(5,5))
bax = brokenaxes(xlims=((1, 500), (600, 10000)),
ylims=((1, 500), (600, 10000)),
hspace=.15, xscale='log', yscale='log')
x = np.logspace(0.0, 4, 100)
bax.loglog(x, x, label='$y=x=10^{0}$ to $10^{4}$')
bax.legend(loc='best')
bax.grid(axis='both', which='major', ls='-')
bax.grid(axis='both', which='minor', ls='--', alpha=0.4)
bax.set_xlabel('x')
bax.set_ylabel('y')
plt.show()
Gallery
If you make a plot that you are proud of with this tool, send me a png and code and I'll add it to the gallery!
Life advice
Please use this tool wisely. Any data visualization techique can be used to elucidate trends in the data, and can be used to manipulate and mislead. The latter is particularly true for broken axes plots, so please try to use them responsibly. Other than that, this software is free to use for any purpose.
Release files for brokenaxes 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| brokenaxes-0.4.2.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| brokenaxes-0.4.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 12.8 kB
Release files / brokenaxes-0.4.2.tar.gz
| Download URL | brokenaxes-0.4.2.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dccd7d5e5aacb7128e0f6727505af37ebdcdd8e5f0f35bc126d8d4e0a0a1a10f
|
|
BLAKE2b-256 checksum How to use checksums |
75b071b05ac6ac08de59911ee0392f838cefd76c728616e9e337dc78b92d90dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8
|
Release files / brokenaxes-0.4.2-py2.py3-none-any.whl
| Download URL | brokenaxes-0.4.2-py2.py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
81736cdc0671bab8ae5accc7b53cdc4e99ccd1f8ed9bdc3b9940c60e76283e0b
|
|
BLAKE2b-256 checksum How to use checksums |
69cf91eb9bcab0c40bb52754109281b371edf7febc7ef24e25986650b8aa4fb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8
|