3

I am trying to overlay a quiver3d plot over an imshow plot in mayavi. The code I am using looks something like this:

from mayavi import mlab
import numpy as np
    
img = np.random.uniform(0, 255, size=(512, 512)).astype(np.int)

N = 10000
event_size = 2
xs = np.random.uniform(img.shape[1], size=N)
ys = np.random.uniform(img.shape[0], size=N)
ts = np.sort(np.random.uniform(1000, size=N))
ps = np.random.randint(0,2,size=N)

mlab.imshow(img, colormap='gray', extent=[0, img.shape[0], 0, img.shape[1], ts[0], ts[1]])
colors = [0 if p>0 else 240 for p in ps]
ones = np.ones(len(xs))
p3d = mlab.quiver3d(ys, xs, ts, ones, ones,
            ones, scalars=colors, mode='sphere', scale_factor=event_size)
p3d.glyph.color_mode = 'color_by_scalar'

p3d.module_manager.scalar_lut_manager.lut.table = colors
mlab.draw()
mlab.show()

The issue I have with it, is that the imshow image seems to completely obscure the quiver plot, even when the 'quivers' are on top of the image. To illustrate, a GIF:

enter image description here

What am I doing wrong? Many thanks in advance!

==== EDIT ==== Here is also a GIF from my actual use case, I think it illustrates the problem better than the minimal example above:

enter image description here

Mr Squid
  • 1,196
  • 16
  • 34
  • 1
    `mlab.draw()` did not work for me. I used `mlab.figure()` in the beginning and `mlab.show()` instead of `.draw()` and the results look good to me. – scleronomic Jul 15 '20 at 12:23
  • Whoops, I forgot to put `mlab.show` in my working example, I am actually using it in my code. I tried to place `mlab.figure` at the beginning, but I am getting the same problem. You say it worked fine for you? Maybe it is an issue with the rendering engine? – Mr Squid Jul 15 '20 at 23:23
  • 1
    Yes for me the results look as expected. I tried it on Mac and Linux. See [here](https://imgur.com/a/UCY9ndO). Note also that there is a button in the toolbar for `parallel projection`. – scleronomic Jul 17 '20 at 09:12
  • Thank you, that will be very helpful in fixing the bug, which I'm guessing will lie in the rendering backend that my mayavi is using. – Mr Squid Jul 17 '20 at 09:15
  • @scleronomic Which Python/mayavi version are you using? – Mr Squid Jul 18 '20 at 01:51
  • 1
    python: 3.7.7, mayavi: 4.7.1 – scleronomic Jul 18 '20 at 16:39

1 Answers1

2

OK, so the solution wound up being switching to nvidia graphics. I was running the code on a laptop with a GeForce GTX 1050 maxQ GPU and Intel on-board graphics. With on-board graphics (sudo prime-select intel), I get the bug, when I switch to dedicated graphics (sudo prime-select nvidia) I get the desired output.

Mr Squid
  • 1,196
  • 16
  • 34