Skip to content

Commit 09d49a7

Browse files
committed
Add default colors
1 parent 8d4b6d6 commit 09d49a7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

mathics/eval/drawing/plot3d_vectorized.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from mathics.core.evaluation import Evaluation
1212
from mathics.core.symbols import strip_context
13+
from mathics.core.systemsymbols import SymbolRGBColor, SymbolNone
1314
from mathics.timing import Timer
1415

1516
from .plot_compile import plot_compile
@@ -34,7 +35,20 @@ def eval_Plot3D(
3435
ys = np.linspace(ymin, ymax, ny)
3536
xs, ys = np.meshgrid(xs, ys)
3637

37-
for function in plot_options.functions:
38+
# https://davidmathlogic.com/colorblind
39+
palette = [
40+
(255, 176, 0), # orange
41+
(100, 143, 255), # blue
42+
(220, 38, 127), # red
43+
(50, 150, 140), # green
44+
(120, 94, 240), # purple
45+
#(240, 228, 66), # yellow
46+
(254, 97, 0), # dark orange
47+
(0, 114, 178), # dark blue
48+
#(0, 0, 0), # black
49+
]
50+
51+
for i, function in enumerate(plot_options.functions):
3852
with Timer("compile"):
3953
function = plot_compile(evaluation, function, names)
4054

@@ -73,9 +87,15 @@ def eval_Plot3D(
7387
# ugh - indexes in Polygon are 1-based
7488
quads += 1
7589

90+
# choose a color
91+
rgb = palette[i%len(palette)]
92+
rgb = [c/255.0 for c in rgb]
93+
graphics.add_color(SymbolRGBColor, rgb)
94+
7695
# add a GraphicsComplex for this function
7796
graphics.add_complex(xyzs, lines=None, polys=quads)
7897

98+
7999
return graphics
80100

81101

mathics/eval/drawing/util.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ def add_linexyzs(self, line_xyzs, colors=None):
5858
"""Add lines specified by explicit xy[z] coordinates"""
5959
self.add_thing(SymbolLine, line_xyzs, colors)
6060

61-
# TODO: color
61+
def add_color(self, symbol, components):
62+
from mathics.core.convert.expression import to_expression
63+
expr = to_expression(symbol, *components)
64+
self.graphics.append(expr)
65+
6266
def add_complex(self, xyzs, lines=None, polys=None):
6367
complex = [NumericArray(xyzs)]
6468
if polys is not None:

0 commit comments

Comments
 (0)