Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vispy visual.HistogramVisual

Going off of the examples/basics/visuals/graphy.py, I tried to display a histogram but failed:

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()

and yet the text visual works just fine. I understand histogramVisual is a subclass of mesh, but I didn't see anything useful in the source code of mesh.py. I am using wx as my backend.

like image 960
Ralph Avatar asked May 01 '20 23:05

Ralph


1 Answers

The histogram was appearing, but very small. The following input data will coerce the program to display a histogram:

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')
like image 54
Ralph Avatar answered Sep 29 '22 21:09

Ralph