# Buggy code
def roiChanged(self):
    if self.image is None:
        return

    image = self.getProcessedImage()

    # Extract image data from ROI
    axes = (self.axes["x"], self.axes["y"])

    data, coords = self.roi.getArrayRegion(
        image.view(np.ndarray), self.imageItem, returnMappedCoords=True
    )
    if data is None:
        return

    # Convert extracted data into 1D plot data
    if self.axes["t"] is None:
        # Average across y-axis of ROI
        data = data.mean(axis=axes[1])
        if (
            axes == (1, 0)
        ):  ## we're in row-major order mode -- there's probably a better way to do this slicing dynamically, but I've not figured it out yet.
            coords = coords[:, 0, :] - coords[:, 0, 0:1]
        else:  # default to old way
            coords = coords[:, :, 0] - coords[:, 0:1, 0]
        xvals = (coords**2).sum(axis=0) ** 0.5
    else:
        # Average data within entire ROI for each frame
        data = data.mean(axis=max(axes)).mean(axis=min(axes))
        xvals = self.tVals

    # Handle multi-channel data
    if data.ndim == 1:
        plots = [(xvals, data, "w")]
    if data.ndim == 2:
        if data.shape[1] == 1:
            colors = "w"
        else:
            colors = "rgbw"
        plots = []
        for i in range(data.shape[1]):
            d = data[:, i]
            plots.append((xvals, d, colors[i]))

    # Update plot line(s)
    while len(plots) < len(self.roiCurves):
        c = self.roiCurves.pop()
        c.scene().removeItem(c)
    while len(plots) > len(self.roiCurves):
        self.roiCurves.append(self.ui.roiPlot.plot())
    for i in range(len(plots)):
        x, y, p = plots[i]
        self.roiCurves[i].setData(x, y, pen=p)


# Traceback (Exception)
Traceback (most recent call last):
File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/imageview/ImageView.py", line 566, in roiClicked
self.roiChanged()
File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/imageview/ImageView.py", line 640, in roiChanged
self.roiCurves[i].setData(x, y, pen=p)
File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotDataItem.py", line 471, in setData
self.updateItems()
File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotDataItem.py", line 497, in updateItems
self.curve.setData(x=x, y=y, **curveArgs)
File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 335, in setData
self.updateData(*args, **kargs)
File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 385, in updateData
raise Exception("X and Y arrays must be the same shape--got %s and %s." % (self.xData.shape, self.yData.shape))
Exception: X and Y arrays must be the same shape--got (100,) and (10,).
[22:13:37]  Ignored exception:

|==============================>>
|  Traceback (most recent call last):
|    File "/Users/ogi/Developer/pyqtgraph/examples/ImageView.py", line 70, in <module>
|      QtGui.QApplication.instance().exec_()
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/widgets/GraphicsView.py", line 155, in paintEvent
|      return QtGui.QGraphicsView.paintEvent(self, ev)
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/debug.py", line 93, in w
|      printExc('Ignored exception:')
|    --- exception caught here ---
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/debug.py", line 91, in w
|      func(*args, **kwds)
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 464, in paint
|      path = self.getPath()
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 446, in getPath
|      self.path = self.generatePath(*self.getData())
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 435, in generatePath
|      path = fn.arrayToQPath(x, y, connect=self.opts['connect'])
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/functions.py", line 1496, in arrayToQPath
|      arr[1:-1]['y'] = y
|  ValueError: could not broadcast input array from shape (10) into shape (100)
|==============================<<
[22:13:37]  Ignored exception:

|==============================>>
|  Traceback (most recent call last):
|    File "/Users/ogi/Developer/pyqtgraph/examples/ImageView.py", line 70, in <module>
|      QtGui.QApplication.instance().exec_()
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/widgets/GraphicsView.py", line 155, in paintEvent
|      return QtGui.QGraphicsView.paintEvent(self, ev)
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/debug.py", line 93, in w
|      printExc('Ignored exception:')
|    --- exception caught here ---
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/debug.py", line 91, in w
|      func(*args, **kwds)
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 464, in paint
|      path = self.getPath()
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 446, in getPath
|      self.path = self.generatePath(*self.getData())
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 435, in generatePath
|      path = fn.arrayToQPath(x, y, connect=self.opts['connect'])
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/functions.py", line 1496, in arrayToQPath
|      arr[1:-1]['y'] = y
|  ValueError: could not broadcast input array from shape (10) into shape (100)
|==============================<<
[22:13:38]  Ignored exception:

