matplotlib/matplotlib — Issue #679: Symlog plotting is broken for anything other than base 10
Author: joferkington
Created: 2012-01-17 00:58:56+00:00
State: open

Symlog plotting raises an `IndexError` if `basex` or `basey` is anything other than `10`.

As an example:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.set_xscale('symlog', basex=2)

x = range(1024)
ax.plot(x)

plt.show()

This appears to be due to a mutable default argument in `ticker.SymmetricalLogLocator`.

Changing:

class SymmetricalLogLocator(Locator):
"""
Determine the tick locations for log axes
"""

def __init__(self, transform, subs=[1.0]):
"""
place ticks on the location= base**i*subs[j]
"""
self._transform = transform
self._subs = subs
self.numticks = 15

To:

class SymmetricalLogLocator(Locator):
"""
Determine the tick locations for log axes
"""

def __init__(self, transform, subs=None):
"""
place ticks on the location= base**i*subs[j]
"""
self._transform = transform
if subs is None:
self._subs = [1.0]
else:
self._subs = subs
self.numticks = 15

Appears to solve the problem.