Hi Michael, Am 07.04.2011 um 18:38 schrieb Michael J Gruber: > I'm trying to make color graphs of complex functions but seem to have > problems with hsb gradients. (I want to use an hsb gradient in order to > map arguments/phases of complex numbers to something periodic, such as > the meaning of h in hsb.)
The periodicity is the problem in combination with the calculation of an mid point by the surface style. (And the addition of a middle point in the surface style is required for its typical use case, namely 3d plots, where you need to have planes for each mesh triangle. You can't use rectangles for that case, although they are available in PostScript and PDF. Supporting a different mesh type could be a solution in 2d, but is not programmed.) You need to replace the midcolor calculation to handle your periodicity. Fortunately it is possible (and trivial) to hook into this calculation. Please see the updated version of your example. The problem at the zero point is different. You may finally decide to just ignore it. (I really think this is a suitable solution.) Or you may want to fix it. Which means you can't draw a continuous surface. The problem is, that the color is discontinuous at this point. You could simply skip the point (or the gird point closest to this singularity) in your data. Fortunately PyX understands the situation and properly draws all the rest just skipping this region. While it would be nicer to have a very small circle (hole) drawn at the singularity, this goes beyond the simple rectangular surface functionality of PyX. You will need to start coding that case yourself (and you will immediately see that it will become a quite special purpose code, which is absolutely fine, but goes beyond what can be provided by plain PyX). André PS: This whole thread could have posted to pyx-user as well, but I don't mind. -- by _ _ _ Dr. André Wobst, Amselweg 22, 85716 Unterschleißheim / \ \ / ) [email protected], http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/
from pyx import *
import math,cmath
class mysurface(graph.style.surface):
def midcolor(self, c1, c2, c3, c4):
return cmath.phase(sum(cmath.rect(1, c) for c in [c1, c2, c3, c4]))
N=8
class FullSaturationCCW(color.gradient):
def __init__(self):
self.colorclass = color.rgb
def getcolor(self, param):
return color.gradient.Hue.getcolor(param).rgb()
g = graph.graphxy(width = 8, height = 8)
xs = [ (2.0*i/N) for i in range(-N, N+1) ]
ys = xs[:]
pointlist = [ [x, y, cmath.phase(x+1j*y)] for x in xs for y in ys if abs(x)+abs(y) > 1e-10]
g.plot(graph.data.points(pointlist, x=1, y=2, color=3), [mysurface(gradient=FullSaturationCCW(), mincolor=-math.pi,maxcolor=math.pi,backcolor=color.rgb.black)])
g.writeEPSfile(__file__[:-3])
g.writePDFfile(__file__[:-3])
smime.p7s
Description: S/MIME cryptographic signature
------------------------------------------------------------------------------ Xperia(TM) PLAY It's a major breakthrough. An authentic gaming smartphone on the nation's most reliable network. And it wants your games. http://p.sf.net/sfu/verizon-sfdev
_______________________________________________ PyX-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pyx-devel
