키 누르기 이벤트 #

키 누르기 이벤트에 연결하는 방법을 보여줍니다.

메모

이 예제는 Matplotlib의 대화형 기능을 실행하며 정적 문서에는 나타나지 않습니다. 상호 작용을 보려면 컴퓨터에서 이 코드를 실행하십시오.

개별 부분을 복사하여 붙여넣거나 페이지 하단의 링크를 사용하여 전체 예제를 다운로드할 수 있습니다.

키를 누르십시오
import sys
import numpy as np
import matplotlib.pyplot as plt


def on_press(event):
    print('press', event.key)
    sys.stdout.flush()
    if event.key == 'x':
        visible = xl.get_visible()
        xl.set_visible(not visible)
        fig.canvas.draw()


# Fixing random state for reproducibility
np.random.seed(19680801)

fig, ax = plt.subplots()

fig.canvas.mpl_connect('key_press_event', on_press)

ax.plot(np.random.rand(12), np.random.rand(12), 'go')
xl = ax.set_xlabel('easy come, easy go')
ax.set_title('Press a key')
plt.show()

Sphinx-Gallery에서 생성한 갤러리