## [PyX-devel] HSB trouble

 [PyX-devel] HSB trouble From: Michael J Gruber - 2011-04-07 14:39:16 Attachments: hsb.py     hsb.png ```Heya, 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.) There seems to be a problem around param = 0 or 1, though. The following should be true for small eps (0 < eps < 1./6): hsb( eps, 1, 1).rgb() == rgb(1, 6*eps, 0) hsb(1-eps, 1, 1).rgb() == rgb(1, 0, 6*eps) And I don't think pyx.color is failing me here, but just look at the phase plot of f(z)=z: Weird stuff happening along the negative real axis where, admittedly, cmath.phase(z) jumps, but everything looks nice with other gradients, and hsb sprinkles in "positive real color" all over the negative real axis. What is going on? Michael ```

 [PyX-devel] HSB trouble From: Michael J Gruber - 2011-04-07 14:39:16 Attachments: hsb.py     hsb.png ```Heya, 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.) There seems to be a problem around param = 0 or 1, though. The following should be true for small eps (0 < eps < 1./6): hsb( eps, 1, 1).rgb() == rgb(1, 6*eps, 0) hsb(1-eps, 1, 1).rgb() == rgb(1, 0, 6*eps) And I don't think pyx.color is failing me here, but just look at the phase plot of f(z)=z: Weird stuff happening along the negative real axis where, admittedly, cmath.phase(z) jumps, but everything looks nice with other gradients, and hsb sprinkles in "positive real color" all over the negative real axis. What is going on? Michael ```
 Re: [PyX-devel] HSB trouble From: Michael J Gruber - 2011-04-08 08:12:35 ```André Wobst venit, vidit, dixit 07.04.2011 23:03: > 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. Thanks for the perfect explanation. I didn't know that pyx computes midpoints between the color parameters, not the colors. (And it seemed to work with linear rgb gradients.) Just yesterday I was teaching my students about arg(zw) not always being arg(z)+arg(w)... Thanks also for the working code. I had to remember to use it with pyx@... (later than v0.10), though, and noticed 2 typos in the warnings ("gradiend" should be "gradient" no matter how soft it is). But that's not impordand :) > PS: This whole thread could have posted to pyx-user as well, but I > don't mind. Sorry, it looked like a pyx problem, while it was an mjg problem... Michael ```