Skip to main content

addcopyfighandler: Add a Ctrl+C / Cmd+C handler to matplotlib figures for copying the figure to the clipboard

Importing this module (after importing matplotlib or pyplot) will add a handler to all subsequently-created matplotlib figures so that pressing Ctrl+C (or Cmd+C on MacOS) with a matplotlib figure window selected will copy the figure to the clipboard as an image. The copied image is generated through matplotlib.pyplot.savefig(), and thus is affected by the relevant rcParams settings (savefig.dpi, savefig.format, etc.).

Uses code & concepts from:

Windows-specific behavior:

  • addcopyfighandler should work regardless of which graphical backend is being used by matplotlib (tkagg, gtk3agg, qtagg, etc.).
  • If matplotlib.rcParams['savefig.format'] is 'svg', the figure will be copied to the clipboard as an SVG.
  • If Pillow is installed, all non-SVG format specifiers will be overridden, and the figure will be copied to the clipboard as a Device-Independant Bitmap.
  • If Pillow is not installed, the supported format specifiers are 'png', 'jpg', 'jpeg', and 'svg'. All other format specifiers will be overridden, and the figure will be copied to the clipboard as PNG data.

Linux-specific behavior:

  • Requires either Qt or GTK libraries for clipboard interaction. Automatically detects which is being used from matplotlib.get_backend().
    • Qt support requires PyQt5, PyQt6, PySide2 or PySide6.
    • GTK support requires pycairo, PyGObject and PIL or pillow to be installed.
      • Only GTK 3 is supported, as GTK 4 has totally changed the way clipboard data is handled and I can't figure it out. I'm totally open to someone else solving this and submitting a PR if they want. I don't use GTK.
  • The figure will be copied to the clipboard as a PNG, regardless of matplotlib.rcParams['savefig.format']. Alas, SVG output is not currently supported. Pull requests that enable SVG support would be welcomed.

MacOS-specific behavior:

  • Requires Qt, whether PyQt5/6 or PySide2/6.
  • The figure will be copied to the clipboard as a PNG, regardless of matplotlib.rcParams['savefig.format'].

Releases

3.2.4: 2024-09-03

3.2.3: 2024-09-03

3.2.2: 2024-06-24

3.2.1: 2024-06-13

  • Made backend checks case-insensitive due to undocumented changes in matplotlib 3.9.

3.2.0: 2024-02-13

  • Added MacOS support (thanks @orlp!). No SVG support, same as Linux.

3.1.1: 2024-02-13

  • Wrap matplotlib.pyploy.figure appropriately to maintain docstring (thanks @eendebakpt!)

3.1.0: 2024-02-13

  • Add support for PyQt6 and PySide6 on Linux (already supported on Windows)

3.0.0: 2021-03-28

  • Add Linux support (tested on Ubuntu). Requires PyQt5, PySide2, or PyObject libraries; relevant library chosen based on matplotlib graphical backend in use. No SVG support.
  • On Windows, non SVG-formats will now use the Pillow library if installed, storing the figure to the clipboard as a device-indepenent bitmap (as previously handled in v2.0). This is compatible with a wider range of Windows applications.

2.1.0: 2020-08-27

  • Remove Pillow.
  • Add support for png & svg file formats.

2.0.0: 2019-06-07

  • Remove Qt requirement. Now use Pillow to grab the figure image, and win32clipboard to manage the Windows clipboard.

1.0.2: 2018-11-27

  • Force use of Qt4Agg or Qt5Agg. Some installs will default to TkAgg backend, which this module doesn't support. Forcing the backend to switch when loading this module saves the user from having to manually specify one of the Qt backends in every analysis.

1.0.1: 2018-11-27

  • Improve setup.py: remove need for importing module, add proper installation dependencies
  • Change readme from ReST to Markdown

1.0: 2017-08-09

  • Initial release

Metadata

Release files for addcopyfighandler 3.2.4

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

Source distribution (sdist)

Source distribution for addcopyfighandler 3.2.4
File Size Uploaded Provenance Actions
addcopyfighandler-3.2.4.tar.gz 5.6 kB Without provenance Details for addcopyfighandler-3.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for addcopyfighandler 3.2.4
File Interpreter ABI Platform Actions
addcopyfighandler-3.2.4-py2.py3-none-any.whl Python 3, Python 2 none any Details for addcopyfighandler-3.2.4-py2.py3-none-any.whl

Total release size: 12.0 kB

Release files / addcopyfighandler-3.2.4.tar.gz

Download URL addcopyfighandler-3.2.4.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b3f2f349a448f27756fa94ca78c485bf8b32b0a81507f719f3b8c1cb33539614
BLAKE2b-256 checksum
How to use checksums
6235e3a2bf8d34601675557e4d3d5023dc911ecc344a9f3e4f818b15a2c3cb9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / addcopyfighandler-3.2.4-py2.py3-none-any.whl

Download URL addcopyfighandler-3.2.4-py2.py3-none-any.whl
Size 6.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
70a0aa648c7d29680d9460f08767a8a1b645a77c2bdefdd5213c5324fd93fee5
BLAKE2b-256 checksum
How to use checksums
504302771c3380d13a91d09ac5aaf693e5a42a457453700536122e65596d06a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Security for addcopyfighandler 3.2.4

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