VisibleDepricationWarning:使用ndim转换数组> 0到索引将导致将来出错

时间:2017-04-06 09:21:01

标签: python numpy matplotlib

test.py:93: VisibleDepricationWarning: converting an array with ndim > 0 to an index will result in an error in the future
    self.selected.set_data(refs_cov[dataind], refs_gc[dataind])

使用此代码的修改版本时,我收到以上错误消息:http://matplotlib.org/examples/event_handling/data_browser.html

我修改后的版本:

import numpy as np
import matplotlib.pyplot as plt

class _PointBrowser(object):

    """
    Click on a point to select and highlight it -- the data that
    generated the point will be shown in the lower axes.  Use the 'n'
    and 'p' keys to browse through the next and previous points
    """

    def __init__(self):
        self.lastind = 0

        self.selected, = ax.plot([x[0]], [y[0]], 'o', ms=6, alpha=0.8,
                                 color='red', visible=False)

    def onpick(self, event):

        if event.artist != line:
            return True

        N = len(event.ind)
        if not N:
            return True

        dataind = event.ind

        # Handle error message that exits the program when clicking on an area
        # with nested data points, as that will result in dataind == array of multiple values
        try:
            print 'Reference: %s\nCoverage: %.2f\nGC: %.2f%%\nLength: %d\n' % \
                    (np.take(refs, dataind)[0], np.take(x, dataind), np.take(y, dataind), np.take(refs_lengths, dataind))

        except TypeError:
            pass

        self.lastind = dataind
        self.update()

    def update(self):
        if self.lastind is None:
            return

        dataind = self.lastind

        ax2.cla()
        ax2.plot()

        # Handle error message that exits the program when clicking on an area
        # with nested data points, as that will result in dataind == array of multiple values
        try:
            ax2.text(0.05, 0.9, 'Reference: %s\nCoverage: %.2f\nGC: %.2f%%\nLength: %d\n' % \
                    (np.take(refs, dataind)[0], np.take(x, dataind), np.take(y, dataind), np.take(refs_lengths, dataind)), \
                    transform=ax2.transAxes, va='top')

            self.selected.set_visible(True)
            self.selected.set_data(x[dataind], y[dataind])

        except TypeError:
            ax2.text(0.05, 0.9, 'Error: Try pan/zoom!',
                    transform=ax2.transAxes, va='top')

        fig.canvas.draw()

我想要实现的目标: 一个绘图,您可以使用鼠标选择一个值,然后用斧头中的红色点亮该数据点,并在ax2和终端中打印出该点的特定信息。

这已经实现,一切都按预期完成。除了错误消息。它仅在我第一次使用鼠标选择值时显示。即便如此,它仍按预期打印出所有内容。

任何人都知道它出现的原因?

0 个答案:

没有答案