From: Carol L. <car...@sr...> - 2004-12-01 00:06:11
|
I am trying to overlay a polar grid on a previously plotted axis. The plot looks fine on the screen and in a png file. However, I get an error message when making a postscript file. Basically, I drew one set of axes in rectangular coordinates and then tried to overlay a polar grid with: # Save current axes ax = gca() l, b, w, h = ax.get_position() # Normalized axp = axes([l, b, w, h], polar=True, frameon=False) theta = arange(0,1,0.001) * 2*2*pi r = array([1.0 for i in range(len(theta))]) polar(theta, r, color='k') angles = arange(0,360,45) labels = ('','NE','','NW','','SW', '','SE' '') thetalines, thetatext = thetagrids(angles, labels) # Restore previous axes axes(ax) I am using a version of the CVS code that I downloaded today, Nov. 30, 2004. I have source code I could send, but I doubt you want an attachment sent to the list. Here are the messages that appear: File "testoverlay.py", line 90, in ? savefig('overlay.ps') File "/usr/lib/python2.3/site-packages/matplotlib/matlab.py", line 1008, in savefig manager.canvas.print_figure(*args, **kwargs) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_gtkagg.py", line 66, in print_figure agg.print_figure(filename, dpi, facecolor, edgecolor, orientation) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_agg.py", line 385, in print_figure ps.print_figure(filename, dpi, facecolor, edgecolor, orientation) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_ps.py", line 570, in print_figure self.figure.draw(renderer) File "/usr/lib/python2.3/site-packages/matplotlib/figure.py", line 254, in draw for a in self.axes: a.draw(renderer) File "/usr/lib/python2.3/site-packages/matplotlib/axes.py", line 3125, in draw l.draw(renderer) File "/usr/lib/python2.3/site-packages/matplotlib/lines.py", line 257, in draw lineFunc(renderer, gc, xt, yt) File "/usr/lib/python2.3/site-packages/matplotlib/lines.py", line 513, in _draw_dotted renderer.draw_lines(gc, xt, yt) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_ps.py", line 275, in draw_lines self._draw_lines(gc,points[0:1000]) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_ps.py", line 264, in _draw_lines self._draw_ps("\n".join(ps), gc, None) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_ps.py", line 375, in _draw_ps self.set_linedash(*gc.get_dashes()) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_ps.py", line 103, in set_linedash if seq: File "/usr/lib/python2.3/site-packages/numarray/generic.py", line 477, in __nonzero__ raise RuntimeError("An array doesn't make sense as a truth value. Use sometrue(a) or alltrue(a).") RuntimeError: An array doesn't make sense as a truth value. Use sometrue(a) or alltrue(a). -- Ms. Carol A. Leger SRI International Phone: (650) 859-4114 333 Ravenswood Avenue G-273 Menlo Park, CA 94025 e-mail: le...@sr... |
From: Carol L. <car...@sr...> - 2004-12-01 17:19:59
|
> Yep, this is a bug. In backend_ps in the the set_linedashes function > on line 103, replace the line > > if seq: > > with > > if seq is not None and len(seq): > > My guess is you are using numarray, and if memory serves numarray but > not Numeric fails on using an array as a boolean, which is what > backend ps is doing here. > > Yes, I am using numarray. I made the change to line 103 and now line 102 is reporting a similar error. Traceback (most recent call last): File "testoverlay.py", line 91, in ? savefig('overlay.ps') File "/usr/lib/python2.3/site-packages/matplotlib/matlab.py", line 1008, in savefig manager.canvas.print_figure(*args, **kwargs) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_gtkagg.py", line 66, in print_figure agg.print_figure(filename, dpi, facecolor, edgecolor, orientation) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_agg.py", line 385, in print_figure ps.print_figure(filename, dpi, facecolor, edgecolor, orientation) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_ps.py", line 570, in print_figure self.figure.draw(renderer) File "/usr/lib/python2.3/site-packages/matplotlib/figure.py", line 254, in draw for a in self.axes: a.draw(renderer) File "/usr/lib/python2.3/site-packages/matplotlib/axes.py", line 3125, in draw l.draw(renderer) File "/usr/lib/python2.3/site-packages/matplotlib/lines.py", line 257, in draw lineFunc(renderer, gc, xt, yt) File "/usr/lib/python2.3/site-packages/matplotlib/lines.py", line 513, in _draw_dotted renderer.draw_lines(gc, xt, yt) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_ps.py", line 275, in draw_lines self._draw_lines(gc,points[0:1000]) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_ps.py", line 264, in _draw_lines self._draw_ps("\n".join(ps), gc, None) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_ps.py", line 375, in _draw_ps self.set_linedash(*gc.get_dashes()) File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_ps.py", line 102, in set_linedash if (offset,seq) != self.linedash: File "/usr/lib/python2.3/site-packages/numarray/generic.py", line 477, in __nonzero__ raise RuntimeError("An array doesn't make sense as a truth value. Use sometrue(a) or alltrue(a).") RuntimeError: An array doesn't make sense as a truth value. Use sometrue(a) or alltrue(a). -- Ms. Carol A. Leger SRI International Phone: (650) 859-4114 333 Ravenswood Avenue G-273 Menlo Park, CA 94025 e-mail: le...@sr... |
From: John H. <jdh...@ac...> - 2004-12-01 21:21:44
|
>>>>> "Carol" == Carol Leger <car...@sr...> writes: >> Yep, this is a bug. In backend_ps in the the set_linedashes >> function on line 103, replace the line if seq: with if seq is >> not None and len(seq): My guess is you are using numarray, and >> if memory serves numarray but not Numeric fails on using an >> array as a boolean, which is what backend ps is doing here. >> Carol> Yes, I am using numarray. I made the change to line 103 Carol> and now line 102 is reporting a similar error. Sorry for all the troubles here. Try this function for set_linedash in backend_ps def set_linedash(self, offset, seq): if self.linedash is not None: oldo, oldseq = self.linedash if offset==oldo and seq==oldseq: return if seq is not None and len(seq): s="[%s] %d setdash\n"%(_nums_to_str(*seq), offset) self._pswriter.write(s) else: self._pswriter.write("[] 0 setdash\n") self.linedash = (offset,seq) |
From: John H. <jdh...@ac...> - 2004-12-01 22:07:15
|
>>>>> "Carol" == Carol Leger <car...@sr...> writes: >> Yep, this is a bug. In backend_ps in the the set_linedashes >> function on line 103, replace the line if seq: with if seq is >> not None and len(seq): My guess is you are using numarray, and >> if memory serves numarray but not Numeric fails on using an >> array as a boolean, which is what backend ps is doing here. >> Carol> Yes, I am using numarray. I made the change to line 103 Carol> and now line 102 is reporting a similar error. Ignore my last post - the solution I posted was as buggy as before. I think I finally nailed this down. Basically, we are comparing seq1 and seq2, either are possibly None, or general sequences, or arrays. I wrote a little function def seq_allequal(seq1, seq2): """ seq1 and seq2 are either None or sequences or numerix arrays Return True if both are None or both are seqs with identical elements """ if seq1 is None: return seq2 is None if seq2 is None: return False #ok, neither are None:, assuming iterable if len(seq1) != len(seq2): return False return alltrue(equal(seq1, seq2)) You should import alltrue and equal from the numerix module at the top of backend_ps, add this function to backend_ps and then replace set_linedash with def set_linedash(self, offset, seq): if self.linedash is not None: oldo, oldseq = self.linedash if seq_allequal(seq, oldseq): return if seq is not None and len(seq): s="[%s] %d setdash\n"%(_nums_to_str(*seq), offset) self._pswriter.write(s) else: self._pswriter.write("[] 0 setdash\n") self.linedash = (offset,seq) I think this is finally coherent. At least it passes my tests now... JDH |
From: Carol L. <car...@sr...> - 2004-12-02 00:50:37
|
The that the polar plot overlayed on a rectangular plot is working in Postscipt, I am having trouble with the semi-transparent boxes around the text. The png file looks fine, but the postcript file does not show the differences in the alpha value. Since the code is short, I'll supply it here: #!/usr/bin python from matplotlib.matlab import * def OverlayText(xmax): x=0 y = 0.65*xmax ystep = 0.2*xmax alpha = arange(0.0,1.2,0.2) for a in alpha: stext = 'Alpha = %.1f' % a t = text(x,y,stext) set(t,bbox={'edgecolor':'w','facecolor':'w','alpha':a}) y = y - ystep if __name__ == "__main__": # Make some kind of plot xmin = -750 xmax = 750 ymin = xmin ymax = xmax x = [xmin,xmax,xmax,xmin] y = [ymin,ymin,ymax,ymax] fill(x,y,'g',edgecolor='b') a = gca() a.set_xlim([xmin,xmax]) a.set_ylim([ymin,ymax]) OverlayText(xmax) savefig('overlay2.png') savefig('overlay2.ps') show() -- Ms. Carol A. Leger SRI International Phone: (650) 859-4114 333 Ravenswood Avenue G-273 Menlo Park, CA 94025 e-mail: le...@sr... |
From: John H. <jdh...@ac...> - 2004-12-02 12:27:37
|
>>>>> "Carol" == Carol Leger <car...@sr...> writes: Carol> The that the polar plot overlayed on a rectangular plot is Carol> working in Postscipt, I am having trouble with the Carol> semi-transparent boxes around the text. postscript doesn't support the alpha channel and there is nothing matplotlib can do about it. It's a postscript limitation. Right now the only vector output that supports alpha is SVG. Hopefully we'll get a PDF backend one day which also supports alpha. JDH |
From: Norbert N. <No...@ne...> - 2004-12-02 14:16:37
|
True. Just had to check this again to make sure, but even PS3 does not support Alpha transparency in any way. The big improvement there was bitmapped masking of images, but the whole concept of true transparency really seems to be an extremely new idea. Am Donnerstag, 2. Dezember 2004 13:26 schrieb John Hunter: > >>>>> "Carol" == Carol Leger <car...@sr...> writes: > > Carol> The that the polar plot overlayed on a rectangular plot is > Carol> working in Postscipt, I am having trouble with the > Carol> semi-transparent boxes around the text. > > postscript doesn't support the alpha channel and there is nothing > matplotlib can do about it. It's a postscript limitation. Right now > the only vector output that supports alpha is SVG. Hopefully we'll > get a PDF backend one day which also supports alpha. > > JDH > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://productguide.itmanagersjournal.com/ > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- _________________________________________Norbert Nemec Bernhardstr. 2 ... D-93053 Regensburg Tel: 0941 - 2009638 ... Mobil: 0179 - 7475199 eMail: <No...@Ne...> |
From: John H. <jdh...@ac...> - 2004-12-01 03:26:09
|
>>>>> "Carol" == Carol Leger <car...@sr...> writes: Carol> I am trying to overlay a polar grid on a previously plotted Carol> axis. The plot looks fine on the screen and in a png file. Carol> However, I get an error message when making a postscript Carol> file. Yep, this is a bug. In backend_ps in the the set_linedashes function on line 103, replace the line if seq: with if seq is not None and len(seq): My guess is you are using numarray, and if memory serves numarray but not Numeric fails on using an array as a boolean, which is what backend ps is doing here. Overlaying a polar plot over a rectangular axes. Man, what will they think of next!? You will send me the screenshot when you're done, right? JDH |