6

离开examples/basics/visuals/graphy.py,我试图显示一个直方图但失败了:

from vispy import app, visuals
import wx
import numpy as np

class snrHistogram(app.Canvas):
    def __init__(self, *args, **kwargs):
        app.Canvas.__init__(self, title='histogram fail',
                            keys="interactive", size=(600, 600))

        self.snr_hist = visuals.HistogramVisual(np.arange(256), bins=4, color='r', orientation='v')
        self.label = visuals.TextVisual("hi", color='blue', pos=[50, 50, 0])
        self.configure_transforms()
        self.show()

    def configure_transforms(self):
        vp = (0, 0, self.physical_size[0], self.physical_size[1])
        self.context.set_viewport(*vp)
        self.label.transforms.configure(canvas=self, viewport=vp)
        self.snr_hist.transforms.configure(canvas=self, viewport=vp)

    def on_resize(self, event):
        self.configure_transforms()

    def on_mouse_wheel(self, event):
        self.update()

    def on_draw(self, event):
        self.snr_hist.draw()
        self.label.draw()
        self.update()

    def on_close(self, event):
        self.close()

if __name__ == '__main__':
    s = snrHistogram()
    app.run()

然而文本视觉效果很好。我知道 histogramVisual 是网格的子类,但是我在 mesh.py 的源代码中没有看到任何有用的东西。我使用 wx 作为我的后端。

4

1 回答 1

4

直方图出现了,但非常小。以下输入数据将强制程序显示直方图:

self.snr_hist = visuals.HistogramVisual(
    np.repeat([0, 1, 1, 20, 20, 40, 40, 80, 80, 90, 81, 70, 65],
    100), bins=4, color='r', orientation='h')
于 2020-05-04T18:05:40.193 回答