mpldatacursor icon indicating copy to clipboard operation
mpldatacursor copied to clipboard

Crash after highlight x:[.. None ..], y:[.. float ..] data

Open GVA-error opened this issue 4 years ago • 0 comments

xData = [0, 1, None, 2, 3] yData = [0, 1, 1.5, 2, 3]

The left side of the graph can be highlighted, but the right one cannot.

image

Source cod:

import sys

from PyQt5.QtWidgets import QApplication, QMainWindow

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from mpldatacursor import HighlightingDataCursor


class MainWidget(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        figure = Figure(figsize=(10, 5), dpi=85, linewidth=0.1)
        canvas = FigureCanvas(figure=figure)
        somePlot = figure.add_subplot(111)

        xData = [0, 1, None, 2, 3]
        yData = [0, 1, 1.5, 2, 3]
        someLinePlot = somePlot.plot(xData, yData, 'r.-', label='Value')
        myCursor = HighlightingDataCursor(someLinePlot, highlight_color='red', highlight_width=1, hover=True, \
                                             display='single', xytext=(15, 15), formatter=self.myFormater)
                                             # "single"|"multiple"|"one-per-axes" - the result is the same
                                             
                                             
        canvas.draw()
        self.setCentralWidget(canvas)
        
    def myFormater(self, x=None, y=None, z=None, s=None, label=None, **kwargs):
        output = []
        if x == None or y == None:
            return u"\n"
        output.append(u'{key}: {val:0.3g}'.format(key=label, val=x))
        output.append(u'{key}: {val:0.3g}'.format(key=self.tr('Depth'), val=y))
        #output.append(u'(' + label + ')')
        return u"\n".join(output)


if __name__ == "__main__":
    app = QApplication(sys.argv)

    mainWidget = MainWidget()
    mainWidget.show()

    sys.exit(app.exec_())


Traceback:

Traceback (most recent call last):
  File "C:\permafrost3d\venv\lib\site-packages\matplotlib\cbook\__init__.py", line 224, in process
    func(*args, **kwargs)
  File "C:\permafrost3d\venv\lib\site-packages\mpldatacursor\datacursor.py", line 705, in _select
    if contains(anno, fixed_event)[0]:
  File "C:\permafrost3d\venv\lib\site-packages\mpldatacursor\datacursor.py", line 697, in contains
    return artist.contains(event)
  File "C:\permafrost3d\venv\lib\site-packages\matplotlib\text.py", line 1754, in contains
    in_patch, _ = self.arrow_patch.contains(event)
  File "C:\permafrost3d\venv\lib\site-packages\matplotlib\patches.py", line 135, in contains
    codes = self.get_path().codes
  File "C:\permafrost3d\venv\lib\site-packages\matplotlib\patches.py", line 4128, in get_path
    _path, fillable = self.get_path_in_displaycoord()
  File "C:\permafrost3d\venv\lib\site-packages\matplotlib\patches.py", line 4145, in get_path_in_displaycoord
    shrinkB=self.shrinkB * dpi_cor
  File "C:\permafrost3d\venv\lib\site-packages\matplotlib\patches.py", line 2492, in __call__
    clipped_path = self._clip(path, patchA, patchB)
  File "C:\permafrost3d\venv\lib\site-packages\matplotlib\patches.py", line 2447, in _clip
    left, right = split_path_inout(path, insideA)
  File "C:\permafrost3d\venv\lib\site-packages\matplotlib\bezier.py", line 350, in split_path_inout
    ctl_points, command = next(path_iter)
StopIteration

Environment: Python 3.7.1

depends from pip: pyqt5, matplotlib, mpldatacursor

platform: Windows 10

GVA-error avatar Nov 25 '20 13:11 GVA-error