python和log有啥区别_“ log”和“ symlog”有什么区别?

我终于找到了一些时间来做一些实验,以了解它们之间的区别。这是我发现的:

log仅允许使用正值,并允许您选择如何处理负值(mask或clip)。

symlog表示对数对称,并允许正值和负值。

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))

# 'linear' is the default mode, so this next line is redundant:

pyplot.xscale('linear')

使用“线性”缩放的图

# How to treat negative values?

# 'mask' will treat negative values as invalid

# 'mask' is the default, so the next two lines are equivalent

pyplot.xscale('log')

pyplot.xscale('log', nonposx='mask')

使用'log'缩放和nonposx ='mask'的图形

# 'clip' will map all negative values a very small positive one

pyplot.xscale('log', nonposx='clip')

使用'log'缩放和nonposx ='clip'的图形

# 'symlog' scaling, however, handles negative values nicely

pyplot.xscale('symlog')

使用“符号”缩放的图形

# And you can even set a linear range around zero

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

使用“符号”缩放比例的图形,但线性在(-20,20)

为了完整起见,我使用以下代码保存每个图:

# Default dpi is 80

pyplot.savefig('matplotlib_xscale_linear.png', dpi=50, bbox_inches='tight')

请记住,您可以使用以下方法更改图形大小:

fig = pyplot.gcf()

fig.set_size_inches([4., 3.])

# Default size: [8., 6.]

(如果您不知道我的回答我的问题,请阅读本)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值