我正在尝试用Jupyter Notebook绘制一个数字并将其作为输入提供给神经网络进行预测。
我使用以下代码绘制像素,而不是接收输入。
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy
fake_img = numpy.random.random((28,28))
plt.imshow(fake_img, cmap='gray')
ax = plt.gca()
fig = plt.gcf()
linepoints = numpy.array([])
def onclick(event):
print(event)
if event.button == 3:
global linepoints
x = event.xdata
y = event.ydata
linepoints = numpy.append(linepoints, x)
linepoints = numpy.append(linepoints, y)
if numpy.size(linepoints) == 4:
plt.plot((linepoints[0], linepoints[2]), (linepoints[1], linepoints[3]), '-')
linepoints = numpy.array([])
plt.show()
cid = fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()
如何获得画布可绘制并将图像接收到数组?
答案 0 :(得分:0)
自mac trackpad seems to have only 2 mousebuttons以来,默认情况下无法使用第三个进行鼠标互动。
因此,您需要使用第一个或第二个鼠标按钮进行交互。
if event.button == 1:
或
if event.button == 2: