Axes ratio in 3D plot

Dear community

This question is a new one, but related to my previous post
A 3D sketch in DASH - Dash Python - Plotly Community Forum

The new problem is, everything works fine if the user doesn’t specify an extreme ratio between box dimensions. Let me show you. The software initializes x,y,z in the ratio 1:1:1 and it looks like this:

Specifying a width to height ratio of 0.5 and 2 (i.e. maintaining the volume, but the height is now 4 x the width), this still works and it looks like this:

It can be seen in the view that part of the axes is outside the view. Is there a way I could change the viewing window so all of it becomes visible inside the view? Maybe place the ‘camera’ further away or change the scene settings?

If the user specifies width 0.4 and height 2.5 (height is 6.25 x width) the axes ‘collapses’ and the circular (blue) elements becomes elliptical:

In above picture it can be seen the box looks cubic, except the axes proportions gives this away.

The code which controls the x-and-y axes proportionality looks like this:

fig.update_layout(yaxis = dict(scaleanchor = 'x'))

Is there anything I can do to avoid the situation where this command fails? I would be OK to allow some super-long skinny box and the view window be whatever the user was expecting.

Alternatively, is there a way in which I can be informed that keeping axes proportions has failed? .. Then, at least, I can show a warning message to the user. This is not really a solution to the ‘bug’ but at least raising a flag which says we are well aware that the behavior is acting in an unexpected way.

With kind regards,
Claus

Hi community

I have tried to do some debugging. I print ‘fig’ to the console and I can see that scaleanchor is set correctly, it just isn’t respected by DASH:

Figure({
    'data': [{'color': '#CCCCCC',
    ...
    'layout': {'template': '...', 'yaxis': {'scaleanchor': 'x'}}
})

I tried exception handling:

try:
    fig.update_layout(yaxis = dict(scaleanchor = 'x'))
except:
    print('exception, compressed domain view')  # no exceptions registered

Since setting this parameter is ‘working’ I obviously don’t have any exceptions.

I can see in the documentation that this phenomenon might be what is called compressing an axis. Please see link below for details (it takes 30 seconds to load, please be patient):

https://plotly.com/python/axes/#fixed-ratio-axes-with-compressed-domain

None of the data objects in the figure contain any information to identify if an axis has been set in compressed view.

Does someone know how to detect when compressed domain is activated? Is there a way to deactivate it?

With kind regards,
Claus

You could try setting the scene to this, assuming your figure is a mesh3D trace:

fig.update_layout(dict(scene=dict(aspectmode='data')))

This basically tells the graph to not scale any axes but draw the 3D shape based on the data, aka coordinates. I would guess you don’t even need the scaleratio anymore.

2 Likes

Hi AIMPED

Thank you very much, this indeed works:

fig.update_layout(scene=dict(aspectmode='data'))

BIG SMILE

Now I will go study and find out what it means…

With kind regards,
Claus

Hey @cfuttrup, happy to be of help.

I created an app some time ago to experiment with scene and eye parameters, maybe useful in this context.

1 Like