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

Windows and Linux are currently supported. Pull requests implementing macOS support are welcome.

Uses code & concepts from:

Windows-specific behavior:

  • addcopyfighandler should work regardless of which graphical backend is being used by matplotlib (tkagg, gtk3agg, qt5agg, 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 or PySide2.
    • GTK support requires pycairo, PyGObject and PIL or pillow to be installed.
  • 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.

Releases

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.0.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

addcopyfighandler-3.0.0-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: addcopyfighandler-3.0.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for addcopyfighandler-3.0.0.tar.gz
Algorithm Hash digest
SHA256 1dde55680416d3247bd0da73a64057622425c13b974d5cb13bc10976cd560d09
MD5 daf1bdc0e133bb43027ce553d6b431aa
BLAKE2b-256 d1910c478871688fab5dc79db96ee436f811054e60ec1ce411d595be69b49a3f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: addcopyfighandler-3.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for addcopyfighandler-3.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 30c5054b13ea0ee838f376cd9d3f3e6747a4c08c63c5c5362712e5d0d53ef690
MD5 45fab5821ae61afc11cbf87627971394
BLAKE2b-256 b934d1bcd770df8308aefa739e377cfd1f8d7c6d060866432e8c52e2fc76207d

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