在 Matplotlib 中对含有零值的图像进行对数缩放


若要在 matplotlib 中对包含零值的图像进行对数缩放,我们可以使用按名称指定的**xscale()**和**yscale()**方法与**"symlog"**类。

步骤

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

  • 使用**plot()**方法绘制两个包含零值的列表。

  • 按名称使用**yscale()**方法与**"symlog"**类。

  • 按名称使用**xscale()**方法与**"symlog"**类。

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

实例

from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.plot([0, 1, 2, 0, 3], [1, 0, 2, 3, 5], marker='o', linestyle='-')
plt.yscale('symlog')
plt.xscale('symlog')
plt.show()

输出

更新时间: 2021-06-01

1 千次以上浏览

开启你的职业生涯

完成课程获取认证

开始
广告
© . All rights reserved.