@@ -72,19 +72,29 @@ class ColorMap(MacroElement):
72
72
The right bound of the color scale.
73
73
caption: str
74
74
A caption to draw with the colormap.
75
+ text_color: str, default "black"
76
+ The color for the text.
75
77
max_labels : int, default 10
76
78
Maximum number of legend tick labels
77
79
"""
78
80
79
81
_template = ENV .get_template ("color_scale.js" )
80
82
81
- def __init__ (self , vmin = 0.0 , vmax = 1.0 , caption = "" , max_labels = 10 ):
83
+ def __init__ (
84
+ self ,
85
+ vmin = 0.0 ,
86
+ vmax = 1.0 ,
87
+ caption = "" ,
88
+ text_color = "black" ,
89
+ max_labels = 10 ,
90
+ ):
82
91
super ().__init__ ()
83
92
self ._name = "ColorMap"
84
93
85
94
self .vmin = vmin
86
95
self .vmax = vmax
87
96
self .caption = caption
97
+ self .text_color = text_color
88
98
self .index = [vmin , vmax ]
89
99
self .max_labels = max_labels
90
100
self .tick_labels = None
@@ -185,22 +195,32 @@ def _repr_html_(self):
185
195
for i in range (self .width )
186
196
],
187
197
)
188
- + '<text x="0" y="38" style="text-anchor:start; font-size:11px; font:Arial">{}</text>' .format ( # noqa
198
+ + (
199
+ '<text x="0" y="38" style="text-anchor:start; font-size:11px;'
200
+ ' font:Arial; fill:{}">{}</text>'
201
+ ).format (
202
+ self .text_color ,
189
203
self .vmin ,
190
204
)
191
205
+ "" .join (
192
206
[
193
207
(
194
- '<text x="{}" y="38"; style="text-anchor:middle; font-size:11px; font:Arial">{}</text>' # noqa
195
- ).format (x_ticks [i ], val_ticks [i ])
208
+ '<text x="{}" y="38"; style="text-anchor:middle; font-size:11px;'
209
+ ' font:Arial; fill:{}">{}</text>'
210
+ ).format (x_ticks [i ], self .text_color , val_ticks [i ])
196
211
for i in range (1 , nb_ticks - 1 )
197
212
],
198
213
)
199
- + '<text x="{}" y="38" style="text-anchor:end; font-size:11px; font:Arial">{}</text>' .format (
214
+ + (
215
+ '<text x="{}" y="38" style="text-anchor:end; font-size:11px;'
216
+ ' font:Arial; fill:{}">{}</text>'
217
+ ).format (
200
218
self .width ,
219
+ self .text_color ,
201
220
self .vmax ,
202
221
)
203
- + '<text x="0" y="12" style="font-size:11px; font:Arial">{}</text>' .format (
222
+ + '<text x="0" y="12" style="font-size:11px; font:Arial; fill:{}">{}</text>' .format (
223
+ self .text_color ,
204
224
self .caption ,
205
225
)
206
226
+ "</svg>"
@@ -233,6 +253,10 @@ class LinearColormap(ColorMap):
233
253
vmax : float, default 1.
234
254
The maximal value for the colormap.
235
255
Values higher than `vmax` will be bound directly to `colors[-1]`.
256
+ caption: str
257
+ A caption to draw with the colormap.
258
+ text_color: str, default "black"
259
+ The color for the text.
236
260
max_labels : int, default 10
237
261
Maximum number of legend tick labels
238
262
tick_labels: list of floats, default None
@@ -245,13 +269,15 @@ def __init__(
245
269
vmin = 0.0 ,
246
270
vmax = 1.0 ,
247
271
caption = "" ,
272
+ text_color = "black" ,
248
273
max_labels = 10 ,
249
274
tick_labels = None ,
250
275
):
251
276
super ().__init__ (
252
277
vmin = vmin ,
253
278
vmax = vmax ,
254
279
caption = caption ,
280
+ text_color = text_color ,
255
281
max_labels = max_labels ,
256
282
)
257
283
self .tick_labels = tick_labels
@@ -415,13 +441,15 @@ def to_step(
415
441
]
416
442
417
443
caption = self .caption
444
+ text_color = self .text_color
418
445
419
446
return StepColormap (
420
447
colors ,
421
448
index = index ,
422
449
vmin = index [0 ],
423
450
vmax = index [- 1 ],
424
451
caption = caption ,
452
+ text_color = text_color ,
425
453
max_labels = max_labels ,
426
454
tick_labels = self .tick_labels ,
427
455
)
@@ -439,6 +467,7 @@ def scale(self, vmin=0.0, vmax=1.0, max_labels=10):
439
467
vmin = vmin ,
440
468
vmax = vmax ,
441
469
caption = self .caption ,
470
+ text_color = self .text_color ,
442
471
max_labels = max_labels ,
443
472
)
444
473
@@ -469,6 +498,10 @@ class StepColormap(ColorMap):
469
498
vmax : float, default 1.
470
499
The maximal value for the colormap.
471
500
Values higher than `vmax` will be bound directly to `colors[-1]`.
501
+ caption: str
502
+ A caption to draw with the colormap.
503
+ text_color: str, default "black"
504
+ The color for the text.
472
505
max_labels : int, default 10
473
506
Maximum number of legend tick labels
474
507
tick_labels: list of floats, default None
@@ -482,13 +515,15 @@ def __init__(
482
515
vmin = 0.0 ,
483
516
vmax = 1.0 ,
484
517
caption = "" ,
518
+ text_color = "black" ,
485
519
max_labels = 10 ,
486
520
tick_labels = None ,
487
521
):
488
522
super ().__init__ (
489
523
vmin = vmin ,
490
524
vmax = vmax ,
491
525
caption = caption ,
526
+ text_color = text_color ,
492
527
max_labels = max_labels ,
493
528
)
494
529
self .tick_labels = tick_labels
@@ -544,6 +579,8 @@ def to_linear(self, index=None, max_labels=10):
544
579
index = index ,
545
580
vmin = self .vmin ,
546
581
vmax = self .vmax ,
582
+ caption = self .caption ,
583
+ text_color = self .text_color ,
547
584
max_labels = max_labels ,
548
585
)
549
586
@@ -560,6 +597,7 @@ def scale(self, vmin=0.0, vmax=1.0, max_labels=10):
560
597
vmin = vmin ,
561
598
vmax = vmax ,
562
599
caption = self .caption ,
600
+ text_color = self .text_color ,
563
601
max_labels = max_labels ,
564
602
)
565
603
0 commit comments