Intricate 3D Surface Plot with Sine and Exponential Decay

Intricate 3D Surface Plot with Sine and Exponential Decay

To create a complex 3D surface plot in $Python$ using $Plotly$, we can generate a dataset that defines a surface over a grid of $x$ and $y$ values.

One common approach is to base this on mathematical functions to make the surface appear intricate, such as sinusoidal functions or $Gaussian$ surfaces, which add visually interesting layers of complexity.

Let’s walk through the steps to create a detailed 3D surface plot using $Plotly$.

1. Set Up the Libraries

First, import the required libraries:

1
2
import numpy as np
import plotly.graph_objects as go

2. Define the X and Y Grid

To create a surface, we need a grid of points for the $x$ and $y$ dimensions.

These will serve as the base coordinates for each point on our surface.

1
2
3
4
# Define the grid size
x = np.linspace(-10, 10, 100)
y = np.linspace(-10, 10, 100)
X, Y = np.meshgrid(x, y)

3. Define the Complex Function for Z Values

For a more intricate plot, we can use a combination of functions, like a $Gaussian$ function multiplied by a sine or cosine function.

This creates peaks and valleys that look complex and engaging.

1
2
# Complex function for Z
Z = np.sin(np.sqrt(X**2 + Y**2)) * np.cos(X) * np.exp(-0.1 * np.sqrt(X**2 + Y**2))

This function combines a radial sine function with a decaying exponential, adding oscillations and smooth curvature.

4. Create the Surface Plot

With the X, Y, and Z values prepared, we use $Plotly$ to create the 3D surface plot:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Create the surface plot
fig = go.Figure(data=[go.Surface(z=Z, x=X, y=Y, colorscale='Viridis')])

# Set additional plot parameters for enhanced aesthetics
fig.update_layout(
title="Complex 3D Surface Plot",
scene=dict(
xaxis_title='X-axis',
yaxis_title='Y-axis',
zaxis_title='Z-axis',
camera=dict(
eye=dict(x=1.25, y=1.25, z=1.25)
),
aspectratio=dict(x=1, y=1, z=0.5)
)
)

5. Display the Plot

Finally, display the plot with:

1
fig.show()

Explanation of the Parameters

  • Colorscale: Viridis is chosen for its high-contrast, which enhances the readability of peaks and valleys.
    You can try others like Plasma or Cividis.
  • Scene settings: This includes axis titles for clarity and a custom camera position to provide a good viewing angle.
  • Aspect ratio: Adjusts the scaling of the axes, so the plot is not distorted.

This script generates a 3D surface that features smooth transitions, sharp peaks, and interesting valleys, making it a complex and visually appealing 3D plot.

Adjusting the function or grid size can add further complexity if desired.