我有一个带有一堆随机x,y坐标的散点图.目前,Y轴从0开始并上升到最大值.我希望Y轴从最大值开始并上升到0.
points = [(10,5), (5,11), (24,13), (7,8)]
x_arr = []
y_arr = []
for x,y in points:
x_arr.append(x)
y_arr.append(y)
plt.scatter(x_arr,y_arr)
Run Code Online (Sandbox Code Playgroud) 我正在绘制数据,其中x的范围从-1000到1000.但我只对x = -1和0之间的值感兴趣.
我还想在x对数刻度上绘图.但由于x值是负数,我不能使用xscale("log").我可以使用xscale("symlog"),这是我想要的行为.
不幸的是,"symlog"似乎被打破了.我不能使用值小于2的linthreshx参数(默认值?).但是由于我对从-1到0的x值感兴趣,我必须使用该参数并将其设置为1e-5甚至更小的值.
如果我将linthreshx设置为小于1的值,那么情节会中断.这是一个简单的例子,取自'log'和'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)
Run Code Online (Sandbox Code Playgroud)
跑步,你会看到我的意思曲线"回来"......这是结果图像:
问题似乎是,在x轴上,0实际上是10 ^ 0 = 1,而不是0.放置小于1的东西将使线返回并且轴值是错误的(当用鼠标悬停并获得时x值).
我可能没有使用正确的工具,但如何实现我想要的?我希望x轴看起来像:-10 ^ 2 -10 ^ 1 -10 ^ 0 -10 ^ -1 -10 ^ -2 -10 …