@@ -78,7 +78,7 @@ def __eq__(self,
7878 Returns
7979 -------
8080 eq : bool
81- Wheter self equals other.
81+ Whether self equals other.
8282 """
8383 if not isinstance (other , Colormap ):
8484 return NotImplemented
@@ -504,27 +504,71 @@ def _interpolate_msh(frac: float,
504504
505505 This interpolation gives a perceptually uniform colormap.
506506
507+ Parameters
508+ ----------
509+ frac : float
510+ Location at the colormap in a range [0,1].
511+ low : numpy.ndarray, shape (3)
512+ Color in Msh for the low end of the colormap.
513+ high : numpy.ndarray, shape (3)
514+ Color in Msh for the high end of the colormap.
515+
516+ Returns
517+ -------
518+ color : numpy.ndarray, shape (3)
519+ Color in Msh at frac between low and high.
520+
507521 References
508522 ----------
509523 | https://www.kennethmoreland.com/color-maps/ColorMapsExpanded.pdf
510524 | https://www.kennethmoreland.com/color-maps/diverging_map.py
511525 """
512- def rad_diff (a ,b ):
513- return abs (a [2 ]- b [2 ])
514-
515- def adjust_hue (msh_sat , msh_unsat ):
516- """If saturation of one of the two colors is much less than the other, hue of the less."""
517- if msh_sat [0 ] >= msh_unsat [0 ]:
526+ def rad_diff (h_1 ,h_2 ):
527+ """
528+ Compute angular difference between two hue orientations.
529+
530+ Parameters
531+ ----------
532+ h_1 : float
533+ First hue orientation.
534+ h_2 : float
535+ Second hue orientation.
536+
537+ Returns
538+ -------
539+ d : float
540+ Angular difference between given hue orientations.
541+ """
542+ d = abs (h_1 - h_2 )% (2 * np .pi )
543+ return min (d ,2 * np .pi - d )
544+
545+ def adjust_hue (msh_sat , m_unsat ):
546+ """
547+ Provide adjusted hue when interpolating to an unsaturated color.
548+
549+ Parameters
550+ ----------
551+ msh_sat : numpy.ndarray, shape(3)
552+ Saturated color in Msh space.
553+ m_unsat : float
554+ Magnitue (in Msh space) of unsaturated color.
555+
556+ Returns
557+ -------
558+ h_adjusted : float
559+ Adjusted hue.
560+ """
561+ if msh_sat [0 ] >= m_unsat :
518562 return msh_sat [2 ]
519563
520- hSpin = msh_sat [1 ]/ np .sin (msh_sat [1 ])* np .sqrt (msh_unsat [ 0 ] ** 2.0 - msh_sat [0 ]** 2 )/ msh_sat [0 ]
564+ hSpin = msh_sat [1 ]/ np .sin (msh_sat [1 ])* np .sqrt (m_unsat ** 2.0 - msh_sat [0 ]** 2 )/ msh_sat [0 ]
521565 if msh_sat [2 ] < - np .pi / 3.0 : hSpin *= - 1.0
522566 return msh_sat [2 ] + hSpin
523567
524568 lo = np .array (low )
525569 hi = np .array (high )
526570
527- if (lo [1 ] > 0.05 and hi [1 ] > 0.05 and rad_diff (lo ,hi ) > np .pi / 3.0 ):
571+ if (lo [1 ] > 0.05 and hi [1 ] > 0.05 and rad_diff (lo [ 2 ] ,hi [ 2 ] ) > np .pi / 3.0 ):
528572 M_mid = max (lo [0 ],hi [0 ],88.0 )
529573 if frac < 0.5 :
530574 hi = np .array ([M_mid ,0.0 ,0.0 ])
@@ -533,9 +577,9 @@ def adjust_hue(msh_sat, msh_unsat):
533577 lo = np .array ([M_mid ,0.0 ,0.0 ])
534578 frac = 2.0 * frac - 1.0
535579 if lo [1 ] < 0.05 < hi [1 ]:
536- lo [2 ] = adjust_hue (hi ,lo )
580+ lo [2 ] = adjust_hue (hi ,lo [ 0 ] )
537581 elif hi [1 ] < 0.05 < lo [1 ]:
538- hi [2 ] = adjust_hue (lo ,hi )
582+ hi [2 ] = adjust_hue (lo ,hi [ 0 ] )
539583
540584 return (1.0 - frac ) * lo + frac * hi
541585
0 commit comments