用计算出的值替换 matplotlib 刻度标记的正确方法是什么?


我们可以使用 ax.loglog(x, y)set_major_formatter() 方法用计算出的值替换刻度标签。

步骤

  • 设置图形大小并调整子图之间和周围的填充。

  • 创建一个图形和一组子图。

  • 对 X 和 Y 轴进行对数缩放绘制一个图形。

  • 设置主要刻度线的格式化程序。

  • 若要显示图形,请使用 show() 方法。

示例

Open Compiler
import numpy as np from matplotlib import pyplot as plt, ticker plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() ax.loglog(np.logspace(0, 5), np.logspace(0, 5)**2) ax.xaxis.set_major_formatter(ticker.LogFormatterExponent()) plt.show()

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

输出

更新于: 2021 年 9 月 23 日

290 次浏览

开启你的职业生涯

完成课程获得认证

开始
广告