I have a 10x12 array that I would like to plot using plotly. The length of x-axis is 10 and y-axis is 12. I expect the plot to have a range of 10 in the x-axis and 12 in the y-axis. But that is not the case. I get 10 on both axes. I have included a MWE to reproduce the issue.
import numpy as np
import plotly.graph_objects as go
data_array = np.empty((10, 12))
for i in range(10):
for j in range(12):
data_array[i, j] = i+j
x = np.linspace(1, 10, 10)
y = np.linspace(1, 12, 12)
fig = go.Figure(data=[go.Surface(z=data_array, x=x, y=y)])
fig.show()
I have tried setting the range via update_layout which doesn't solve the problem.
import numpy as np
import plotly.graph_objects as go
data_array = np.empty((10, 12))
for i in range(10):
for j in range(12):
data_array[i, j] = i+j
x = np.linspace(1, 10, 10)
y = np.linspace(1, 12, 12)
fig = go.Figure(data=[go.Surface(z=data_array, x=x, y=y)])
fig.update_layout(scene=dict(xaxis=dict(range=[0, 10]),
yaxis=dict(range=[0, 12])))
fig.show()
Although the range of y-axis in now till 12, there is nothing plotted in that part of the graph. How can I get this to work? Thanks.
Based on the answer below, I have changed the code.
import numpy as np
import plotly.graph_objects as go
data_array = np.empty((10, 12))
for idx1, i in enumerate(range(0, 50, 5)):
for idx2, j in enumerate(range(0, 24, 2)):
data_array[idx1, idx2] = (i+j) / (50+24)
x = np.linspace(0, 45, 10)
y = np.linspace(0, 22, 12)
fig = go.Figure(data=[go.Surface(z=data_array.T)])
fig.show()
But the axes now have no correspondence with the actual x and y values. The values in the plot go from 0 to 9 and 0 to 11 for x and y axes respectively. How do I set the calibration? Thanks.


