我有一些線段(LineCollection)和一些點的圖形。這些線條和點有一些與它們不相關的值。我希望能夠添加鼠標懸停的工具提示或其他輕鬆找到點和線的關聯值的方法。這是可能的點或線段嗎?matplotlib中的點和線工具提示?
10
A
回答
6
對於分,我已經找到一種方法,但你必須使用WX後端
"""Example of how to use wx tooltips on a matplotlib figure window.
Adapted from http://osdir.com/ml/python.matplotlib.devel/2006-09/msg00048.html"""
import matplotlib as mpl
mpl.use('WXAgg')
mpl.interactive(False)
import pylab as pl
from pylab import get_current_fig_manager as gcfm
import wx
import numpy as np
import random
class wxToolTipExample(object):
def __init__(self):
self.figure = pl.figure()
self.axis = self.figure.add_subplot(111)
# create a long tooltip with newline to get around wx bug (in v2.6.3.3)
# where newlines aren't recognized on subsequent self.tooltip.SetTip() calls
self.tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n' % (' '*100))
gcfm().canvas.SetToolTip(self.tooltip)
self.tooltip.Enable(False)
self.tooltip.SetDelay(0)
self.figure.canvas.mpl_connect('motion_notify_event', self._onMotion)
self.dataX = np.arange(0, 100)
self.dataY = [random.random()*100.0 for x in xrange(len(self.dataX))]
self.axis.plot(self.dataX, self.dataY, linestyle='-', marker='o', markersize=10, label='myplot')
def _onMotion(self, event):
collisionFound = False
if event.xdata != None and event.ydata != None: # mouse is inside the axes
for i in xrange(len(self.dataX)):
radius = 1
if abs(event.xdata - self.dataX[i]) < radius and abs(event.ydata - self.dataY[i]) < radius:
top = tip='x=%f\ny=%f' % (event.xdata, event.ydata)
self.tooltip.SetTip(tip)
self.tooltip.Enable(True)
collisionFound = True
break
if not collisionFound:
self.tooltip.Enable(False)
example = wxToolTipExample()
pl.show()
+1
如果enthought更普遍地支持這樣的功能,這將是非常好的... – aestrivex 2013-05-08 20:28:21
1
也許在this recipe的變化會做你想要什麼點?至少它不限於wx後端。
2
這是一個古老的線程,但萬一有人正在尋找如何將工具提示添加到線,這工作:
import matplotlib.pyplot as plt
import numpy as np
import mpld3
f, ax = plt.subplots()
x1 = np.array([0,100], int)
x2 = np.array([10,110], int)
y = np.array([0,100], int)
line = ax.plot(x1, y)
mpld3.plugins.connect(f, mpld3.plugins.LineLabelTooltip(line[0], label='label 1'))
line = ax.plot(x2, y)
mpld3.plugins.connect(f, mpld3.plugins.LineLabelTooltip(line[0], label='label 2'))
mpld3.show()
相關問題
- 1. Microsoft工具提示中的點工具提示問題
- 2. 工具提示中的線程
- 3. D3中多線圖的工具提示
- 4. Google線圖:如何更改工具提示中的小數點?
- 5. 可點擊的點和可點擊的工具提示
- 6. 的ScrollViewer和工具提示
- 7. c3.js - xgrid線上的工具提示
- 8. jQuery的工具提示插件沒有提示工具提示
- 9. Combine NotifyIcon和工具提示
- 10. 工具提示和RaphaelJS
- 11. D3.js:折線圖 - 工具提示和垂直線懸停
- 12. joomla站點的jquery工具提示
- 13. Extjs可點擊的工具提示
- 14. jQuery的工具提示可點擊嗎?
- 15. Highcharts - 如何刪除固定的工具提示和點之間的連接線
- 16. Datagrid中的工具提示
- 17. Paper.js中的工具提示
- 18. .net中的工具提示
- 19. 工具提示中的Gridview
- 20. Chart.js - 折線圖工具提示標籤
- 21. 工具提示中的多線圖JS不工作
- 22. 當工具提示顯示時,「實時」更新小工具的工具提示
- 23. 工具提示與點擊信息
- 24. 點擊進入工具提示
- 25. 工具提示圖片點擊
- 26. 工具提示搶斷鼠標點擊
- 27. 顯示ZedGraph中曲線的標籤和長度(不僅僅是工具提示)
- 28. 顯示和處理工具提示.NET
- 29. 使StockCharts中的工具提示與HighCharts中的工具提示行爲相同
- 30. 在工具提示中Highcharts
[下面是matplotlib一個例子(http://matplotlib.sourceforge.net/ examples/pylab_examples/cursor_demo.html),我在Google上找到它。 [那麼這裏是另一個流行的SO回答。](http://stackoverflow.com/a/4674445/1020470)[嗯,這也是,也指向matplotlib示例。](http://stackoverflow.com/ a/7909589/1020470) – 2012-08-11 03:10:46