Tengo un gráfico con algunos segmentos de línea (LineCollection) y algunos puntos. Estas líneas y puntos tienen algunos valores asociados que no están graficados. Me gustaría poder agregar una sugerencia de mouse sobre el mouse u otro método para encontrar fácilmente el valor asociado para los puntos y la línea. ¿Es esto posible para segmentos de puntos o líneas?Información sobre herramientas de punto y línea en matplotlib?
10
A
Respuesta
6
Para los puntos, que han encontrado una manera, pero usted tiene que utilizar el backend 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
Sería extremadamente agradable si se hubiera pensado en una característica como esta para los componentes en general ... – aestrivex
1
Tal vez una variación de this recipe haría lo que quiere para puntos? Al menos no está restringido a wx back-end.
2
Es un viejo hilo, pero en caso de que alguien está buscando cómo agregar información sobre herramientas en línea, esto funciona:
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()
Cuestiones relacionadas
- 1. Información sobre herramientas en paneles
- 2. Información sobre herramientas para QPushButton
- 3. información sobre herramientas para Button
- 4. información sobre herramientas vacía tema
- 5. fuente de información sobre herramientas en wpf
- 6. muestra información sobre herramientas personalizada al pasar el cursor sobre un punto en flot
- 7. jQuery + información sobre herramientas de contenido ajax
- 8. Información sobre herramientas en una imagen
- 9. Anotaciones Java en eclipse Información sobre herramientas?
- 10. información sobre herramientas celular en SlickGrid
- 11. Información sobre herramientas para elementos CheckedListBox?
- 12. Apagar información sobre herramientas en Eclipse/Aptana
- 13. Definir nueva información sobre herramientas en Emacs
- 14. Mostrar información sobre herramientas en el mouse sobre un texto
- 15. QTip2 Elementos múltiples, misma información sobre herramientas
- 16. jqplot formato de información sobre herramientas valores
- 17. Información sobre herramientas sobre un polígono en Google Maps
- 18. información sobre herramientas para navegadores móviles
- 19. Crear información sobre herramientas para UserControl personalizado
- 20. Primefaces información sobre herramientas para p: selectManyCheckbox
- 21. WPF Enlace a la información sobre herramientas
- 22. Preservar información sobre herramientas al exportar GraphPlot
- 23. jqplot información sobre herramientas en el gráfico de barras
- 24. Ocultar información sobre herramientas nativa usando jQuery
- 25. Cómo agregar información sobre herramientas a jqgrid
- 26. JQuery JSTree: agregue una información sobre herramientas
- 27. WPF validador personalizado con información sobre herramientas
- 28. Agregar información sobre herramientas a JTextPane
- 29. Google Charts - html completo en información sobre herramientas
- 30. Mostrar información sobre herramientas sobre un control deshabilitado
[He aquí un ejemplo de matplotlib] (http://matplotlib.sourceforge.net/ examples/pylab_examples/cursor_demo.html), que encontré en Google. [Entonces esta es otra respuesta SO popular.] (Http://stackoverflow.com/a/4674445/1020470) [Bueno, y este también, que también apunta al ejemplo matplotlib.] (Http://stackoverflow.com/ a/7909589/1020470) –