我在運行以下代碼時使用 Jupyter Notebook,
import matplotlib.pyplot as plt
import numpy as np
a = np.arange(10)
b = np.sin(a)
plt.plot(a,b)
print("After 3 clicks:")
x = plt.ginput(3)
print(x)
plt.show()
運行此代碼時,我收到以下警告
UserWarning: Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure.
x = plt.ginput(3)
由于這個問題,我無法單擊圖形上的點,也無法在輸出中獲得單擊的點。
我系統中的python版本是3.9.7,matplotlib版本是3.4.3。
uj5u.com熱心網友回復:
問題已解決。我在匯入 pyplot 之前使用了 matplotlib.use()。
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
import numpy as np
a = np.arange(10)
b = np.sin(a)
plt.plot(a,b)
print("After 3 clicks:")
x = plt.ginput(3)
print(x)
plt.show()
matplotlib.use('Qt5Agg') 這將非 GUI 后端更改為 Qt5Agg 的 GUI 后端。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/511683.html
