From: Alex G. <gs...@cs...> - 2005-11-21 07:59:09
Attachments:
matplotlib.diff
|
Currently implemented for PostScript backend only - the rest ignore the command. I tried to make it in the same style as the rest of Matplotlib iface: 'x' does bidiagonal hatching '/' does diagonal, '-' does horizontal, and so on. Repeating the hatching symbol increases the density of hatching. Attached is the diff for version 0.85. Is there a chance for this thing to be included into the source? |
From: John H. <jdh...@ac...> - 2005-11-30 22:42:10
|
>>>>> "Alex" == Alex Gontmakher <gs...@cs...> writes: Alex> Currently implemented for PostScript backend only - the rest Alex> ignore the command. I tried to make it in the same style as Alex> the rest of Matplotlib iface: 'x' does bidiagonal hatching Alex> '/' does diagonal, '-' does horizontal, and so on. Alex> Repeating the hatching symbol increases the density of Alex> hatching. Alex> Attached is the diff for version 0.85. Is there a chance Alex> for this thing to be included into the source? Thanks Alex -- I'm happy to include this but am having trouble applying your patch. Could you get a fresh CVS checkout, reapply your changes, and do a 'cvs diff'? Thanks, JDH Alex> Only in matplotlib-0.85.new: build diff -r Alex> matplotlib-0.85/lib/matplotlib/backend_bases.py Alex> matplotlib-0.85.new/lib/matplotlib/backend_bases.py 389a390 >> self._hatch = None Alex> 401a403 >> self._hatch = gc._hatch Alex> 549c551,558 < --- >> def set_hatch(self, hatch): """ Sets the hatch style for >> filling """ self._hatch = hatch def get_hatch(self): return >> self._hatch Alex> Only in matplotlib-0.85.new/lib/matplotlib: Alex> backend_bases.py~ diff -r Alex> matplotlib-0.85/lib/matplotlib/backends/backend_ps.py Alex> matplotlib-0.85.new/lib/matplotlib/backends/backend_ps.py Alex> 148a149,150 >> self.hatch = None self.hatch_func = False Alex> 195a198,260 >> def set_hatch(self, hatch): """ hatch can be one of: / - >> diagonal hatching \ - back diagonal | - vertical - - horizontal >> # - crossed X - crossed diagonal letters can be combined, in >> which case all the specified hatchings are done if same letter >> repeats, it increases the density of hatching in that direction >> """ hatches = {'horiz':0, 'vert':0, 'diag1':0, 'diag2':0} >> >> for letter in hatch: if (letter == '/'): hatches['diag2'] += 1 >> elif (letter == '\\'): hatches['diag1'] += 1 elif (letter == >> '|'): hatches['vert'] += 1 elif (letter == '-'): >> hatches['horiz'] += 1 elif (letter == '+'): hatches['horiz'] += >> 1 hatches['vert'] += 1 elif (letter == 'x'): hatches['diag1'] >> += 1 hatches['diag2'] += 1 >> >> def do_hatch(angle, density): if (density == 0): return "" orig >> = """ gsave eoclip %s rotate 0.0 0.0 0.0 0.0 setrgbcolor 0 >> setlinewidth /gap %d def pathbbox /b exch def /r exch def /t >> exch def /l exch def l cvi gap idiv gap mul gap r cvi gap idiv >> gap mul {t moveto 0 b t sub rlineto} for stroke grestore """ % >> (angle, 12/density) return """ gsave eoclip %s rotate 0.0 0.0 >> 0.0 0.0 setrgbcolor 0 setlinewidth /hatchgap %d def pathbbox >> /hatchb exch def /hatchr exch def /hatcht exch def /hatchl exch >> def hatchl cvi hatchgap idiv hatchgap mul hatchgap hatchr cvi >> hatchgap idiv hatchgap mul {hatcht moveto 0 hatchb hatcht sub >> rlineto} for stroke grestore """ % (angle, 12/density) >> self._pswriter.write("gsave\n") >> self._pswriter.write(do_hatch(0, hatches['horiz'])) >> self._pswriter.write(do_hatch(90, hatches['vert'])) >> self._pswriter.write(do_hatch(45, hatches['diag1'])) >> self._pswriter.write(do_hatch(-45, hatches['diag2'])) >> self._pswriter.write("grestore\n") >> Alex> 771,772c836,837 < write(ps.strip()) < write("\n") --- >> write(ps.strip()) write("\n") Alex> 778a844,847 >> hatch = gc.get_hatch() if (hatch): self.set_hatch(hatch) >> Alex> Only in matplotlib-0.85.new/lib/matplotlib/backends: Alex> backend_ps.py~ diff -r Alex> matplotlib-0.85/lib/matplotlib/patches.py Alex> matplotlib-0.85.new/lib/matplotlib/patches.py 30a31 >> hatch = None, Alex> 44a46 >> self.hatch = hatch Alex> 53a56 >> self.set_hatch(other.get_hatch()) Alex> 114a118,128 >> def set_hatch(self, h): """ Set the hatching pattern >> >> ACCEPTS: string (can be one of "|,/,\,x,+", or combinations >> thereof") """ self.hatch = h >> >> def get_hatch(self): 'return the current hatch pattern' return >> self.hatch Alex> 127a142,143 >> if self.hatch != None: gc.set_hatch(self.hatch) Alex> Only in matplotlib-0.85.new/lib/matplotlib: patches.py~ Only Alex> in matplotlib-0.85.new: setupext.pyc Only in Alex> matplotlib-0.85/src: _na_backend_agg.cpp Only in Alex> matplotlib-0.85/src: _na_backend_gdk.c Only in Alex> matplotlib-0.85/src: _na_cntr.c Only in matplotlib-0.85/src: Alex> _na_image.cpp Only in matplotlib-0.85/src: Alex> _na_transforms.cpp Only in matplotlib-0.85/src: Alex> _nc_backend_agg.cpp Only in matplotlib-0.85/src: Alex> _nc_backend_gdk.c Only in matplotlib-0.85/src: _nc_cntr.c Alex> Only in matplotlib-0.85/src: _nc_image.cpp Only in Alex> matplotlib-0.85/src: _nc_transforms.cpp |