【问题标题】:Matplotlib's "symlog" option: how to prevent curves that "come back"?Matplotlib 的“symlog”选项:如何防止“回来”的曲线?
【发布时间】:2023-04-02 00:00:02
【问题描述】:

我正在绘制从 -1000 到 1000 的 x 范围内的数据。但我只对 x = -1 和 0 之间的值感兴趣。

我还想在 x 对数刻度上绘图。但由于 x 值为负,我不能使用 xscale("log")。我可以使用 xscale("symlog") ,这是我想要的行为。

不幸的是,“symlog”似乎被破坏了。我不能使用值小于 2(默认值?)的 linthreshx 参数。但由于我对从 -1 到 0 的 x 值感兴趣,因此我必须使用该参数并将其设置为 1e-5 甚至更小。

如果我将 linthreshx 设置为小于 1 的值,情节就会中断。这是一个简单的例子,取自What is the difference between 'log' and 'symlog'?

import numpy
from matplotlib import pyplot

# Enable interactive mode
pyplot.ion()

# Draw the grid lines
pyplot.grid(True)

# Numbers from -50 to 50, with 0.1 as step
xdomain = numpy.arange(-50,50, 0.1)

# Plots a simple linear function 'f(x) = x'
pyplot.plot(xdomain, xdomain)
# Plots 'sin(x)'
pyplot.plot(xdomain, numpy.sin(xdomain))

pyplot.axis([-60,60,-1.5,1.5])

pyplot.xscale('symlog', linthreshx=0.1)

运行你会明白我所说的“回归”曲线是什么意思...这是生成的图像:

问题似乎是,在 x 轴上,0 实际上是 10^0 = 1,而不是 0。放置小于 1 的值会使线返回并且轴值错误(当悬停在鼠标并获取 x 值)。

虽然我可能没有使用正确的工具,但如何实现我想要的?我希望 x 轴看起来像:-10^2 -10^1 -10^0 -10^-1 -10^-2 -10^-3 ... [达到我定义的最小指数] ... 10^-3 10^-2 10^-1 10^0 10^1 10^2

谢谢

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    这实际上是 matplotlib 中的一个错误。

    https://github.com/matplotlib/matplotlib/issues/396

    现在已修复。我附上一张图片,显示上一个 sn-p 的正确结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      • 2012-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      相关资源
      最近更新 更多