Skip to content

Commit db2994c

Browse files
committed
Slight refactor
1 parent 51feaee commit db2994c

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

mathics/eval/drawing/plot3d_vectorized.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
from .util import GraphicsGenerator
1818

1919

20-
@Timer("eval_Plot3D")
21-
def eval_Plot3D(
20+
def make_plot(
2221
plot_options,
2322
evaluation: Evaluation,
24-
density = False
23+
dim: int
2524
):
26-
graphics = GraphicsGenerator(dim = 2 if density else 3)
25+
graphics = GraphicsGenerator(dim)
2726

2827
# pull out plot options
2928
_, xmin, xmax = plot_options.ranges[0]
@@ -105,7 +104,8 @@ def compute_over_grid(nx, ny):
105104
# transpose and flatten to ((nx-1)*(ny-1), 4) array, suitable for use in GraphicsComplex
106105
quads = quads.T.reshape(-1, 4)
107106

108-
if not density:
107+
# Plot3D
108+
if dim == 3:
109109

110110
# choose a color
111111
rgb = palette[i % len(palette)]
@@ -116,8 +116,11 @@ def compute_over_grid(nx, ny):
116116
# add a GraphicsComplex displaying a surface for this function
117117
graphics.add_complex(xyzs, lines=None, polys=quads)
118118

119-
else:
119+
# DensityPlot
120+
elif dim == 2:
120121

122+
# Fixed palette for now
123+
# TODO: accept color options
121124
with Timer("compute colors"):
122125
zs = xyzs[:,2]
123126
z_min, z_max = min(zs), max(zs)
@@ -130,8 +133,10 @@ def compute_over_grid(nx, ny):
130133
graphics.add_complex(xyzs[:,0:2], lines=None, polys=quads, colors=colors)
131134

132135

133-
# if requested by the Mesh attribute create a mesh of lines covering the surfaces
134-
if nmesh:
136+
# If requested by the Mesh attribute create a mesh of lines covering the surfaces
137+
# For now only for Plot3D
138+
# TODO: mesh for DensityPlot?
139+
if nmesh and dim == 3:
135140
# meshes are black for now
136141
graphics.add_directives([SymbolRGBColor, 0, 0, 0])
137142

@@ -149,13 +154,17 @@ def compute_over_grid(nx, ny):
149154
return graphics
150155

151156

152-
#
153-
#
154-
#
157+
@Timer("eval_Plot3D")
158+
def eval_Plot3D(
159+
plot_options,
160+
evaluation: Evaluation,
161+
):
162+
return make_plot(plot_options, evaluation, dim=3)
155163

156164

165+
@Timer("eval_DensityPlot")
157166
def eval_DensityPlot(
158167
plot_options,
159168
evaluation: Evaluation,
160169
):
161-
return eval_Plot3D(plot_options, evaluation, density=True)
170+
return make_plot(plot_options, evaluation, dim=2)

0 commit comments

Comments
 (0)