Shep
Shep

Reputation: 8370

Exception in `transform_non_affine` with log axis

I'm getting a weird error when I try to use axes.transData when plotting on a log scale. Minimal code to reproduce this error:

#!/usr/bin/env python3
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure

fig = Figure(figsize=(8,6))
canvas = FigureCanvas(fig)
ax = fig.add_subplot(1,1,1)
ax.plot(range(10))
ax.set_yscale('log')                 # <--- works fine without this line
print(ax.transData.transform((1,1))) # <--- exception thrown here
canvas.print_figure('test.pdf')

The stack trace is as follows:

  File "/usr/local/lib/python3.3/site-packages/matplotlib-1.3.1-py3.3-linux-x86_64.egg/matplotlib/transforms.py", line 1273, in transform
    return self.transform_affine(self.transform_non_affine(values))
  File "/usr/local/lib/python3.3/site-packages/matplotlib-1.3.1-py3.3-linux-x86_64.egg/matplotlib/transforms.py", line 2217, in transform_non_affine
    return self._a.transform_non_affine(points)
  File "/usr/local/lib/python3.3/site-packages/matplotlib-1.3.1-py3.3-linux-x86_64.egg/matplotlib/transforms.py", line 2002, in transform_non_affine
    x_points = x.transform_non_affine(points)[:, 0:1]
TypeError: tuple indices must be integers, not tuple

If I comment out the set_yscale('log') it runs fine. Does anyone know why this transform doesn't work?

Upvotes: 1

Views: 89

Answers (1)

Shep
Shep

Reputation: 8370

Not completely satisfying, but I found a workaround. The issue seems to be related to the 1 dimensional array input to transform. Oddly it works if I use this:

ax.transData.transform(pts[None,:])

In other words, I have to reshape the array make it 2 dimensional.

Upvotes: 1

Related Questions