离开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 作为我的后端。