2、matplotlib中的 ax=fig.add_axes([0,0,1,1])详解


转载请附原文地址,谢谢。

从结果的角度考察ax=fig.add_axes([0,0,1,1])的作用

1、前言:(可跳过)

虽然使用matplotlib.pyplot模块可以很容易地快速生成图,但建议使用面向对象的方法,因为它可以为你的图提供更多的控制和定制。大部分的函数也可以在matplotlib.axes.Axes类中使用。使用更正式的面向对象方法背后的主要想法是创建图对象,然后只需调用该对象的方法或属性。这种方法有助于更好地处理画布上有多个图的情况。

但是在面向对象的界面中,Pyplot只用于创建图形等少数功能,用户明确地创建并跟踪图形和轴对象。在这个层面上,用户使用Pyplot创建数字,通过这些数字,可以创建一个或多个轴对象。这些坐标轴对象就可以用于大多数绘图操作。

2、步骤

首先,我们还是先创建一个图的实例,既提供一个空的画布:

fig = plt.figure()

然后为图形添加轴。add_axes()方法需要一个由4个元素组成的list对象,分别对应图形的左、底、宽、高。每个数字必须在0和1之间。

ax=fig.add_axes([0,0,1,1])

到这里,不明白fig.add_axes([0,0,1,1])是怎么回事也没关系,下面直接看实例,分别改变0,0,1,1的数值,看一下图像的变化:
下面是初始代码块

from matplotlib import pyplot as plt
import numpy as np
import math
x = np.arange(0, math.pi*2, 0.05)
y = np.sin(x)
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.plot(x,y)
plt.show()

初始显示结果如下:
在这里插入图片描述
改动为 ax= fig.add_axes([0.8,0,1,1]),由下图的显示结果可知,改变第一个参数为0.8,图像从左往右移动了80%,只能看到图片左边20%的部分。
在这里插入图片描述
改动为ax = fig.add_axes([0,0.8,1,1]),由下图的显示结果可知,改变第二个参数为0.8,图像从下往上移动了80%。
在这里插入图片描述
改动为ax = fig.add_axes([0,0,0.5,1]),由下图的显示结果可知,改变第三个参数为0.5,图像在宽度方向上压缩了一半,且位置靠在最左边。
在这里插入图片描述
改动为ax = fig.add_axes([0,0,1,0.5]),由下图的显示结果可知,改变第四个参数为0.5,图像在高度方向上压缩了一半,且位置靠在最下边。
在这里插入图片描述
这有什么用呢,下面我们同时改变这四个参数,看一下效果:
此时ax = fig.add_axes([0.5,0.5,0.3,0…3]),由下图可以看出,利用这四个参数,我们可以在原来设定的画板上的任意位置进行贴图。
在这里插入图片描述

附:以上结果仅仅是在pycharm进行的,如果你是在jupyter notebook中进行的,也是一样的道理,如下截图所示:
在这里插入图片描述

import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from matplotlib.animation import FuncAnimation from mpl_toolkits.mplot3d import Axes3D import ipywidgets as widgets from IPython.display import display plt.rcParams['axes.unicode_minus'] = False # 解决负号显示问题 plt.rcParams["font.family"] = "SimHei" # 设置中文字体 # 物理常数 c = 3e8 # 光速 (m/s) class FDAArraySimulator: def __init__(self, f0=10e9, delta_f=50e3, N=16): """ 初始化FDA阵列仿真器 参数: f0: 中心频率 (Hz) delta_f: 频率增量 (Hz) - 关键FDA参数 N: 阵元数量 """ self.f0 = f0 self.delta_f = delta_f self.N = N self.d = 0.5 * c / f0 # 阵元间距 (半波长) # 仿真参数 self.theta = np.linspace(-90, 90, 181) # 方位角 () self.R = np.linspace(100, 10000, 101) # 距离 () self.time_points = np.linspace(0, 1e-3, 100) # 时间序列 () self.theta_rad = np.deg2rad(self.theta) # 转换为弧度 def calculate_fda_beam(self, t): """ 计算FDA阵列因子,体现空间-时间耦合特性 参数: t: 时间点 () 返回: 归一化的阵列因子 (距离 × 角度) """ # 初始化阵列因子矩阵 AF = np.zeros((len(self.R), len(self.theta)), dtype=complex) for m in range(self.N): # 遍历每个阵元 # 计算当前阵元的频率 f_m = self.f0 + m * self.delta_f # 空间相位分量 (角度相关) space_phase = 2 * np.pi * f_m * (m * self.d * np.sin(self.theta_rad)) / c #体现角度依赖性(波束方向) # 时间相位分量 (时间相关) time_phase = 2 * np.pi * self.delta_f * m * t #实现时间相关性(自动扫描特性) # 距离相位分量 (距离相关) range_phase = 2 * np.pi * f_m * self.R[:, None] / c #引入距离依赖性(FDA独特特性) # 综合阵列因子 - 体现空间-时间耦合 AF += np.exp(1j * (space_phase - range_phase + time_phase)) return np.abs(AF) / self.N # 归一化 def plot_spatio_temporal_coupling(self, t=0.5e-3): """ 可视化空间-时间耦合特性 参数: t: 时间点 () """ fig = plt.figure(figsize=(15, 10)) # 计算波束方向图 beam_pattern = self.calculate_fda_beam(t) # 1. 距离-角度热力图 plt.subplot(2, 2, 1) plt.imshow(20 * np.log10(beam_pattern + 1e-10), extent=[self.theta.min(), self.theta.max(), self.R.min() / 1000, self.R.max() / 1000], aspect='auto', cmap='jet', origin='lower') plt.colorbar(label='增益 (dB)') plt.xlabel('方位角 ()') plt.ylabel('距离 (km)') plt.title(f'FDA空间-时间耦合特性 (t={t * 1000:.1f}ms)') # 2. 固定距离的切面 plt.subplot(2, 2, 2) fixed_range_idx = 50 # 选择中间距离 plt.plot(self.theta, 20 * np.log10(beam_pattern[fixed_range_idx, :] + 1e-10)) plt.xlabel('方位角 ()') plt.ylabel('增益 (dB)') plt.title(f'固定距离{self.R[fixed_range_idx] / 1000:.1f}km的波束方向图') plt.grid(True) # 3. 固定角度的切面 plt.subplot(2, 2, 3) fixed_angle_idx = 90 # 选择0度方向 plt.plot(self.R / 1000, 20 * np.log10(beam_pattern[:, fixed_angle_idx] + 1e-10)) plt.xlabel('距离 (km)') plt.ylabel('增益 (dB)') plt.title(f'固定方位角{self.theta[fixed_angle_idx]:.0f}°的波束方向图') plt.grid(True) # 4. 空间-时间耦合示意图 plt.subplot(2, 2, 4) # 在固定距离和角度上观察增益随时间变化 fixed_range = 5000 # 固定距离5km fixed_angle = 0 # 固定角度0度 r_idx = np.argmin(np.abs(self.R - fixed_range)) a_idx = np.argmin(np.abs(self.theta - fixed_angle)) # 计算时间序列上的增益变化 time_gain = [] for time_point in self.time_points: beam = self.calculate_fda_beam(time_point) time_gain.append(20 * np.log10(beam[r_idx, a_idx] + 1e-10)) plt.plot(self.time_points * 1000, time_gain) plt.xlabel('时间 (ms)') plt.ylabel('增益 (dB)') plt.title(f'固定点(θ={fixed_angle}°, R={fixed_range / 1000:.1f}km)的增益随时间变化') plt.grid(True) plt.tight_layout() plt.show() def animate_auto_scanning(self): """ 创建自动扫描特性的动画 """ fig = plt.figure(figsize=(10, 8)) ax = fig.add_subplot(111, projection='3d') # 创建网格 T, R_grid = np.meshgrid(self.theta, self.R / 1000) # 初始化空图 beam = self.calculate_fda_beam(0) Z = 20 * np.log10(beam + 1e-10) surf = ax.plot_surface(T, R_grid, Z, cmap=cm.jet, alpha=0.8) # 设置坐标轴标签 ax.set_xlabel('方位角 ()') ax.set_ylabel('距离 (km)') ax.set_zlabel('增益 (dB)') ax.set_title('FDA自动扫描特性 (t=0 ms)') ax.set_zlim(-40, 0) # 更新函数用于动画 def update(frame): ax.clear() t = self.time_points[frame] beam = self.calculate_fda_beam(t) Z = 20 * np.log10(beam + 1e-10) surf = ax.plot_surface(T, R_grid, Z, cmap=cm.jet, alpha=0.8) ax.set_xlabel('方位角 ()') ax.set_ylabel('距离 (km)') ax.set_zlabel('增益 (dB)') ax.set_title(f'FDA自动扫描特性 (t={t * 1000:.1f} ms)') ax.set_zlim(-40, 0) return surf, # 创建动画 ani = FuncAnimation(fig, update, frames=len(self.time_points), interval=50, blit=False) plt.tight_layout() plt.show() return ani def interactive_parameter_analysis(self): """ 交互式参数分析界面 """ style = {'description_width': 'initial'} # 创建交互控件 delta_f_slider = widgets.FloatLogSlider( value=self.delta_f, min=3, max=6, step=0.1, description='频率增量Δf (Hz):', readout_format='.0f', style=style ) time_slider = widgets.FloatSlider( value=0, min=0, max=1e-3, step=1e-5, description='时间 t (s):', readout_format='.5f', style=style ) angle_slider = widgets.FloatSlider( value=0, min=-90, max=90, step=1, description='固定角度θ ():', style=style ) range_slider = widgets.FloatSlider( value=5000, min=100, max=10000, step=100, description='固定距离R (m):', style=style ) # 更新函数 def update_plots(delta_f_val, t_val, fixed_angle, fixed_range): # 临时创建新的仿真器实例 temp_simulator = FDAArraySimulator( f0=self.f0, delta_f=delta_f_val, N=self.N ) # 计算波束方向图 beam_pattern = temp_simulator.calculate_fda_beam(t_val) # 创建图形 fig, axs = plt.subplots(1, 2, figsize=(15, 6)) # 1. 距离-角度热力图 im = axs[0].imshow(20 * np.log10(beam_pattern + 1e-10), extent=[self.theta.min(), self.theta.max(), self.R.min() / 1000, self.R.max() / 1000], aspect='auto', cmap='jet', origin='lower') fig.colorbar(im, ax=axs[0], label='增益 (dB)') axs[0].set_xlabel('方位角 ()') axs[0].set_ylabel('距离 (km)') axs[0].set_title(f'FDA波束方向图 (Δf={delta_f_val / 1000:.1f}kHz, t={t_val * 1000:.2f}ms)') # 2. 固定角度和距离的增益变化 r_idx = np.argmin(np.abs(self.R - fixed_range)) a_idx = np.argmin(np.abs(self.theta - fixed_angle)) # 计算时间序列上的增益变化 time_gain = [] for time_point in self.time_points: temp_beam = temp_simulator.calculate_fda_beam(time_point) time_gain.append(20 * np.log10(temp_beam[r_idx, a_idx] + 1e-10)) axs[1].plot(self.time_points * 1000, time_gain) axs[1].axvline(x=t_val * 1000, color='r', linestyle='--', label=f'当前时间: {t_val * 1000:.2f}ms') axs[1].set_xlabel('时间 (ms)') axs[1].set_ylabel('增益 (dB)') axs[1].set_title(f'固定点(θ={fixed_angle}°, R={fixed_range / 1000:.1f}km)的增益随时间变化') axs[1].grid(True) axs[1].legend() plt.tight_layout() plt.show() # 创建交互界面 widgets.interactive( update_plots, delta_f_val=delta_f_slider, t_val=time_slider, fixed_angle=angle_slider, fixed_range=range_slider ) # ========== 主执行函数 ========== if __name__ == "__main__": print("频控阵天线(FDA)波束特性仿真") # 创建FDA仿真器实例 fda_simulator = FDAArraySimulator() print("1. 空间-时间耦合特性") fda_simulator.plot_spatio_temporal_coupling() print("\n2. 自动扫描特性 (动画展示)") fda_simulator.animate_auto_scanning() print("\n3. 交互式参数分析") fda_simulator.interactive_parameter_analysis()
最新发布
07-26
为什么下面的代码里,最后面的print函数里的中文输出无法正常显示: # encoding: utf-8 import scipy.io import numpy as np import matplotlib.pyplot as plt from scipy import signal import matplotlib as mpl import matplotlib.font_manager as fm import pandas as pd import seaborn as sns import os from pathlib import Path plt.rcParams['font.sans-serif'] = ['SimHei'] # 使用黑体显示中文 plt.rcParams['axes.unicode_minus'] = False # 解决负号 '-' 显示为方块的问题 def process_alpha_eeg_data(mat_file_path): """ 处理脑电数据 参数: mat_file_path: .mat文件路径 返回: fig: 生成的图表对象 results_df: 包含所有分析结果的DataFrame """ # 1. .mat文件数据 mat_data = scipy.io.loadmat(mat_file_path) # 2. 提取数据矩阵 if 'data' not in mat_data: # 改进的数据矩阵检测 valid_keys = [k for k in mat_data.keys() if not k.startswith('__') and isinstance(mat_data[k], np.ndarray) and mat_data[k].ndim == 2] if not valid_keys: raise ValueError("未找到有效的二维数据矩阵") # 选择最大的数据矩阵 data_matrix = mat_data[max(valid_keys, key=lambda k: mat_data[k].size)] print(f"使用自动检测到的数据矩阵: {max(valid_keys, key=lambda k: mat_data[k].size)}") else: data_matrix = mat_data['data'] # 3. 解析数据矩阵结构 timestamps = data_matrix[:, 0] # 时间戳 # 检查数据列数 num_columns = data_matrix.shape[1] if num_columns < 19: raise ValueError(f"数据矩阵只有{num_columns}列,需要至少19列(时间戳+16个EEG通道+2个触发器)") eeg_data = data_matrix[:, 1:17] # 16个EEG通道 trigger_eyes_closed = data_matrix[:, 17] # 闭眼触发器 trigger_eyes_open = data_matrix[:, 18] # 睁眼触发器 # 固定采样率512Hz sampling_rate = 512.0 # 4. 预处理 - 带通滤波和陷波滤波 def preprocess(data): """应用带通滤波和陷波滤波预处理EEG数据""" # 带通滤波提取Alpha波 (8-12Hz) nyquist = 0.5 * sampling_rate low = 8 / nyquist high = 12 / nyquist b, a = signal.butter(4, [low, high], btype='bandpass') alpha_data = signal.filtfilt(b, a, data) # 陷波滤波去除50/60Hz工频干扰 notch_freq = 50.0 # 根据实际工频干扰调整 notch_width = 2.0 freq = notch_freq / nyquist q = freq / (notch_width / nyquist) b, a = signal.iirnotch(freq, q) return signal.filtfilt(b, a, alpha_data) # 应用预处理到所有通道 eeg_data_filtered = np.apply_along_axis(preprocess, 0, eeg_data) # 5. 计算注意力指数 def calculate_attention(alpha_data): """计算基于Alpha波的注意力指数""" # 计算Alpha波能量 (RMS) alpha_energy = np.sqrt(np.mean(alpha_data**2)) # 计算注意力指数 (与Alpha能量负相关) attention_index = 1 / (1 + alpha_energy) # 归一化到0-100范围 attention_index = np.clip(attention_index * 100, 0, 100) return attention_index # 6. 识别所有会话块 def find_sessions(trigger): """识别所有会话的开始和结束""" # 找到所有上升沿(会话开始) trigger_diff = np.diff(trigger) session_starts = np.where(trigger_diff == 1)[0] + 1 # 找到所有下降沿(会话结束) session_ends = np.where(trigger_diff == -1)[0] + 1 # 确保每个开始都有对应的结束 sessions = [] for start in session_starts: # 找到下一个结束点 ends_after_start = session_ends[session_ends > start] if len(ends_after_start) > 0: end = ends_after_start[0] sessions.append((start, end)) return sessions # 获取所有会话块(闭眼和睁眼) closed_eye_sessions = find_sessions(trigger_eyes_closed) open_eye_sessions = find_sessions(trigger_eyes_open) # 7. 处理每个会话块 session_results = [] # 处理闭眼会话块 for session_idx, (start_idx, end_idx) in enumerate(closed_eye_sessions): # 提取会话数据 session_eeg = eeg_data_filtered[start_idx:end_idx, :] session_duration = (end_idx - start_idx) / sampling_rate # 计算平均注意力指数(所有通道) channel_attention = [] for ch in range(session_eeg.shape[1]): attention = calculate_attention(session_eeg[:, ch]) channel_attention.append(attention) session_avg_attention = np.mean(channel_attention) # 存储会话结果 session_results.append({ 'session_id': session_idx + 1, 'condition': '闭眼', 'start_time': timestamps[start_idx], 'duration': session_duration, 'avg_attention': session_avg_attention, 'channel_attention': channel_attention }) # 处理睁眼会话块 for session_idx, (start_idx, end_idx) in enumerate(open_eye_sessions): # 提取会话数据 session_eeg = eeg_data_filtered[start_idx:end_idx, :] session_duration = (end_idx - start_idx) / sampling_rate # 计算平均注意力指数(所有通道) channel_attention = [] for ch in range(session_eeg.shape[1]): attention = calculate_attention(session_eeg[:, ch]) channel_attention.append(attention) session_avg_attention = np.mean(channel_attention) # 存储会话结果 session_results.append({ 'session_id': session_idx + 1 + len(closed_eye_sessions), 'condition': '睁眼', 'start_time': timestamps[start_idx], 'duration': session_duration, 'avg_attention': session_avg_attention, 'channel_attention': channel_attention }) # 创建结果DataFrame results_df = pd.DataFrame(session_results) # 8. 简化可视化结果 - 只保留两个图表 fig = plt.figure(figsize=(16, 10), constrained_layout=True) gs = fig.add_gridspec(2, 1) # 2行1列布局 # 图1: 随时间变化的注意力指数 ax1 = fig.add_subplot(gs[0, 0]) # 为不同条件设置不同颜色 colors = {'闭眼': 'blue', '睁眼': 'orange'} for condition in ['闭眼', '睁眼']: condition_data = results_df[results_df['condition'] == condition] ax1.plot(condition_data['session_id'], condition_data['avg_attention'], 'o-', label=condition, markersize=8, color=colors[condition]) ax1.set_title('不同条件下注意力指数随时间变化', fontsize=16) ax1.set_xlabel('会话块编号', fontsize=14) ax1.set_ylabel('平均注意力指数 (%)', fontsize=14) ax1.legend(fontsize=12) ax1.grid(True, linestyle='--', alpha=0.3) # 添加每个数据点的数值标签 for _, row in results_df.iterrows(): ax1.text(row['session_id'], row['avg_attention'] + 2, f"{row['avg_attention']:.1f}", ha='center', va='bottom', fontsize=9) # 图2: 闭眼与睁眼条件下的注意力比较 ax2 = fig.add_subplot(gs[1, 0]) # 箱线图展示条件间差异 sns.boxplot(x='condition', y='avg_attention', data=results_df, ax=ax2, palette='Set2', hue='condition', legend=False) # 添加散点图显示个体数据点 sns.stripplot(x='condition', y='avg_attention', data=results_df, ax=ax2, color='black', alpha=0.7, size=7, jitter=True) ax2.set_title('闭眼与睁眼条件下注意力比较', fontsize=16) ax2.set_xlabel('条件', fontsize=14) ax2.set_ylabel('平均注意力指数 (%)', fontsize=14) # 添加统计显著性标记(使用独立样本t检验) from scipy import stats closed_data = results_df[results_df['condition'] == '闭眼']['avg_attention'] open_data = results_df[results_df['condition'] == '睁眼']['avg_attention'] t_stat, p_value = stats.ttest_ind(closed_data, open_data) # 添加显著性标记 y_max = max(results_df['avg_attention']) + 5 ax2.plot([0, 0, 1, 1], [y_max, y_max+2, y_max+2, y_max], lw=1.5, c='black') ax2.text(0.5, y_max+3, f"p = {p_value:.4f}", ha='center', va='bottom', fontsize=12) plt.tight_layout() # 9. 保存结果 base_name = os.path.splitext(os.path.basename(mat_file_path))[0] # 保存图像 fig.savefig(f"{base_name}_analysis.png", dpi=300, bbox_inches='tight') # 保存结果到CSV results_df.to_csv(f"{base_name}_results.csv", index=False, encoding='utf-8-sig') return fig, results_df, p_value # 使用示例 if __name__ == "__main__": # 中文路径示例 mat_file = "F:/Grade2/attention/2348892/subject_02.mat" try: # 处理数据并生成可视化 fig, results_df, p_value = process_alpha_eeg_data(mat_file) # 显示图像 plt.show() # 打印会话结果和统计显著性 print("EEG分析结果:") print(results_df[['session_id', 'condition', 'duration', 'avg_attention']]) print(f"\n统计显著性结果: p = {p_value:.4f}") if p_value < 0.05: print("闭眼与睁眼条件下的注意力指数存在显著差异 (p < 0.05)") else: print("闭眼与睁眼条件下的注意力指数无显著差异") except Exception as e: print(f"处理过程中发生错误: {str(e)}") import traceback traceback.print_exc()
06-27
<think>嗯,用户想了解matplotlib中的ax.plot_surface的用法和含义。首先,我需要回忆一下这个函数的基本作用。plot_surface主要用于绘制三维曲面图,对吧?它需要X、Y、Z三个二维数组来定义曲面的点。参数方面,用户可能关心的是rstride和cstride,这两个参数控制行和列的步长,影响曲面的网格密度。还有cmap参数,用来设置颜色映射,可能和颜色渐变有关。另外,edgecolor可以调整网格线的颜色,或者设为'none'去掉边线。接下来,我需要确认用户可能的背景。他们可能已经有一些Matplotlib的基础,但需要更深入地了解三维绘图部分。用户提供的引用中提到了曲面图的示例代码,比如使用plot_surface和plot_trisurf,所以可能需要对比这两个函数的区别。比如,plot_surface适用于规则网格数据,而plot_trisurf适合非结构化的数据。用户的需求是知道用法和示例,所以回答应该包括函数的基本语法、参数解释以及一个简单的示例。可能还需要提到如何生成X、Y网格数据,比如使用numpy的meshgrid函数。此外,用户可能想知道常见问题,比如为什么需要二维数组,或者如何处理数据格式的问题。还要注意引用中的内容,比如引用4提到了plot_trisurf的使用,可能需要说明plot_surface与之的不同。同时,用户可能遇到错误,比如数据维度不匹配,这时候需要强调X、Y、Z必须是二维的。另外,示例代码部分需要确保正确性,比如导入Axes3D,设置投影为3d,以及正确生成数据。可能还需要解释每个步骤的作用,比如创建画布、添加子图等。最后,生成的相关问题要围绕用户可能进一步探索的方向,比如调整曲面颜色、处理不规则数据、常见错误解决等。这些问题应该帮助用户深入理解plot_surface的应用场景和技巧。</think>### `ax.plot_surface` 用法与含义详解 `ax.plot_surface` 是 Matplotlib 中绘制三维曲面的核心函数,通过定义 $X$、$Y$、$Z$ 坐标生成连续曲面。以下是详细解析: --- #### 一、**函数语法与参数** ```python ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=None, edgecolor='k', alpha=1.0) ``` - **`X, Y, Z`**: 二维数组,表示三维坐标点。需通过 `np.meshgrid` 生成规则网格数据[^4]。 - **`rstride`/`cstride`**: 行/列方向采样步长,值越大网格越稀疏。例如 `rstride=5` 表示每隔5行取一个数据点[^3]。 - **`cmap`**: 颜色映射,如 `'viridis'`、`'jet'`,用于根据 $Z$ 值着色曲面[^2]。 - **`edgecolor`**: 曲面网格线颜色,设为 `'none'` 可隐藏边线[^3]。 --- #### 二、**基础示例** ```python import matplotlib.pyplot as plt import numpy as np # 生成数据 x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, y) Z = np.sin(np.sqrt(X**2 + Y**2)) # 定义曲面高度 # 绘图 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_surface(X, Y, Z, rstride=2, cstride=2, cmap='viridis', edgecolor='none') ax.set_title('3D Surface Plot') plt.show() ``` ![示例图](https://via.placeholder.com/400x300/EEE/000?text=3D+Surface+Plot) *此代码生成一个正弦波纹曲面,使用 `viridis` 颜色映射并隐藏网格线*[^3][^4]。 --- #### 三、**核心注意事项** 1. **数据格式要求** - $X$、$Y$、$Z$ 必须是二维数组,且维度一致(如 $100 \times 100$)。 - 若数据非网格化,需使用 `np.meshgrid` 或 `ax.plot_trisurf`(适用于非结构化数据)[^4]。 2. **性能优化** - 减少网格密度(增大 `rstride`/`cstride`)可提升渲染速度。 - 对大数据集可采样后绘图。 ---
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

steelDK

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值