https://github.com/bendichter/brokenaxes

Create matplotlib plots with broken axes

https://github.com/bendichter/brokenaxes

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 9 committers (11.1%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.4%) to scientific vocabulary

Keywords

matplotlib plotting python visualization
Last synced: 5 months ago · JSON representation

Repository

Create matplotlib plots with broken axes

Basic Info
  • Host: GitHub
  • Owner: bendichter
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 1.03 MB
Statistics
  • Stars: 554
  • Watchers: 6
  • Forks: 49
  • Open Issues: 16
  • Releases: 0
Topics
matplotlib plotting python visualization
Created almost 9 years ago · Last pushed 6 months ago
Metadata Files
Readme License

README.md

brokenaxes

brokenaxes logo. Reference: http://www.brianhensley.net/2012/02/python-controlling-spi-bus-on.html

brokenaxes makes matplotlib plots with breaks in the axes for showing data across a discontinuous range.

PyPI PyPI - Downloads codecov

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.datetime objects
  • Supports log scales.

Installation

I recommend the Anaconda python distribution and this package is available via pypi: pip install brokenaxes

Usage

```python 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.setxlabel('time') bax.setylabel('value') ``` example1

Create subplots

```python 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') ``` example2

Log scales

```python 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.setxlabel('x') bax.setylabel('y') plt.show() ``` example3

datetime

```python import matplotlib.pyplot as plt from brokenaxes import brokenaxes import numpy as np import datetime

fig = plt.figure(figsize=(5, 5)) xx = [datetime.datetime(2020, 1, x) for x in range(1, 20)]

yy = np.arange(1, 20)

bax = brokenaxes( xlims=( ( datetime.datetime(2020, 1, 1), datetime.datetime(2020, 1, 3), ), ( datetime.datetime(2020, 1, 6), datetime.datetime(2020, 1, 20), ) ) )

bax.plot(xx, yy)

fig.autofmtxdate() [x.remove() for x in bax.diaghandles] bax.draw_diags()

import matplotlib.dates as mdates for ax in bax.axs: ax.xaxis.setmajorformatter(mdates.DateFormatter('%Y-%b-%d')) ```

datetime_example

text annotation

```python import matplotlib.pyplot as plt from brokenaxes import brokenaxes

fig = plt.figure(figsize=(5, 5)) bax = brokenaxes( xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)) ) bax.text(0.5, 0.5, "hello") ``` text_example

How do I do more?

You can customize brokenaxes outside of the supported features listed above. Brokenaxes works by creating a number of smaller axes objects, with the positions and sizes of those axes dictated by the data ranges used in the constructor. Those individual axes are stored as a list in bax.axs. Most customizations will require accessing those inner axes objects. (See the last two lines of the datetime example). There is also a larger invisible axes object, bax.big_ax, which spans the entire brokenaxes region and is used for things like x and y axis labels which span all of the smaller axes.

Gallery

If you make a plot with this tool that you are proud of, 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, but can also 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. See the license file for details.

Testing

brokenaxes uses pytest-mpl to ensure that the plots are created correctly.

To test that the plots are created correctly, run pytest --mpl --mpl-baseline-path test_baseline test.py from the root directory.

To generate new test plots, run pytest --mpl-generate-path test_baseline test.py from the root directory.

If you are running the tests on a headless server, you may need to set the MPLBACKEND environment variable to Agg.

Owner

  • Name: Ben Dichter
  • Login: bendichter
  • Kind: user
  • Location: Philadelphia
  • Company: CatalystNeuro

Founder of @CatalystNeuro. Computational neuroscience, data standardization, @NeurodataWithoutBorders, data management and visualization, open science

GitHub Events

Total
  • Issues event: 2
  • Watch event: 29
  • Issue comment event: 4
  • Push event: 3
  • Pull request review event: 2
  • Pull request event: 4
  • Fork event: 3
  • Create event: 2
Last Year
  • Issues event: 2
  • Watch event: 29
  • Issue comment event: 4
  • Push event: 3
  • Pull request review event: 2
  • Pull request event: 4
  • Fork event: 3
  • Create event: 2

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 102
  • Total Committers: 9
  • Avg Commits per committer: 11.333
  • Development Distribution Score (DDS): 0.186
Past Year
  • Commits: 2
  • Committers: 1
  • Avg Commits per committer: 2.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Ben Dichter b****r@g****m 83
webersa s****r@u****r 8
Parke Loyd p****d@g****m 3
pharshalp p****p@g****m 2
Samuël Weber/GwendalD s****r@n****g 2
asbjos 5****s 1
ThomasHilger 3****r 1
Duncan Macleod d****b@g****m 1
Danfeng Shan s****f@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 87
  • Total pull requests: 36
  • Average time to close issues: 3 months
  • Average time to close pull requests: 15 days
  • Total issue authors: 81
  • Total pull request authors: 13
  • Average comments per issue: 3.05
  • Average comments per pull request: 0.94
  • Merged pull requests: 28
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 4
  • Pull requests: 2
  • Average time to close issues: 2 months
  • Average time to close pull requests: about 23 hours
  • Issue authors: 4
  • Pull request authors: 2
  • Average comments per issue: 0.75
  • Average comments per pull request: 0.5
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • tvajtay (2)
  • bendichter (2)
  • mardukbp (2)
  • Masoom02 (2)
  • mangoon91 (2)
  • iTomxy (2)
  • tomr-stargazer (1)
  • glennDittmann (1)
  • kanginthaya (1)
  • guiomar (1)
  • Solacex (1)
  • Kalpi-ds (1)
  • ThomasHilger (1)
  • themiyan (1)
  • MTUNG311 (1)
Pull Request Authors
  • bendichter (32)
  • VictorLeP (4)
  • pharshalp (3)
  • weber-s (3)
  • Copilot (2)
  • zougloub (2)
  • micturkey (1)
  • dfshan (1)
  • fredericjs (1)
  • parkus (1)
  • asbjos (1)
  • duncanmmacleod (1)
  • FLawrence (1)
  • R0one (1)
  • ThomasHilger (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 53,018 last-month
  • Total dependent packages: 4
    (may contain duplicates)
  • Total dependent repositories: 31
    (may contain duplicates)
  • Total versions: 14
  • Total maintainers: 1
pypi.org: brokenaxes

Create broken axes

  • Versions: 13
  • Dependent Packages: 4
  • Dependent Repositories: 29
  • Downloads: 53,018 Last month
Rankings
Dependent repos count: 2.7%
Stargazers count: 2.9%
Dependent packages count: 3.1%
Average: 4.0%
Downloads: 5.1%
Forks count: 6.3%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: brokenaxes
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 2
Rankings
Stargazers count: 18.7%
Dependent repos count: 20.2%
Forks count: 28.2%
Average: 29.7%
Dependent packages count: 51.6%
Last synced: 6 months ago

Dependencies

docs/requirements-doc.txt pypi
  • PyQt5 *
  • matplotlib *
  • numpy *
  • sphinx *
  • sphinx-gallery *
setup.py pypi
  • matplotlib >3.4
.github/workflows/cd.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
  • pypa/gh-action-pypi-publish release/v1 composite
.github/workflows/codecov.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
  • codecov/codecov-action v3 composite
requirements-test.txt pypi
  • pytest >=6.0 test
  • pytest-cov * test
  • pytest-mpl ==0.17.0 test
requirements.txt pypi
  • matplotlib >3.6