Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Draft PR: On adding data tooltip support (#23378)#30133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Dil003 wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromebubekir-pulat:data-tooltip-support
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletionslib/matplotlib/artist.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
from collections import namedtuple
import contextlib
from functools import cache, reduce, wraps
Expand DownExpand Up@@ -1393,6 +1393,28 @@
ax._mouseover_set.discard(self)

mouseover = property(get_mouseover, set_mouseover) # backcompat.

Check failure on line 1396 in lib/matplotlib/artist.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Blank line contains whitespaceRaw Output:message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/artist.py" range:{start:{line:1396 column:1} end:{line:1396 column:5}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:1396 column:1} end:{line:1396 column:5}}}
def set_tooltip(self, tooltip):
"""
Set tooltip for the artist.

Check failure on line 1400 in lib/matplotlib/artist.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Blank line contains whitespaceRaw Output:message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/artist.py" range:{start:{line:1400 column:1} end:{line:1400 column:9}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:1400 column:1} end:{line:1400 column:9}}}
Parameters
----------
tooltip : str, list, callable, or None
- If a string, the same tooltip is used for all data points.
- If a list, each element is used as tooltip for the corresponding data point.

Check failure on line 1405 in lib/matplotlib/artist.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Line too long (90 > 88)Raw Output:message:"Line too long (90 > 88)" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/artist.py" range:{start:{line:1405 column:89} end:{line:1405 column:91}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E501" url:"https://docs.astral.sh/ruff/rules/line-too-long"}
- If a callable, it is called with the data point coordinates as arguments,
and should return the tooltip string.
- If None, no tooltip is shown.
"""
self._tooltip = tooltip
self.stale = True

Check warning on line 1411 in lib/matplotlib/artist.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/artist.py#L1410-L1411

Added lines #L1410 - L1411 were not covered by tests

Check failure on line 1412 in lib/matplotlib/artist.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Blank line contains whitespaceRaw Output:message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/artist.py" range:{start:{line:1412 column:1} end:{line:1412 column:5}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:1412 column:1} end:{line:1412 column:5}}}
def get_tooltip(self):
"""
Return the tooltip for the artist.
"""
return getattr(self, '_tooltip', None)


def _get_tightbbox_for_layout_only(obj, *args, **kwargs):
Expand Down
8 changes: 8 additions & 0 deletionslib/matplotlib/axes/_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
import functools
import itertools
import logging
Expand DownExpand Up@@ -1769,9 +1769,17 @@
(``'green'``) or hex strings (``'#008000'``).
"""
kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)

Check failure on line 1772 in lib/matplotlib/axes/_axes.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Blank line contains whitespaceRaw Output:message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/axes/_axes.py" range:{start:{line:1772 column:1} end:{line:1772 column:9}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:1772 column:1} end:{line:1772 column:9}}}
# Extract tooltip parameter before creating lines
tooltip = kwargs.pop('tooltip', None)

Check failure on line 1775 in lib/matplotlib/axes/_axes.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Blank line contains whitespaceRaw Output:message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/axes/_axes.py" range:{start:{line:1775 column:1} end:{line:1775 column:9}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:1775 column:1} end:{line:1775 column:9}}}
lines = [*self._get_lines(self, *args, data=data, **kwargs)]
for line in lines:
self.add_line(line)
# Set tooltip if provided
if tooltip is not None:
line.set_tooltip(tooltip)

Check warning on line 1781 in lib/matplotlib/axes/_axes.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/axes/_axes.py#L1781

Added line #L1781 was not covered by tests

Check failure on line 1782 in lib/matplotlib/axes/_axes.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Blank line contains whitespaceRaw Output:message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/axes/_axes.py" range:{start:{line:1782 column:1} end:{line:1782 column:17}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:1782 column:1} end:{line:1782 column:17}}}
if scalex:
self._request_autoscale_view("x")
if scaley:
Expand Down
22 changes: 22 additions & 0 deletionslib/matplotlib/backend_bases.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1904,6 +1904,28 @@
with self._idle_draw_cntx():
self.draw(*args, **kwargs)

def show_tooltip(self, text, x, y, timeout=None):
"""
Display a tooltip with the given text at the position (x, y).

Check failure on line 1910 in lib/matplotlib/backend_bases.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Blank line contains whitespaceRaw Output:message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backend_bases.py" range:{start:{line:1910 column:1} end:{line:1910 column:9}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:1910 column:1} end:{line:1910 column:9}}}
Parameters
----------
text : str
The tooltip text containing arbitrary data.
x, y : float
The position of the tooltip in display coordinates.
timeout : float, optional
The timeout in seconds after which the tooltip should disappear.
If None, the tooltip will remain until explicitly hidden.
"""
pass

Check warning on line 1921 in lib/matplotlib/backend_bases.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backend_bases.py#L1921

Added line #L1921 was not covered by tests

Check failure on line 1922 in lib/matplotlib/backend_bases.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Blank line contains whitespaceRaw Output:message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backend_bases.py" range:{start:{line:1922 column:1} end:{line:1922 column:5}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:1922 column:1} end:{line:1922 column:5}}}
def hide_tooltip(self):
"""
Hide the currently displayed tooltip.
"""
pass

@property
def device_pixel_ratio(self):
"""
Expand Down
59 changes: 59 additions & 0 deletionslib/matplotlib/backends/backend_qt.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,7 @@
from . import qt_compat
from .qt_compat import (
QtCore, QtGui, QtWidgets, __version__, QT_API, _to_int, _isdeleted)
from matplotlib.backends.backend_qt import FigureCanvasQT


# SPECIAL_KEYS are Qt::Key that do *not* return their Unicode name
Expand DownExpand Up@@ -542,6 +543,64 @@
return
self._draw_rect_callback = _draw_rect_callback
self.update()

def __init__(self, figure):
super().__init__(figure)
self._tooltip_timer = None
self._tooltip_label = None

Check warning on line 550 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L547-L550

Added lines #L547 - L550 were not covered by tests

def show_tooltip(self, text, x, y, timeout=None):

Check warning on line 552 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L552

Added line #L552 was not covered by tests
"""
Show a tooltip on the canvas.
"""
from matplotlib.backends.qt_compat import QtWidgets, QtCore

Check warning on line 556 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L556

Added line #L556 was not covered by tests

if self._tooltip_label is None:
self._tooltip_label = QtWidgets.QLabel(self)
self._tooltip_label.setStyleSheet("""

Check warning on line 560 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L559-L560

Added lines #L559 - L560 were not covered by tests
background-color: rgba(255, 255, 245, 0.9);
border: 1px solid rgba(0, 0, 0, 0.5);
border-radius: 4px;
padding: 4px;
font-size: 9pt;
""")
self._tooltip_label.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
self._tooltip_label.hide()

Check warning on line 568 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L567-L568

Added lines #L567 - L568 were not covered by tests

# x, y are expected to be in display/pixel coordinates
# Set text and adjust size
self._tooltip_label.setText(text)
self._tooltip_label.adjustSize()

Check warning on line 573 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L572-L573

Added lines #L572 - L573 were not covered by tests

# Position tooltip slightly offset from cursor
offset_x, offset_y = 10, 10
self._tooltip_label.move(int(x + offset_x), int(y + offset_y))

Check warning on line 577 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L576-L577

Added lines #L576 - L577 were not covered by tests

# Show tooltip
self._tooltip_label.show()
self._tooltip_label.raise_()

Check warning on line 581 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L580-L581

Added lines #L580 - L581 were not covered by tests

# Handle timeout (optional - removes tooltip automatically)
if self._tooltip_timer is not None:
self._tooltip_timer.stop()
self._tooltip_timer = None

Check warning on line 586 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L585-L586

Added lines #L585 - L586 were not covered by tests

if timeout is not None:
self._tooltip_timer = QtCore.QTimer()
self._tooltip_timer.setSingleShot(True)
self._tooltip_timer.timeout.connect(self.hide_tooltip)
self._tooltip_timer.start(int(timeout * 1000))

Check warning on line 592 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L589-L592

Added lines #L589 - L592 were not covered by tests

def hide_tooltip(self):

Check warning on line 594 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L594

Added line #L594 was not covered by tests
"""
Hide the tooltip.
"""
if self._tooltip_label is not None:
self._tooltip_label.hide()

Check warning on line 599 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L599

Added line #L599 was not covered by tests

if self._tooltip_timer is not None:
self._tooltip_timer.stop()
self._tooltip_timer = None

Check warning on line 603 in lib/matplotlib/backends/backend_qt.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/backends/backend_qt.py#L602-L603

Added lines #L602 - L603 were not covered by tests


class MainWindow(QtWidgets.QMainWindow):
Expand Down
114 changes: 114 additions & 0 deletionslib/matplotlib/figure.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
"""
`matplotlib.figure` implements the following classes:

Expand DownExpand Up@@ -27,6 +27,7 @@
"""

from contextlib import ExitStack
from matplotlib import lines
import inspect
import itertools
import functools
Expand DownExpand Up@@ -2650,6 +2651,7 @@

self._axstack = _AxesStack() # track all figure Axes and current Axes
self.clear()
self._init_tooltip_handling()

def pick(self, mouseevent):
if not self.canvas.widgetlock.locked():
Expand DownExpand Up@@ -3581,6 +3583,118 @@
self.canvas.draw()

return clicks

def _init_tooltip_handling(self):
"""
Initialize tooltip event handling.
"""
self._tooltip_cid = self.canvas.mpl_connect(
'motion_notify_event', self._on_mouse_move_for_tooltip)

def _on_mouse_move_for_tooltip(self, event):
"""
Handle mouse movement for tooltip display.

This method is called when the mouse moves over the figure.
If the mouse is over an artist with tooltip data, the tooltip is shown.
Otherwise, the tooltip is hidden.
"""
if not event.inaxes:
self.canvas.hide_tooltip()
return

# Get all artists under the cursor, from top to bottom
artists = []
for ax in self.get_axes():
if ax == event.inaxes: # Only check the current axes
# Get all artists in this axes, reversed to check top-most first
for artist in reversed(ax.get_children()):
if hasattr(artist, 'get_tooltip') and artist.get_visible():
artists.append(artist)

# Check if the mouse is over any artist with tooltip data
found_tooltip = False
for artist in artists:
tooltip = artist.get_tooltip()
if tooltip is None:
continue

# Check if the mouse is over this artist
contains, info = artist.contains(event)
if not contains:

Check warning on line 3624 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3624

Added line #L3624 was not covered by tests
continue

Check warning on line 3626 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3626

Added line #L3626 was not covered by tests
# Get tooltip text based on the type of tooltip
# if isinstance(artist, matplotlib.lines.Line2D) and 'ind' in info:
if isinstance(artist, lines.Line2D) and 'ind' in info:
# For Line2D objects
indices = info['ind']
if not indices.size:

Check warning on line 3632 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3632

Added line #L3632 was not covered by tests
continue

Check warning on line 3634 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3634

Added line #L3634 was not covered by tests
idx = indices[0]
xdata, ydata = artist.get_data()

Check warning on line 3637 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3636-L3637

Added lines #L3636 - L3637 were not covered by tests
if callable(tooltip):
# Function tooltip
if idx < len(xdata) and idx < len(ydata):
text = tooltip(xdata[idx], ydata[idx])
else:

Check warning on line 3642 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3642

Added line #L3642 was not covered by tests
continue
elif isinstance(tooltip, list):

Check warning on line 3644 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3644

Added line #L3644 was not covered by tests
# List tooltip
if idx < len(tooltip):
text = tooltip[idx]
else:

Check warning on line 3648 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3648

Added line #L3648 was not covered by tests
continue
else:

Check warning on line 3650 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3650

Added line #L3650 was not covered by tests
# String tooltip
text = str(tooltip)

Check warning on line 3653 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3653

Added line #L3653 was not covered by tests
elif isinstance(artist, matplotlib.collections.PathCollection) and 'ind' in info:
# For scatter plots
indices = info['ind']
if not indices.size:

Check warning on line 3657 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3657

Added line #L3657 was not covered by tests
continue

Check warning on line 3659 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3659

Added line #L3659 was not covered by tests
idx = indices[0]
offsets = artist.get_offsets()

Check warning on line 3662 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3661-L3662

Added lines #L3661 - L3662 were not covered by tests
if callable(tooltip):
# Function tooltip
if idx < len(offsets):
x, y = offsets[idx]
text = tooltip(x, y)
else:

Check warning on line 3668 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3667-L3668

Added lines #L3667 - L3668 were not covered by tests
continue
elif isinstance(tooltip, list):

Check warning on line 3670 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3670

Added line #L3670 was not covered by tests
# List tooltip
if idx < len(tooltip):
text = tooltip[idx]
else:

Check warning on line 3674 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3674

Added line #L3674 was not covered by tests
continue
else:

Check warning on line 3676 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3676

Added line #L3676 was not covered by tests
# String tooltip
text = str(tooltip)

Check warning on line 3679 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3679

Added line #L3679 was not covered by tests
else:
# Generic artist
if callable(tooltip):
text = tooltip(event.xdata, event.ydata)
else:

Check warning on line 3684 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3684

Added line #L3684 was not covered by tests
text = str(tooltip)

Check warning on line 3686 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3686

Added line #L3686 was not covered by tests
# Show the tooltip
bbox = self.bbox
fig_x = event.x / bbox.width
fig_y = event.y / bbox.height
self.canvas.show_tooltip(text, fig_x, fig_y)
found_tooltip = True
break

Check warning on line 3694 in lib/matplotlib/figure.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/figure.py#L3689-L3694

Added lines #L3689 - L3694 were not covered by tests
# Hide tooltip if no artist with tooltip was found
if not found_tooltip:
self.canvas.hide_tooltip()

def waitforbuttonpress(self, timeout=-1):
"""
Expand Down
55 changes: 55 additions & 0 deletionstest_tooltip.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
# # ## Check if your tooltip data is being stored
# # import matplotlib.pyplot as plt
# # import numpy as np

# # # Test if tooltip is being stored
# # x = np.linspace(0, 10, 5)
# # y = np.sin(x)

# # line, = plt.plot(x, y, 'o-', tooltip=['Point A', 'Point B', 'Point C', 'Point D', 'Point E'])

# # # Check if tooltip was stored
# # print("Tooltip stored:", line.get_tooltip())
# # print("Line has tooltip method:", hasattr(line, 'get_tooltip'))

# # # Not showing the plot yet, just testing the storage




# ## Test the backend
# import matplotlib.pyplot as plt
# import matplotlib
# import numpy as np

# print("Backend:", matplotlib.get_backend())

# # Test with a simple plot and try hovering
# x = np.linspace(0, 10, 5)
# y = np.sin(x)

# fig, ax = plt.subplots()
# line, = ax.plot(x, y, 'o-', tooltip=['Point A', 'Point B', 'Point C', 'Point D', 'Point E'], picker=5)

# print("Tooltip stored:", line.get_tooltip())
# print("Figure has tooltip handling:", hasattr(fig, '_on_mouse_move_for_tooltip'))

# # Test if canvas has tooltip methods
# print("Canvas has show_tooltip:", hasattr(fig.canvas, 'show_tooltip'))
# print("Canvas has hide_tooltip:", hasattr(fig.canvas, 'hide_tooltip'))

# plt.title('Try hovering over the points')
# plt.show()


# import matplotlib.pyplot as plt
# import numpy as np

# # Test tooltips with console output
# x = np.linspace(0, 10, 5)
# y = np.sin(x)

# plt.figure()
# plt.plot(x, y, 'o-', tooltip=['Point A', 'Point B', 'Point C', 'Point D', 'Point E'])
# plt.title('Move mouse over points - check console for tooltip messages')
# plt.show()
Loading

[8]ページ先頭

©2009-2025 Movatter.jp