'Python, unstable behavior of addcopyfighandler
I found the following strange (unstable) behavior of the Python addcopyfighandler package. I use the same code in two computers, #1 and #2
import matplotlib.pyplot as plt
import numpy as np
import addcopyfighandler
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s)
ax.set(xlabel='time (s)', ylabel='voltage (mV)',
title='About as simple as it gets, folks')
ax.grid()
fig.savefig("test.png")
plt.show()
In #1 computer, I addcopyfighandler works as expectedly fine, with the use of ctrl+C, I can copy and then paste the plot to the paint program. But in #2 computer, after ctrl+C, the clipboard is empty, so after pasting (ctrl+V), the paint program is empty. Only the one difference I have found visually, in #1 computer the matplotlib-navigationtoolbar of plt figure is in the top, but in #2 the matplotlib-navigationtoolbar of plt is in the bottom, see image. I use Python 3.10 (Win-10). How to overcome this issue and copy the figure by ctrl+C for all cases? I use Python 3.10 (Win-10). Thanks. enter image description here
Solution 1:[1]
The answer is simple: computer #1 has pyqt5 installed and computer #2 does not. After installing pip [enter pip install pyqt5 in a console] on computer #2, the same toolbar menu appeared in Fig. 2 as in Fig. 1. Moreover, after installing pyqt5, the addcopyfighandler package (import addcopyfighandler) starts working on computer #2 in the same way as on computer #1. So, both problems are solved by installing pyqt5.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joooeey |
