This is my first time using Plotly specifically, but not my first time in Numpy, Matplotlib, Pandas, etc.
I’m trying to create a 3D Surface plot using go.Surface based on the information here: 3d Surface Plots (plotly.com)
Here is a snippet of the code that I have:
import numpy as np import math import plotly.graph_objects as go x_values = np.linspace(0,0.5, 5000) y_values = np.linspace(0,2.0, 5000) x_axis, y_axis = np.meshgrid(x_values, y_values) k = 16.0 r = 0.004572 d = 0.000889 t_hot = 749.817 t_cold = 394.261 z_values = (k*2*math.pi*y_axis*(t_hot-t_cold)*x_axis)/d z_values = np.array(z_values) fig = go.Figure(data=[go.Surface(z=z_values, x=x_values, y=y_values)]) fig.update_layout(title='Test', autosize=False) fig.show()
However I cannot resolve why the figure is showing up empty. Here are the things I’ve checked:
- I create a meshgrid for the x_axis and y_axis values that I use to determine my z values.
- The z_values object is a 2D ndarray
- I plot the surface using the original linspace objects created to get the appropriately sized/scaled x and y axis
Other than how I derive my Z values it is nearly identical to one of the examples given in the knowledge document I shared above:
import plotly.graph_objects as go import pandas as pd import numpy as np # Read data from a csv z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv') z = z_data.values sh_0, sh_1 = z.shape x, y = np.linspace(0, 1, sh_0), np.linspace(0, 1, sh_1) fig = go.Figure(data=[go.Surface(z=z, x=x, y=y)]) fig.update_layout(title='Mt Bruno Elevation', autosize=False, width=500, height=500, margin=dict(l=65, r=50, b=65, t=90)) fig.show()
I made sure my z object looked the same as the examples despite the differences in how we get there i.e. an ndarray with 2 uniform dimensions (N x N)
When I run this script however the web object loads in my browser and I can interact with it as normal and the x axis and y axis looks correct given the linspaces used to plot it, but the Z axis should be scaled from 0 to around 400 million but instead it is scaled to -400 million to 400 million (which could be correct but I’m not sure how I’d set that axis manually). However the actual surface is empty, there is nothing in the graph.
If anyone has any feedback I would greatly appreciate it as I’ve been beating my head against the wall on this one for a hot minute.
It is unfortunate that the ‘tutorial’ documentation on this particular function set is seemingly lacking, with what the functions’ input requirements are, the shape/typing of the outputs, what args are necessary versus optional. I know there is a reference page that explicitly describes each method/module but its a huge list and going through it to find the needed information takes time compared to adding that info into the ‘tutorial’ page itself related to the given examples. But I am going on a tangent now.
Thank you in advance for anyone who is able to help.