Spaces:
Running
Running
File size: 3,029 Bytes
57b8366 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# config/defaults.py
DEFAULT_MAP_CODE = """
# === 歡迎來到地圖繪製實驗室 ===
# 試著修改下方的參數,然後點擊「執行程式碼」看看會發生什麼事!
# --- 地圖參數設定 ---
center_lon, center_lat = 135, 35
extent_lon, extent_lat = 30, 25
map_title = "Map with Custom Symbols"
coastline_color = 'darkgreen'
# --- 符號參數設定 (在這裡新增或修改你的標記點!) ---
symbols = [
{'lon': 121.52, 'lat': 25.04, 'style': 'r*', 'label': 'Taipei 101'},
{'lon': 139.69, 'lat': 35.68, 'style': 'bs', 'label': 'Tokyo'},
{'lon': 126.97, 'lat': 37.56, 'style': 'go', 'label': 'Seoul'},
]
# --- 核心繪圖區 ---
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
fig = plt.figure(figsize=(8, 8))
projection = ccrs.Mercator(central_longitude=center_lon)
ax = fig.add_subplot(1, 1, 1, projection=projection)
ax.set_extent([center_lon - extent_lon / 2, center_lon + extent_lon / 2, center_lat - extent_lat / 2, center_lat + extent_lat / 2], crs=ccrs.PlateCarree())
ax.add_feature(cfeature.LAND, edgecolor='black', facecolor='#c5a582')
ax.add_feature(cfeature.OCEAN, facecolor='#a2d1f5')
ax.add_feature(cfeature.COASTLINE.with_scale('50m'), edgecolor=coastline_color)
ax.add_feature(cfeature.BORDERS, linestyle=':')
for symbol in symbols:
ax.plot(symbol['lon'], symbol['lat'], symbol['style'], markersize=12, markeredgecolor='white', transform=ccrs.PlateCarree(), label=symbol['label'])
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=0.7, color='gray', alpha=0.5, linestyle='--')
gl.top_labels = False
gl.right_labels = False
ax.legend()
ax.set_title(map_title)
print(f"成功繪製了 {len(symbols)} 個符號!")
# fig = fig
"""
DEFAULT_SEISMO_CODE = """
# === 歡迎來到震波圖繪製實驗室 ===
# --- 參數設定區 ---
p_wave_arrival = 10; s_wave_arrival = 25; main_freq = 2.0; decay_rate = 0.04; plot_title = "Simulated P and S Wave Arrival"
# --- 核心繪圖區 ---
import matplotlib.pyplot as plt; import numpy as np
t = np.linspace(0, 100, 1000); amp = np.zeros_like(t)
p_wave_mask = t > p_wave_arrival; p_wave = 1.0 * np.exp(-decay_rate * (t - p_wave_arrival)) * np.sin(2 * np.pi * main_freq * (t - p_wave_arrival)); amp += p_wave * p_wave_mask
s_wave_mask = t > s_wave_arrival; s_wave = 2.5 * np.exp(-decay_rate * (t - s_wave_arrival)) * np.sin(2 * np.pi * (main_freq * 0.6) * (t - s_wave_arrival)); amp += s_wave * s_wave_mask
amp += 0.1 * np.random.randn(len(t)); fig, ax = plt.subplots(figsize=(8, 4)); ax.plot(t, amp, 'k-')
ax.axvline(p_wave_arrival, color='r', linestyle='--', label=f'P-wave at {p_wave_arrival}s')
ax.axvline(s_wave_arrival, color='b', linestyle='--', label=f'S-wave at {s_wave_arrival}s')
ax.set_title(plot_title); ax.set_xlabel("Time (seconds)"); ax.set_ylabel("Amplitude"); ax.grid(True); ax.legend(); plt.tight_layout()
print(f"P-S time difference: {s_wave_arrival - p_wave_arrival} seconds")
# fig = fig
""" |