Skip to main content

Adds a Ctrl+C handler to matplotlib figures for copying the figure to the clipboard

Project description

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.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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

addcopyfighandler-3.2.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

addcopyfighandler-3.2.0-py2.py3-none-any.whl (6.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file addcopyfighandler-3.2.0.tar.gz.

File metadata

  • Download URL: addcopyfighandler-3.2.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for addcopyfighandler-3.2.0.tar.gz
Algorithm Hash digest
SHA256 3785890847cf70c3231900ed9445a0aa1a6cf10bdae598b9ecaa6cffce2eb525
MD5 655726da8d478d16859eab14e4e3e3cf
BLAKE2b-256 63a69bbc1ae3a291476422336ae6f510c98f5a965db29af812372c28f6534f88

See more details on using hashes here.

File details

Details for the file addcopyfighandler-3.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for addcopyfighandler-3.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fc2376b2cb311fa521a72ecdf8923d467a05b4e12b37d5a268320b2631f9f094
MD5 8874ba14134e60c4f026e2487238c7a8
BLAKE2b-256 0ca15c27ba260206ccb52891de086ce90082cf50a1c56f5a4d3bbf8d9b426137

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page