Here is my code:
import imgui
foo = [0.9, 1.1, 1.3, 2.5]
imgui.begin()
imgui.plot_lines("Plot", foo)
imgui.end()
And it gives me this error:
File "imgui\core.pyx", line 6042, in imgui.core.plot_lines
File "stringsource", line 660, in View.MemoryView.memoryview_cwrapper
File "stringsource", line 350, in View.MemoryView.memoryview.__cinit__
TypeError: a bytes-like object is required, not 'list'
I tried converting foo
to a np.array
or to a array.array
by doing imgui.plot_lines("Plot", np.array(foo) or array.array(foo)
but it didn't work, I was expecting a plot to appear in my window.
The signature of
plot_lines
is:values
is a 1D Cython memoryview of typefloat
meaning that what you pass to it must be an object that supports the buffer protocol with a 32 bit floating point number. Both Numpy arrays andarray.array
can meet that criteria if the underlying type is set correctly, howevernp.array(foo)
creates an array of 64-bit floating point numbers by default.list
fails because it doesn't support the buffer-protocol.There look to be examples of calling
plot_lines
in the package: https://github.com/pyimgui/pyimgui/blob/480b4de8ab82adaa2cd310100330b41f40274bcc/doc/examples/plots.py#L21-L40.They pass an
array.array
but specify the type as a 32-bit float. In your example this would be:Alternatively you could specify the type of a Numpy array with
The other thing you'll probably need to do (I haven't tested it myself!) is to actually create a window to draw in. The documentation says
The code example for
plot_lines
that I linked to above looks to useGLFW
as the backend.