我想使用对数刻度绘制以下几对点。
import matplotlib.pyplot as plt
f, ax = plt.subplots(1)
xdata = [256, 512, 1024, 2048]
ydata = [1, 2, 30, 150]
ax.scatter(xdata, ydata)
ax.set_ylim(ymin=0)
ax.set_xlim(xmin=0)
plt.show(f)
这些点会渲染,但我不知道如何使两个轴上的刻度以 2 为底的对数。我希望每个增量都使值翻倍,例如x 增量应为 0、256、512、1024、2048(字节),y 增量应为分钟,其中数据现在以秒为单位:0、1、2、4、8、16、32。
能做到吗?
你想要的叫做对数规模(而不是指数)。我想这就是为什么你自己没有找到答案的原因,否则你很容易得出答案相应的 matplotlib 示例 https://matplotlib.org/examples/pylab_examples/log_demo.html.
The following should work (the only discrepancy from your requirements is that the axes labels are in the form of 2n rather than plain numbers):
import matplotlib.pyplot as plt
f, ax = plt.subplots(1)
xdata = [256, 512, 1024, 2048]
ydata = [1, 2, 30, 150]
plt.xscale('log', basex=2)
plt.yscale('log', basey=2)
ax.scatter(xdata, ydata)
ax.set_ylim(ymin=0)
plt.show(f)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)