"No such attribute" error with PDF output

Given the following matplotlib program:

···

##
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(3)
width = 0.35
hdfs = (292.97, 304.49, 305.47)
bfs = (614.57, 706.02, 847.44)

plt.subplot(111)
hdfs_rects = plt.bar(x, hdfs, width, color='b')
bfs_rects = plt.bar(x + width, bfs, width, color='g', hatch='/')

plt.xticks(x + width, ('100 ls ops', '100 touch ops', '100 0k copy ops'))
plt.ylabel('Time (sec)')
plt.title('Metadata Performance')
plt.legend((hdfs_rects[0], bfs_rects[0]), ('HDFS', 'BoomFS'), loc='upper right')
plt.ylim([0, 1200])
plt.savefig('metadata_throughput.pdf')
##

I see the following error using matplotlib 0.95.1:

Traceback (most recent call last):
  File "metadata_throughput.py", line 21, in <module>
    plt.savefig('metadata_throughput.pdf')
  File "/opt/local/lib/python2.5/site-packages/matplotlib/pyplot.py",
line 345, in savefig
    return fig.savefig(*args, **kwargs)
  File "/opt/local/lib/python2.5/site-packages/matplotlib/figure.py",
line 990, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backend_bases.py",
line 1419, in print_figure
    **kwargs)
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backend_bases.py",
line 1313, in print_pdf
    return pdf.print_pdf(*args, **kwargs)
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_pdf.py",
line 1883, in print_pdf
    self.figure.draw(renderer)
  File "/opt/local/lib/python2.5/site-packages/matplotlib/figure.py",
line 772, in draw
    for a in self.axes: a.draw(renderer)
  File "/opt/local/lib/python2.5/site-packages/matplotlib/axes.py",
line 1601, in draw
    a.draw(renderer)
  File "/opt/local/lib/python2.5/site-packages/matplotlib/patches.py",
line 301, in draw
    renderer.draw_path(gc, tpath, affine, rgbFace)
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_pdf.py",
line 1248, in draw_path
    self.check_gc(gc, rgbFace)
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_pdf.py",
line 1203, in check_gc
    delta = self.gc.delta(gc)
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_pdf.py",
line 1813, in delta
    cmds.extend(cmd(self, *theirs))
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_pdf.py",
line 1725, in hatch_cmd
    name = self.file.hatchPattern(lst)
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_pdf.py",
line 945, in hatchPattern
    return pattern[0]
AttributeError: Name instance has no attribute '__getitem__'

If I change the savefig() call to emit EPS or PNG instead, e.g:

plt.savefig('metadata_throughput.eps')

The program works fine, and I get the output I'd expect. Does anyone
have any suggestions about what's going wrong here?

Thanks in advance,

Neil

Sorry: that should be 0.98.5.1.

Neil

···

On Sat, Dec 20, 2008 at 1:32 AM, Neil Conway <nrc@...2426...> wrote:

I see the following error using matplotlib 0.95.1:

It seems as a bug in the pdf backend, which can be fixed by the simple
patch below. I didn't commit this fix as I think it would be better if
original author (Jouni?) make sure this is a correct way. Neil, your
code will work okay if you don't use hatch. Or, you may apply the
patch by yourself.

-JJ

ps. I didn't know that hatch is supported in pdf backend. The
documentation needs update.

http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.patches.Patch.set_hatch

Index: lib/matplotlib/backends/backend_pdf.py

···

===================================================================
--- lib/matplotlib/backends/backend_pdf.py (revision 6687)
+++ lib/matplotlib/backends/backend_pdf.py (working copy)
@@ -942,4 +942,4 @@
     def hatchPattern(self, lst):
         pattern = self.hatchPatterns.get(lst, None)
         if pattern is not None:
- return pattern[0]
+ return pattern

         name = Name('H%d' % self.nextHatch)
         self.nextHatch += 1

On Sat, Dec 20, 2008 at 2:02 AM, Neil Conway <nrc@...2426...> wrote:

On Sat, Dec 20, 2008 at 1:32 AM, Neil Conway <nrc@...2426...> wrote:

I see the following error using matplotlib 0.95.1:

Sorry: that should be 0.98.5.1.

Neil

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options