Created
October 8, 2020 02:16
-
-
Save mjkramer/4effe6f0d605e78c86827e7464fbeb58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cobbled together from https://stackoverflow.com/questions/31607458 | |
import io | |
import matplotlib.pyplot as plt | |
from PyQt5.QtGui import QImage | |
from PyQt5.QtWidgets import QApplication | |
def add_clipboard_to_figures(): | |
oldfig = plt.figure | |
def newfig(*args, **kwargs): | |
fig = oldfig(*args, **kwargs) | |
def add_figure_to_clipboard(event): | |
if event.key == "ctrl+c": | |
with io.BytesIO() as buffer: | |
fig.savefig(buffer) | |
image = QImage.fromData(buffer.getvalue()) | |
QApplication.clipboard().setImage(image) | |
fig.canvas.mpl_connect('key_press_event', add_figure_to_clipboard) | |
return fig | |
plt.figure = newfig | |
add_clipboard_to_figures() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment