|
21 | 21 | def eval_Plot3D( |
22 | 22 | plot_options, |
23 | 23 | evaluation: Evaluation, |
| 24 | + density = False |
24 | 25 | ): |
25 | | - graphics = GraphicsGenerator(dim=3) |
| 26 | + graphics = GraphicsGenerator(dim = 2 if density else 3) |
26 | 27 |
|
27 | 28 | # pull out plot options |
28 | 29 | _, xmin, xmax = plot_options.ranges[0] |
@@ -104,14 +105,30 @@ def compute_over_grid(nx, ny): |
104 | 105 | # transpose and flatten to ((nx-1)*(ny-1), 4) array, suitable for use in GraphicsComplex |
105 | 106 | quads = quads.T.reshape(-1, 4) |
106 | 107 |
|
107 | | - # choose a color |
108 | | - rgb = palette[i % len(palette)] |
109 | | - rgb = [c / 255.0 for c in rgb] |
110 | | - # graphics.add_color(SymbolRGBColor, rgb) |
111 | | - graphics.add_directives([SymbolRGBColor, *rgb]) |
| 108 | + if not density: |
112 | 109 |
|
113 | | - # add a GraphicsComplex displaying a surface for this function |
114 | | - graphics.add_complex(xyzs, lines=None, polys=quads) |
| 110 | + # choose a color |
| 111 | + rgb = palette[i % len(palette)] |
| 112 | + rgb = [c / 255.0 for c in rgb] |
| 113 | + # graphics.add_color(SymbolRGBColor, rgb) |
| 114 | + graphics.add_directives([SymbolRGBColor, *rgb]) |
| 115 | + |
| 116 | + # add a GraphicsComplex displaying a surface for this function |
| 117 | + graphics.add_complex(xyzs, lines=None, polys=quads) |
| 118 | + |
| 119 | + else: |
| 120 | + |
| 121 | + with Timer("compute colors"): |
| 122 | + zs = xyzs[:,2] |
| 123 | + z_min, z_max = min(zs), max(zs) |
| 124 | + zs = zs[:, np.newaxis] # allow broadcasting |
| 125 | + c_min, c_max = [0.5, 0, 0.1], [1.0, 0.9, 0.5] |
| 126 | + c_min, c_max = np.full((len(zs),3), c_min), np.full((len(zs),3), c_max) |
| 127 | + colors = ((zs - z_min) * c_max + (z_max - zs) * c_min) / (z_max - z_min) |
| 128 | + |
| 129 | + # flatten the points and add the quads |
| 130 | + graphics.add_complex(xyzs[:,0:2], lines=None, polys=quads, colors=colors) |
| 131 | + |
115 | 132 |
|
116 | 133 | # if requested by the Mesh attribute create a mesh of lines covering the surfaces |
117 | 134 | if nmesh: |
@@ -141,6 +158,4 @@ def eval_DensityPlot( |
141 | 158 | plot_options, |
142 | 159 | evaluation: Evaluation, |
143 | 160 | ): |
144 | | - # TODO |
145 | | - # see plot3d.eval_DensityPlot for possible info on handling colors |
146 | | - pass |
| 161 | + return eval_Plot3D(plot_options, evaluation, density=True) |
0 commit comments