Skip to content

Code Emitter problem in Obsidian #174

@hexiongwu1995

Description

@hexiongwu1995

Code Emitter problem in Obsidian

In Obsidian, When I click the run button of the up Code Block, it returns the picture of the below Code Block.
And the problem repeats again and again and again. I have already disabled the auto-run functiuon, but the problem continues.
please provide some advices. Thanks a lot.

import numpy as np
import matplotlib.pyplot as plt

k = 9.93e6
wavelength = 6.328e-7
z = np.linspace(0, 3*wavelength, 100)
E = np.cos(k * z)

plt.plot(z, E, color='red', linestyle='-')
plt.xlabel('Direction of plane wave propagation z (m)')
plt.ylabel('Vibrating direction of Electric field E (V/m)')
plt.title('Distribution of Electric field along direction of propagation at t=0')
plt.grid(True, color='grey', alpha=0.8, linestyle=':')

print("\n This is the Distribution of Electric field along direction of propagation at t=0 for He-Ne laser :")
plt.show()
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# ==========================================
# 1. Physical parameter definitions
# ==========================================
# Wave number k (rad/m)
k = 9.93e6 

# To make the waveform clearly visible, we need to plot on a very small scale
# Wavelength lambda = 2*pi / k ≈ 632.8 nm
wavelength = 2 * np.pi / k

# Define z-axis range: plot distance from 0 to 2.5 wavelengths
# If using meters directly, the values are too small and require very dense sampling
z = np.linspace(0, 2.5 * wavelength, 500)

# ==========================================
# 2. Calculate field components (t=0)
# ==========================================
# Electric field E(z) = cos(k*z) x_hat (V/m)
# Amplitude set to 1
E_x = np.cos(k * z)
E_y = np.zeros_like(z)
E_z = np.zeros_like(z)

# Magnetic field B(z) = 3.33e-9 * cos(k*z) y_hat (T)
# The real amplitude is 3.33e-9, but for visualization we scale it
# B_visual here is only for plot length, not representing actual physical value
B_amp_real = 3.33e-9
B_scale_factor = 1.0 / B_amp_real  # Scale B field to similar magnitude as E for visualization
B_visual_y = B_amp_real * B_scale_factor * np.cos(k * z)

B_x = np.zeros_like(z)
B_z = np.zeros_like(z)

# ==========================================
# 3. 3D visualization plotting
# ==========================================
fig = plt.figure(figsize=(10, 6), dpi=120)  # Adjust DPI for better Obsidian display
ax = fig.add_subplot(111, projection='3d')

# Plot propagation axis (Z axis)
ax.plot(z * 1e9, np.zeros_like(z), np.zeros_like(z), 'k--', lw=1, alpha=0.5, label='Propagation (z)')

# Plot electric field E (red, x direction)
# Use plot to draw the envelope
ax.plot(z * 1e9, E_x, E_y, 'r-', linewidth=1.5, label='E Field (V/m)')
# Use quiver to draw vector arrows (downsampled to avoid overcrowding)
step = 20
ax.quiver(z[::step] * 1e9, np.zeros_like(z)[::step], np.zeros_like(z)[::step], 
          0, E_x[::step], 0, 
          color='r', alpha=0.6, arrow_length_ratio=0.1)

# Plot magnetic field B (blue, y direction)
# Use plot to draw the envelope
ax.plot(z * 1e9, B_x, B_visual_y, 'b-', linewidth=1.5, label='B Field (Scaled)')
# Use quiver to draw vector arrows
ax.quiver(z[::step] * 1e9, np.zeros_like(z)[::step], np.zeros_like(z)[::step], 
          0, 0, B_visual_y[::step], 
          color='b', alpha=0.6, arrow_length_ratio=0.1)

# ==========================================
# 4. Chart beautification and annotation
# ==========================================
ax.set_xlabel('z (nm)')  # Convert z axis to nanometers for display
ax.set_ylabel('x (E-field direction)')
ax.set_zlabel('y (B-field direction)')
ax.set_title('He-Ne Laser Plane Wave at t=0\nE (Red) & B (Blue) Orthogonality')

# Set axis limits to ensure good proportion
ax.set_ylim(-1.5, 1.5)
ax.set_zlim(-1.5, 1.5)

# Adjust view angle to clearly show orthogonality
ax.view_init(elev=20, azim=-45)

plt.legend()
plt.tight_layout()
plt.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions