You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Python中3D图Z轴的科学计数法标签问题

解决Matplotlib 3D图Z轴1e7标识问题的两种方案

方案一:直接显示完整的大数值

关闭Z轴的科学计数法,让刻度直接显示原始完整数值:

  1. 导入matplotlib.ticker模块的ScalarFormatter
  2. 对Z轴主刻度格式化器设置useOffset=False,禁用偏移标识

修改后的绘图代码片段:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter  # 新增导入

# ... 你的planeFit函数、数据定义、拟合计算代码保持不变 ...

ax = plt.figure().add_subplot(projection='3d')
ax.scatter(x, y, z, color='r')
x1d = np.linspace(min(x), max(x), 5)
y1d = np.linspace(min(y), max(y), 5)
x2d, y2d = np.meshgrid(x1d, y1d)
zplane = a * x2d + b * y2d + c
ax.plot_surface(x2d, y2d, zplane, rstride=1, cstride=1, alpha=0.3)
ax.set_xlabel('Frame weight (Tons)')
ax.set_ylabel('GFA/L (feet)')
ax.set_zlabel('GWP (kg CO2)')

# 新增:关闭Z轴科学计数法和偏移标识
z_formatter = ScalarFormatter(useOffset=False)
z_formatter.set_scientific(False)
ax.zaxis.set_major_formatter(z_formatter)

plt.show()

方案二:保留小刻度值,在标签添加缩放说明

保留当前小刻度数值(如2.5、5等),去掉顶部1e7标识,同时在Z轴标签明确标注缩放比例:

  1. 禁用Z轴的偏移标识
  2. 修改Z轴标签为GWP (kg CO2) ×10⁷

修改后的绘图代码片段:

import numpy as np
import matplotlib.pyplot as plt

# ... 你的planeFit函数、数据定义、拟合计算代码保持不变 ...

ax = plt.figure().add_subplot(projection='3d')
ax.scatter(x, y, z, color='r')
x1d = np.linspace(min(x), max(x), 5)
y1d = np.linspace(min(y), max(y), 5)
x2d, y2d = np.meshgrid(x1d, y1d)
zplane = a * x2d + b * y2d + c
ax.plot_surface(x2d, y2d, zplane, rstride=1, cstride=1, alpha=0.3)
ax.set_xlabel('Frame weight (Tons)')
ax.set_ylabel('GFA/L (feet)')

# 修改Z轴标签并禁用偏移标识
ax.set_zlabel('GWP (kg CO2) ×10⁷')
ax.zaxis.get_major_formatter().set_useOffset(False)

plt.show()

内容的提问来源于stack exchange,提问作者user23523627

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 10:47:05