| 
     
      
      
      From: Eric F. <ef...@ha...> - 2006-05-27 17:09:06
      
     
   | 
Darren, Thanks. I expect that a slight modification of your patch will fit in perfectly with what I have in mind, and it is particularly helpful because I know next to zip about svg--and about most of the other backend output formats. I think you misunderstood what I was suggesting; it was not that alpha would be zero in the svg output, but rather that the backend would use alpha==0 in the line color (or gc.alpha) as a flag to not output the stroke command, in the same way as I started using linewidth for this. In the same way, alpha==0 in the facecolor would turn off output of the fill command. So, even if you start with svg and then go to postscript, the result should be correct. It is all a little kludgy. Some things use rgb, some use rgba; some alpha values are ignored completely. The GraphicsContextBase has alpha but GraphicsContextPS does not. The gc seems to have *almost* all the information that gets passed down to the lowest-level renderer functions, but lacks the face color; etc. A more thorough rewrite could clean up a lot of things, but as John noted it would require simultaneously modifying the entire set of backends. Instead, my intention is to make small changes that move towards a greater degree of consistency but without breaking anything. This does not preclude a more extensive refactoring in the future; if anything, it should facilitate it. Eric Darren Dale wrote: > On Saturday 27 May 2006 09:06, Darren Dale wrote: > >>On Saturday 27 May 2006 04:29, Eric Firing wrote: >> >>>Darren noticed that because of the edge-drawing problem, ps and svg >>>backends were making unusable colorbars for image-type plots, so I put a >>>quick hack into the ps backend to make it work until the more general >>>solution is put into place. >> >>Thank you for doing that. I need to use the svg backend to make plots for >>my poster. I was thinking about how to change the svg backend, and setting >>the alpha to zero may create a problem. For example, I create an svg file >>with mpl, and import it into inkscape. Then I print the document to my >>postscript printer, which does not support alpha, and therefore some >>unexpected lines show up on the printed page. Its a corner case, but I bet >>a fair number of people will get nailed by it. > > > Here's a hack that works for me: > > $ svn diff > Index: lib/matplotlib/backends/backend_svg.py > =================================================================== > --- lib/matplotlib/backends/backend_svg.py (revision 2417) > +++ lib/matplotlib/backends/backend_svg.py (working copy) > @@ -71,20 +71,25 @@ > else: > dashes = 'stroke-dasharray: %s; stroke-dashoffset: %f;' % ( > ' '.join(['%f'%val for val in seq]), offset) > + > + linewidth = gc.get_linewidth() > + if linewidth: > + return 'style="fill: %s; stroke: %s; stroke-width: %f; ' \ > + 'stroke-linejoin: %s; stroke-linecap: %s; %s opacity: %f; ' \ > + '%s"' % (fill, > + rgb2hex(gc.get_rgb()), > + linewidth, > + gc.get_joinstyle(), > + _capstyle_d[gc.get_capstyle()], > + dashes, > + gc.get_alpha(), > + clippath,) > + else: > + return 'style="fill: %s; opacity: %f; ' \ > + '%s"' % (fill, > + gc.get_alpha(), > + clippath,) > > - return 'style="fill: %s; stroke: %s; stroke-width: %f; ' \ > - 'stroke-linejoin: %s; stroke-linecap: %s; %s opacity: %f; ' \ > - '%s"' % ( > - fill, > - rgb2hex(gc.get_rgb()), > - gc.get_linewidth(), > - gc.get_joinstyle(), > - _capstyle_d[gc.get_capstyle()], > - dashes, > - gc.get_alpha(), > - clippath, > - ) > - > def _get_gc_clip_svg(self, gc): > cliprect = gc.get_clip_rectangle() > if cliprect is None: > @@ -144,10 +149,10 @@ > y = self.height-y-h > im.write_png(filename) > > - imfile = file (filename, 'r') > - image64 = base64.b64encode (imfile.read()) > - imfile.close() > - os.remove(filename) > + imfile = file (filename, 'r') > + image64 = base64.b64encode (imfile.read()) > + imfile.close() > + os.remove(filename) > lines = [image64[i:i+76] for i in range(0, len(image64), 76)] > > self._svgwriter.write ( > > > ------------------------------------------------------- > All the advantages of Linux Managed Hosting--Without the Cost and Risk! > Fully trained technicians. The highest number of Red Hat certifications in > the hosting industry. Fanatical Support. Click to learn more > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642 > _______________________________________________ > Matplotlib-devel mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel  |