1
我試圖在jupyter notebook
中創建一個交互式圖,但我不知道如何實現它。有一個數據框我運行一個簡單的迴歸,然後繪製看到分佈。我希望能夠懸停其中的一點並獲得與這一點相關的數據。我怎樣才能做到這一點?現在我只能產生靜態情節 如何在matplot圖中顯示數據
import pandas as pd
from sklearn import linear_model
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
net = pd.read_csv("network_ver_64.csv")
net = net[net.AWDT12 > 0]
x = net.LOAD_DAILY.values
y = net.AWDT12.values
x_lenght = int(x.shape[0])
y_lenght = int(y.shape[0])
x = x.reshape(x_lenght, 1)
y = y.reshape(y_lenght,1)
regr = linear_model.LinearRegression()
regr.fit(x, y)
plt.scatter(x, y, color='black')
plt.plot(x, regr.predict(x), color='blue', linewidth=1)
plt.xticks(())
plt.yticks(())
plt.show()
據我所知,你不能用matplotlib獲得懸停功能。你必須嘗試[d3.js](https://d3js.org/)或[bokeh](http://bokeh.pydata.org/en/latest/) –
@MainulIslam很好。是的,我不知道這些模塊,虐待他們瞭解他們 –
[Plot.ly](https://plot.ly/python/)也值得檢查你想做什麼。 – gcalmettes