pythonmatplotlib怎么设置曲线_python – Matplotlib的“symlog”选项:如何防止曲线“回来”?...

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

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

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

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

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值