cplot icon indicating copy to clipboard operation
cplot copied to clipboard

Feature request: Adjustable phase offset

Open jagerber48 opened this issue 11 months ago • 3 comments

Right now cplot has made the decision that a complex phase of zero (pi) corresponds to green (purple) hue. Another obvious choice is for a complex phase of zero (pi) corresponds to red (cyan) hue. I would prefer the latter. It would be nice if I could choose between these two conventions. More generally I could just pass an arbitrary phase so I can rotate the color-wheel to my liking.

I'm actually curious where the choice of zero phase -> green hue comes from? The choice of zero phase -> red hue comes from my understanding that a "hue" of zero corresponds to red. Maybe there is some driving factor for choosing zero phase -> green?

I can work around this by multiply my function f by exp(-1j*2*np.pi/3). This gets the domain color plot to look right, the but the colorbar in the legend for the phase is still "clocked" wrong.

jagerber48 avatar Jan 02 '25 16:01 jagerber48

Hi Justin,

I'm actually curious where the choice of zero phase -> green hue comes from?

We did a little survey asking people if they associate red with positive and green with negative or rather the other way around. Almost everyone voted red=negative, green=positive. Might be because of the traffic light association, or the general notion that green means "good".

The choice of zero phase -> red hue comes from my understanding that a "hue" of zero corresponds to red.

Where does this understanding come from?

nschloe avatar Jan 02 '25 19:01 nschloe

Hi Nico, thank you very much for your response. Interesting to know you did a small survey.

Where does this understanding come from?

Two places. that are possibly the same root source:

  1. It seems to be commonly defined that a hue of 0 corresponds to red. That means if you directly map hue = (np.angle(number) % (2*np.pi)) / (2*np.pi) then a positive real number (zero complex part, zero phase angle) it will be mapped to red. I've seen this convention on all the Wikipedia pages about color like Hue or HSL and HSV and others. Also on the page for Domain Coloring we see that getting zero phase to show up as green requires explicitly adding a phase of 2*np.pi/3 to arg(z). I suspect that you yourself actually wrote this line. So in all of these cases the "natural" thing to do if you're just copying the conventional hue phase is to have zero phase be red.

  2. The first place I was introduced to anything like "domain coloring" was for visualizing chemistry orbitals. I was first introduced to the "real" version of chemistry orbitals in which all lobes are positive or negative. In many examples (including the better done ones) the positive lobes were red and the negative ones were blue. This isn't unanimous across references, but it does appear quite often. We see the red/blue convention here. Of course elsewhere on that page you see many other conventions.

In any case, users might want to make plots copying things they see online following different conventions. Adding an adjustable phase offset in this package would make that easier. Or at least a Boolean switch to the zero phase = red convention.

For what it's worth, I wrote a python app for visualizing complex or real (basically the colors correspond to complex or real/imag parts of the spherical harmonics)hydrogen-like atomic orbitals using domain coloring together with some 3D function visualization techniques. For that I followed zero phase = red convention and I got very used to looking at things that way. I had "invented" the basic idea of the cmap package many times myself before just looking it. cmap does it way better than I ever did so I'm excited to use it, but it's annoying to have to learn the new phase convention (and it doesn't look as good to my eye). During that work I generated these plots on table of spherical harmonics. Of course these references aren't authoritative, it's just what I chose based on stuff I saw, but I'm sharing because it is moreso the personal reason I posted to you about it.

jagerber48 avatar Jan 02 '25 21:01 jagerber48

Note the example further down the domain coloring page already uses the zero phase = red convention, in conflict with the formulas appearing in the text of that page. This just shows that it will be impossible for one phase convention to dominate and allowing multiple conventions could be useful.

jagerber48 avatar Jan 02 '25 22:01 jagerber48