如何修复matplotlib中的添加剂变化

发布于 2025-02-08 22:48:20 字数 609 浏览 0 评论 0原文

Matplotlib在其无限的智慧中希望设定地块的局限性,以泄露尽可能多的信息。因此,如果我正确理解的话,它将在图上找到最大和最小点,确定附近的壁虱,并为这些点准备加法和/或乘法描述。

但是,当某人试图验证公式时,即如果线重叠,这些图可能会产生误导。在上面的示例中,差异左右为1E-10。

我希望拥有一个易于理解的添加剂修复程序。在上面的示例中, +5E7会很好。然后,Yticks必须全部负面。下图显示了我从两个函数中手动减去5E7后的相同关系。更容易理解。

那么,有什么简单的方法可以实现这一目标吗?

Matplotlib, in its infinite wisdom, wants to set the limits of the plots to divulge as much information as possible. Thus, if I understood correctly, it locates the maximum and minimum points on the plot, determines ticks around this vicinity and prepares additive and/or multiplicative descriptions for these points.

enter image description here

However, when someone tries to verify a formula, i.e., would be very happy if the lines overlap, such plots might be misleading. In the above example, the difference is around the order of 1e-10.

What I would prefer is to have an additive fix easy to understand. For the example above, +5e7 would make well. Then, the yticks has to be all negative. The below figure shows the same relation after I manually subtract 5e7 from both functions. Much easier to understand.

enter image description here

So, is there an easy way to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨与橙与城 2025-02-15 22:48:20

您可以首先绘制绘制(而无需实际渲染),然后使用 get_offset 获得偏移(注意:偏移既可以是乘法因子,又可以是附加偏移量>+或-):

import matplotlib.pyplot as plt
import numpy as np

x = [0, 1]
y1 = np.array([5e7, 5e7])
y2 = y1 - 6e-4

fig, ax = plt.subplots()

ax.plot(x, y1)
ax.plot(x, y2)
fig.draw_without_rendering()
offset = float(offset) if (offset := ax.yaxis.get_major_formatter().get_offset().lstrip('0123456789eE')) else 0
ax.clear()

ax.plot(x, y1 - offset)
ax.plot(x, y2 - offset)
ax.set_ylabel(f'Value - {offset:g}')

”在此处输入图像描述”

You can get the offset by first drawing the plot (without actually rendering it) and then use get_offset to get the offset (note: the offset can be both a multiplicative factor and an addivitive offset, where the latter is always preceded by + or -):

import matplotlib.pyplot as plt
import numpy as np

x = [0, 1]
y1 = np.array([5e7, 5e7])
y2 = y1 - 6e-4

fig, ax = plt.subplots()

ax.plot(x, y1)
ax.plot(x, y2)
fig.draw_without_rendering()
offset = float(offset) if (offset := ax.yaxis.get_major_formatter().get_offset().lstrip('0123456789eE')) else 0
ax.clear()

ax.plot(x, y1 - offset)
ax.plot(x, y2 - offset)
ax.set_ylabel(f'Value - {offset:g}')

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文