【发布时间】:2014-11-16 19:58:23
【问题描述】:
当我尝试在对数刻度上绘制时使用 axes.transData 时遇到一个奇怪的错误。重现此错误的最少代码:
#!/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')
堆栈跟踪如下:
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
如果我注释掉 set_yscale('log') 它运行良好。有谁知道为什么这种转换不起作用?
【问题讨论】:
-
注意:同样的问题在 matplotlib 1.4.2 中仍然存在。
-
进一步更新:这对我来说就像一个错误,I opened an issue in the github repo
标签: python-3.x matplotlib