2016-03-30 43 views
0

我嘗試了MPLD3中的工具提示示例。然而,在我的圖中,我有幾個連接x軸的子圖(數據長度相同,我繪製了不同的數據幀列)。使用下面的代碼,當我在最後一個子圖中移動鼠標時,我可以看到工具提示。但是,當我在任何子圖中移動鼠標時,我都會這樣做。我怎樣才能做到這一點?我想它應該有點像LinkedBrush例子。我只是不知道如何編寫我的插件來處理不同數量的子圖。我可以在MPLD3的鏈接子圖中使用工具提示嗎?

以下代碼將在底部子圖上創建一個圖形,其中包含工具提示。

import matplotlib.pyplot as plt 
import numpy as np 
import mpld3 
from mpld3 import plugins, utils 
N=30 
fig, axes = plt.subplots(3, 1, figsize=(6,10), sharex='col') 
for i in range(3): 
    points1=axes[i].scatter(range(N),np.random.random(size=N), color='b',marker='.') 
labels0 = [ 'point {0}'.format(i + 1) for i in range(N)] 
tooltip = plugins.PointLabelTooltip(points1, labels0) 
plugins.connect(fig, tooltip) 
mpld3.save_html(fig, 'test.html') 
+0

你可以添加一些模擬數據'sub'讓這個完整的例子嗎? http://stackoverflow.com/help/mcve –

+0

對不起。只是添加了一個簡單的例子來說明這個問題。 – user3569263

+1

我懷疑你想要的東西比通過簡單地將'labels0 = ...'插入循環中的'plugins.connect'行來實現更復雜(如下所示:http://nbviewer.jupyter.org/gist/aflaxman/453e557a69eb6b794290075065794630 ) –

回答

1

您通過將工具提示創建代碼到你的循環實現這一點:

import matplotlib.pyplot as plt 
import numpy as np 
import mpld3 
from mpld3 import plugins, utils 
N=30 
fig, axes = plt.subplots(3, 1, figsize=(6,10), sharex='col') 
for i in range(3): 
    points1=axes[i].scatter(range(N),np.random.random(size=N), color='b',marker='.') 
    labels0 = [ 'point {0}'.format(i + 1) for i in range(N)] 
    tooltip = plugins.PointLabelTooltip(points1, labels0) 
    plugins.connect(fig, tooltip) 
mpld3.save_html(fig, 'test.html') 
相關問題