Skip to main content

mpl-multitab

Tabbed figure manager for matplotlib using pyQt

Ever struggle to navigate between a myriad of open matplotlib figures? I know your pain...

mpl-multitab is a simple application that allows you to embed mutliple figures in a tabbed figure manager, keeping everything neatly in one place.

Install

Using pip:

pip install mpl-multitab

Alternatively, clone the repo, then run the setup.py script

git clone https://github.com/astromancer/mpl-multitab.git
cd mpl-multitab
python setup.py install

Use

Interactive use

At the start of your jupyter notebook, or ipython session, run the line magic to set the qt backend

%matplotlib qt5

Then

# Example use of MplTabs
# Create a scatter plot of `n` random xy-points for each colour
from mpl_multitab import MplTabs


n = 100
colours = 'rgb'
#
ui = MplTabs()
for c in colours:
    fig = ui.add_tab(c)
    ax = fig.subplots()
    ax.scatter(*np.random.randn(2, n), color=c)

ui.set_focus(0)
ui.show()

Demo GIF can be viewed at https://github.com/astromancer/mpl-multitab/blob/main/tests/demo.gif

In a script

# Example using `MplTabs` in a standalone script.
import sys
from mpl_multitab import MplTabs


n = 100
colours = 'rgb'

app = QtWidgets.QApplication(sys.argv)
ui = MplTabs()
for c in colours:
    fig = ui.add_tab(c)
    ax = fig.subplots()
    ax.scatter(*np.random.randn(2, n), color=c)

ui.set_focus(0)
ui.show()
sys.exit(app.exec_())

Groups of Figures

You can group multiple related figures together using the MplMultiTab class. This is useful for visualising, for example, multiple datasets each having multiple observations.

# Example use for MplMultiTab for 2d collection of data sets
# This dataset is equal number observations per dataset. This need not be the
# case in general.
import itertools as itt
from mpl_multitab import MplMultiTab


n = 100
colours = 'rgb'
markers = '123'
#
ui = MplMultiTab(pos='W')
for c, m in itt.product(colours, markers):
    fig = ui.add_tab(f'Dataset {c.upper()}', f'Observation {m}')
    ax = fig.subplots()
    ax.scatter(*np.random.randn(2, n), color=c, marker=f'${m}$')

ui.set_focus(0, 0)
ui.link_focus()
ui.show()

Demo GIF 2 can be viewed at https://github.com/astromancer/mpl-multitab/blob/main/tests/demo2.gif

In this example all the datasets contain the same number of obervations, but this need not be the case in general.

Performance considerations - Delayed plotting

Creating all the figures in one go at startup may take unreasonably long if you have many figures or lots of data. This can be amortised by delaying the plotting of individual figures until the user switches to that tab. This is demonstrated in the following example:

# MplMultiTab with delayed plotting
import itertools as itt
from mpl_multitab import MplMultiTab


n = 10000
colours = 'rgb'
markers = '123'
#
# first create the figures, but don't do the plotting just yet
ui = MplMultiTab(pos='W')
for c, m in itt.product(colours, markers):
    ui.add_tab(f'Dataset {c.upper()}', f'Observation {m}')

# create plotting function
def plot(fig, indices):
    print('Doing plot:', indices)
    i, j = indices
    ax = fig.subplots()
    return ax.scatter(*np.random.randn(2, n),
                      color=colours[i],
                      marker=f'${markers[j]}$')

ui.add_task(plot)   # add your plot worker
ui.set_focus(0, 0)      # this will trigger the plotting for group 0 tab 0
ui.link_focus()         # keep same tab in focus across group switches
ui.show()

Arbitrary nesting

The MplMultiTab class is able to handle nested tabs to any depth. The following example demonstrates the usage pattern for datasets grouped by 3 different features. The same pattern can be used to handle data of any dimensionality. Tabs all the way down!

# MplMultiTab with 3 tab levels
import itertools as itt
from mpl_multitab import MplMultiTab


n = 10
colours = 'rgb'
markers = 'H*P'
hatch = ('xx', '**')
#
ui = MplMultiTab()
for c, m, h in itt.product(colours, markers, hatch):
    # use "&" to tag letters for keyboard shortcuts which select the tab
    #   eg: using "&x" somewhere in the tab name means you can select it with "Alt+x"
    fig = ui.add_tab(f'Colour &{c.upper()}', f'Marker &{m}', f'Hatch &{h}')
    ax = fig.subplots()
    ax.scatter(*np.random.randn(2, n),
               s=750, marker=m, hatch=h,
               edgecolor=c,  facecolor='none')

ui.link_focus()             # keep same tab in focus across group switches
ui.set_focus(0, 0, 0)
ui.show()

Demo GIF 3 can be viewed at https://github.com/astromancer/mpl-multitab/blob/main/tests/demo3.gif

Test

Testing is done with pytest-qt. This will run through all examples in the examples module:

pytest -vs tests/test_multitab.py

Contribute

Contributions are welcome!

  1. Fork it!
  2. Create your feature branch
    git checkout -b feature/rad
  3. Commit your changes
    git commit -am 'Add some cool feature 😎'
  4. Push to the branch
    git push origin feature/rad
  5. Create a new Pull Request

Contact

License

Version

This project uses semantic versioning. The latest version is

  • 1.2.0

Metadata

Release files for mpl-multitab 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mpl-multitab 1.2.0
File Size Uploaded Provenance Actions
mpl_multitab-1.2.0.tar.gz 20.2 kB Without provenance Details for mpl_multitab-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mpl-multitab 1.2.0
File Interpreter ABI Platform Actions
mpl_multitab-1.2.0-py3-none-any.whl Python 3 none any Details for mpl_multitab-1.2.0-py3-none-any.whl

Total release size: 37.3 kB

Release files / mpl_multitab-1.2.0.tar.gz

Download URL mpl_multitab-1.2.0.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
594d5cdca8bd2c6300f5a53f839c2b0358bec01dad82cef7e85b8ae5a8d5a565
BLAKE2b-256 checksum
How to use checksums
b4bb4c92299f01519bcaa9d957af71d7ae6e48cfa0d51702e78f15ad9675946e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / mpl_multitab-1.2.0-py3-none-any.whl

Download URL mpl_multitab-1.2.0-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a5cd4bb602495eef88d974a8c77fbfd4747194315b96428f48b4dd6fd84887d
BLAKE2b-256 checksum
How to use checksums
da6cf7e58b3ea55fb0abaaf24cc19a2484e0993f9797dad0d9f917858e68023a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Security for mpl-multitab 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page