@@ -71,7 +71,7 @@ def compute_over_grid(nx, ny):
7171 if not is_complex :
7272 zs = function (** {str (names [0 ]): xs , str (names [1 ]): ys })
7373 else :
74- cs = xs + ys * 1j # TODO: fast enough?
74+ cs = xs + ys * 1j # TODO: fast enough?
7575 zs = function (** {str (names [0 ]): cs })
7676
7777 # sometimes expr gets compiled into something that returns a complex
@@ -103,7 +103,6 @@ def compute_over_grid(nx, ny):
103103 # pass the xyzs and quads back to the caller to add colors and emit quads as appropriate
104104 emit (graphics , i , xyzs , quads )
105105
106-
107106 # If requested by the Mesh attribute create a mesh of lines covering the surfaces
108107 # For now only for Plot3D
109108 # TODO: mesh for DensityPlot?
@@ -131,7 +130,6 @@ def eval_Plot3D(
131130 evaluation : Evaluation ,
132131):
133132 def emit (graphics , i , xyzs , quads ):
134-
135133 # color-blind friendly palette from https://davidmathlogic.com/colorblind
136134 palette = [
137135 (255 , 176 , 0 ), # orange
@@ -148,11 +146,10 @@ def emit(graphics, i, xyzs, quads):
148146 rgb = [c / 255.0 for c in rgb ]
149147 # graphics.add_color(SymbolRGBColor, rgb)
150148 graphics .add_directives ([SymbolRGBColor , * rgb ])
151-
149+
152150 # add a GraphicsComplex displaying a surface for this function
153151 graphics .add_complex (xyzs , lines = None , polys = quads )
154152
155-
156153 return make_plot (plot_options , evaluation , dim = 3 , is_complex = False , emit = emit )
157154
158155
@@ -162,7 +159,6 @@ def eval_DensityPlot(
162159 evaluation : Evaluation ,
163160):
164161 def emit (graphics , i , xyzs , quads ):
165-
166162 # Fixed palette for now
167163 # TODO: accept color options
168164 with Timer ("compute colors" ):
@@ -184,10 +180,9 @@ def emit(graphics, i, xyzs, quads):
184180
185181@Timer ("complex colors" )
186182def complex_colors (zs , s = None ):
187-
188183 # hue depends on phase
189184 h = np .angle (zs , deg = True ) / 360
190-
185+
191186 # saturation depends on magnitude
192187 if s is None :
193188 zabs = abs (zs )
@@ -196,10 +191,10 @@ def complex_colors(zs, s=None):
196191 s = (zabs - zmin ) / (zmax - zmin )
197192 else :
198193 s = np .full (zs .shape , s )
199-
194+
200195 # brightness is constant
201196 b = np .full (zs .shape , 1.0 )
202-
197+
203198 # convert to rgb
204199 hsb = np .array ([h , s , b ]).T
205200 rgb = convert_color (hsb , "HSB" , "RGB" , False )
@@ -213,23 +208,24 @@ def eval_ComplexPlot3D(
213208 evaluation : Evaluation ,
214209):
215210 def emit (graphics , i , xyzs , quads ):
216- zs = xyzs [:,2 ]
211+ zs = xyzs [:, 2 ]
217212 rgb = complex_colors (zs , s = 0.8 )
218- xyzs [:,2 ] = abs (zs )
219- graphics .add_complex (xyzs .astype (float ), lines = None , polys = quads , colors = rgb )
213+ xyzs [:, 2 ] = abs (zs )
214+ graphics .add_complex (xyzs .astype (float ), lines = None , polys = quads , colors = rgb )
220215
221216 return make_plot (plot_options , evaluation , dim = 3 , is_complex = True , emit = emit )
222217
223218
224-
225219@Timer ("eval_ComplexPlot" )
226220def eval_ComplexPlot (
227221 plot_options ,
228222 evaluation : Evaluation ,
229223):
230224 def emit (graphics , i , xyzs , quads ):
231225 # flatten the points and add the quads
232- rgb = complex_colors (xyzs [:,2 ])
233- graphics .add_complex (xyzs [:, 0 :2 ].astype (float ), lines = None , polys = quads , colors = rgb )
226+ rgb = complex_colors (xyzs [:, 2 ])
227+ graphics .add_complex (
228+ xyzs [:, 0 :2 ].astype (float ), lines = None , polys = quads , colors = rgb
229+ )
234230
235231 return make_plot (plot_options , evaluation , dim = 2 , is_complex = True , emit = emit )
0 commit comments