只要指定basex = 2或basey = 2.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set_xscale('log', basex=2)
ax.set_yscale('log', basey=2)
ax.plot(range(1024))
plt.show()
对于过零行为,您所指的是“对称日志”图(a.k.a.“symlog”).无论什么值得,数据都不会被过滤掉,它只是一个0附近的线性图,其他地方都有一个日志图.这是变化的规模,而不是数据.
通常你只需要做ax.set_xscale(‘symlog’,basex = 2),但是使用非10基地似乎在symlog图上是错误的.
编辑:
嘿!该bug似乎是由于一个经典的错误:使用可变的默认参数.
我提交了一个错误报告,但是如果您想修复它,则需要在SymmetricalLogLocator的__init__方法中,对第1376行的lib / matplotlib / ticker.py进行小编编辑.
代替
def __init__(self, transform, subs=[1.0]):
self._transform = transform
self._subs = subs
...
将其更改为类似于以下内容:
def __init__(self, transform, subs=None):
self._transform = transform
if subs is None:
self._subs = [1.0]
else:
self._subs = subs
....
随着这个变化,它的行为与预期的一样
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
ax.set_xscale('symlog', basex=2)
ax.set_yscale('symlog', basey=2)
x = np.arange(-1024, 1024)
ax.plot(x, x)
plt.show()