[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: André Wobst - 2011-04-07 21:40:35 Attachments: smime.p7s hsb.py ```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 / \ \ / ) wobsta@..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/ ```
 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 ```