1
我有以下代碼。如果沒有%matplotlib內聯,jupyter筆記本會彈出一個額外的窗口來顯示繪圖並且它是交互式的(右下角在您移動鼠標時更新x和y值)。用%matplotlib inline,該圖不是交互式的。Jupyter筆記本畫布使用%matplotlib內聯時不交互
我能做些什麼來使它在筆記本內互動?
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from numpy.random import randn
%matplotlib inline
origins = ['China','Brazil','India','USA','Canada','UK','Germany',
'Iraq','Chile','Mexico']
df = pd.DataFrame({'height':
np.random.rand(10),'weight':np.random.rand(10),
'origin':origins})
plt.figure()
plt.scatter(df['height'],df['weight'],picker=5)
plt.gca().set_ylabel('Weight')
plt.gca().set_xlabel('Height')
def onpick(event):
origin = df.iloc[event.ind[0]]['origin']
plt.gca().set_title('came from {}'.format(origin))
plt.gcf().canvas.mpl_connect('pick_event',onpick)
plt.show()