我正在绘制数据,其中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
谢谢