Plot two chart types in the same xyz axis


#1

Hello again,

I am sorry if this question is basic, but I have tried to find this info for the past few hours without success.

I have a pandas dataframe that represents the segmentation of structures in a tiff image stack.
I have been looking into ways of plotting these together (image as heatmap, segmentation as mesh3d and scatter3d) as the coordinates should match in xyz.
I have tried looking into the reference and examples but only found subplotting examples, where the charts are displayed side by side or share only 1 or 2 axis.

Is there any way to plot them in the same ‘grid’ where xyz positions match (same range, same origin)?

Thank you!


#2

Hi @predo,

Are you looking for something like https://plot.ly/python/2d-projection-of-3d-surface/?

Here 3 flat surfaces are constructed to represent the heatmaps for each projection. Sounds like you would only want one flat surface as a heatmap and then a mesh3d trace instead of the central surface here, but hopefully this will get you started!

-Jon


#3

Dear @jmmease my two neurons just fired and I see how you pointed me in the right direction. I will update again when I try in a couple of hours.

Thanks again!


#4

hello again @jmmease!

I followed the example and go as far as projecting my z axis.
It works but I seem to have found a bug related to the scene yaxis range.
Please check these snapshots of expected vs bugged projection aspect ratio.

Thank you!


#5

Hi @predo, glad you got something working! I looked at the snapshots and it’s not immediately apparent to be what’s wrong.

Keep in mind that scene.xaxis.range controls the range in data coordinates, not in screen coordinates. You might need to play
with the scene aspect ratio parameters as well. e.g.

fig.layout.scene.aspectratio.x = 1
fig.layout.scene.aspectratio.y = 1.5
fig.layout.scene.aspectratio.z = 2

-Jon


#6

Hi @jmmease, I have indeed tried to force the ratio to be the same on all axis as the data is isotropic and it didnt solve it.

If you wouldnt mind checking the images again, you can see the second image has the yaxis stretched.
The only parameters that are changed are in the legend of the images. I try to keep the axis sizes to match the input data size but for y if I dont go over the data size but a certain amount it will.

I tried to change the aspectratio like you suggested, and something funny happens.
If my yaxis range is the size of the y data it doesnt do anything for y. If I make the axis range big so that it fixes the display, the ratio that I input is now working.


#7

Hi @predo,

Can you make up a reproducible example? That will make it a lot easier to work through what’s going on.

-Jon


#8

Hello again @jmmease,

I am coming with a few questions. I am trying to follow the heatmap projection example you linked using my own dataset.

For trace1, i would expect to have a cube but it does not plot anything and the axis scale is wrong (array shape = 50,50,50).

For tracex and tracey I get the same problems as with trace1.

Now tracez on the other hand, works only if I comment out go.Surface.x and . y.
Interestingly if i give x or y data as go.Surfarce.z it plots but on the wrong axis of course.

I linked the image data and also the code here.

I am wondering if I am doing something really wrong here. I would add that if I try to do a surface plot without the projections, I only get a plot if I pass the array to go.Surfarce.z

Thanks for the help!