|==============================>>
|  Traceback (most recent call last):
|    File "/Users/ogi/Developer/pyqtgraph/examples/ImageView.py", line 70, in <module>
|      QtGui.QApplication.instance().exec_()
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/widgets/GraphicsView.py", line 155, in paintEvent
|      return QtGui.QGraphicsView.paintEvent(self, ev)
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/debug.py", line 93, in w
|      printExc('Ignored exception:')
|    --- exception caught here ---
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/debug.py", line 91, in w
|      func(*args, **kwds)
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 464, in paint
|      path = self.getPath()
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 446, in getPath
|      self.path = self.generatePath(*self.getData())
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 435, in generatePath
|      path = fn.arrayToQPath(x, y, connect=self.opts['connect'])
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/functions.py", line 1496, in arrayToQPath
|      arr[1:-1]['y'] = y
|  ValueError: could not broadcast input array from shape (10) into shape (100)
|==============================<<
[22:13:38]  Ignored exception:

|==============================>>
|  Traceback (most recent call last):
|    File "/Users/ogi/Developer/pyqtgraph/examples/ImageView.py", line 70, in <module>
|      QtGui.QApplication.instance().exec_()
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/widgets/GraphicsView.py", line 155, in paintEvent
|      return QtGui.QGraphicsView.paintEvent(self, ev)
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/debug.py", line 93, in w
|      printExc('Ignored exception:')
|    --- exception caught here ---
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/debug.py", line 91, in w
|      func(*args, **kwds)
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 464, in paint
|      path = self.getPath()
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 446, in getPath
|      self.path = self.generatePath(*self.getData())
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/graphicsItems/PlotCurveItem.py", line 435, in generatePath
|      path = fn.arrayToQPath(x, y, connect=self.opts['connect'])
|    File "/Users/ogi/Developer/pyqtgraph/pyqtgraph/functions.py", line 1496, in arrayToQPath
|      arr[1:-1]['y'] = y
|  ValueError: could not broadcast input array from shape (10) into shape (100)
|==============================<<

# Fixed code
def roiChanged(self):
    # Extract image data from ROI
    if self.image is None:
        return

    image = self.getProcessedImage()

    # getArrayRegion axes should be (x, y) of data array for col-major,
    # (y, x) for row-major
    # can't just transpose input because ROI is axisOrder aware
    colmaj = self.imageItem.axisOrder == "col-major"
    if colmaj:
        axes = (self.axes["x"], self.axes["y"])
    else:
        axes = (self.axes["y"], self.axes["x"])

    data, coords = self.roi.getArrayRegion(
        image.view(np.ndarray), img=self.imageItem, axes=axes, returnMappedCoords=True
    )

    if data is None:
        return

    # Convert extracted data into 1D plot data
    if self.axes["t"] is None:
        # Average across y-axis of ROI
        data = data.mean(axis=self.axes["y"])

        # get coordinates along x axis of ROI mapped to range (0, roiwidth)
        if colmaj:
            coords = coords[:, :, 0] - coords[:, 0:1, 0]
        else:
            coords = coords[:, 0, :] - coords[:, 0, 0:1]
        xvals = (coords**2).sum(axis=0) ** 0.5
    else:
        # Average data within entire ROI for each frame
        data = data.mean(axis=axes)
        xvals = self.tVals

    # Handle multi-channel data
    if data.ndim == 1:
        plots = [(xvals, data, "w")]
    if data.ndim == 2:
        if data.shape[1] == 1:
            colors = "w"
        else:
            colors = "rgbw"
        plots = []
        for i in range(data.shape[1]):
            d = data[:, i]
            plots.append((xvals, d, colors[i]))

    # Update plot line(s)
    while len(plots) < len(self.roiCurves):
        c = self.roiCurves.pop()
        c.scene().removeItem(c)
    while len(plots) > len(self.roiCurves):
        self.roiCurves.append(self.ui.roiPlot.plot())
    for i in range(len(plots)):
        x, y, p = plots[i]
        self.roiCurves[i].setData(x, y, pen=p)