Plotly Python 3D: axes with ticktexts shows only limited numbers of ticks

Hello everyone,

I want to create 3D plots with individually chosen names for the axes ticks, depending on later given input data. But no matter what I do, the axes do not display more than 5 or 7 ticks. Anything else is not displayed in the figures, but if I save the figure to html, I find that the correct axis values are in the (raw) html file. Is it a problem with the viewpoint / zoom? With the manual zooming / rotation functions displayed in the shown figure, I can not find this data.

I use plotly version 6.2.0 and the following code can be used to reproduce this issue:

def make_axis(id, number):
  return [id+str(i) for i in range(number)]

def get_3d_axis_dict(values):
  return dict(
      ticktext= [val for val in values],
      nticks=len(values),
      tickmode='array',
      autorange=False,
      tickvals=[i for i in range(len(values))],
  )

dim_x, dim_y, dim_z = make_axis('x',9), make_axis('y',7), make_axis('z',9)
fig = make_subplots(rows=1, cols=1)
fig.update_layout(
        scene=dict(
            xaxis=get_3d_axis_dict(values=dim_x),
            yaxis=get_3d_axis_dict(values=dim_y),
            zaxis=get_3d_axis_dict(values=dim_z),
        ),
    )
fig.add_scatter3d(x=[1, 2], y=[1, 6], z=[1, 3], mode='markers', marker=dict(color='#000000', size=6))
fig.write_html('Test.html', include_mathjax='cdn')

This produces the following image:

The x and z axis show at max 7 ticks, the y axis only 5. Only one point added with add_scatter3d can be seen as the other one is in the part of the axes which is not displayed.

Do you have any idea what causes this problem or whether there is any kind of fix for this?

Welcome to the formus @bs0!

I think this is caused due to you setting

and not specifying any range. You have two options, either set autorange=True or specify a range.

Is there a reason you are using make_subplots to create the figure object?

import plotly.graph_objects as go

def make_axis(id, number):
  return [id+str(i) for i in range(number)]

def get_3d_axis_dict(values):
  return dict(
      ticktext= [val for val in values],
      nticks=len(values),
      tickmode='array',
      autorange=False,
      range=[0, len(values)],
      tickvals=[i for i in range(len(values))],
  )

dim_x, dim_y, dim_z = make_axis('x',20), make_axis('y',20), make_axis('z',20)
fig = go.Figure()
fig.update_layout(
        scene=dict(
            xaxis=get_3d_axis_dict(values=dim_x),
            yaxis=get_3d_axis_dict(values=dim_y),
            zaxis=get_3d_axis_dict(values=dim_z),
        ),
    )
fig.add_scatter3d(x=[1, 2, 20], y=[1, 6, 20], z=[1, 3, 20], mode='markers', marker=dict(color='#000000', size=6))
fig.show()

Hi,

yes, that indeed solves my problem.

Setting autorange to True did not display the axes as I wanted (shows only the ticks related to the data) so I set it to False to show all ticks. I just thought, plotly would automatically display all given tickvalues in this case.

Thank you very much for your help :slight_smile:

1 Like