forked from plotly/plotly.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_objs_meta.py
More file actions
3260 lines (2671 loc) · 106 KB
/
graph_objs_meta.py
File metadata and controls
3260 lines (2671 loc) · 106 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# ----------------------- Plotly graph object meta ------------------------------
#
# Welcome to the ultimate reference of Plotly's JSON graph format.
#
# Philosophy:
#
# * ALL plotly keys should be placed a single JSON file.
#
# * A fully described key is an object with the keys:
# (1) 'required', (2) 'type', (3) 'val_types', and (4) 'description',
#
# - and additionally (5) streamable, (6) example and (7) code.
#
# * All keys that are contained in more than 1 object has a
# corresponding shortcut function (`make_ `) or dictionary (`drop_ `).
#
# -------------------------------------------------------------------------------
#
# Contents -----------------
#
# Section -- Required modules
#
# Section -- Shortcuts Definitions:
#
# * Inventory of value types repeated over several keys
# - search for `$val_types`
#
# * Inventory of shortcuts for repeated keys of meta-generating functions
# - search for `$shortcuts--` for top of the section
# - search for e.g. `$shortcut-x` for shortcut of specific key
#
# Section -- Graph Objects Meta:
#
# * 'Trace' graph objects (search for `$graph-objs-meta-trace`):
# - Scatter (search for `$scatter`)
# - Bar ( `$bar`)
# - Histogram ( `$histogram`)
# - Bar ( `$box`)
# - Heatmap ( `$heatmap`)
# - Contour ( `$contour`)
# - Histogram2d ( `$histogram2d`)
# - Histogram2dContour ( `$histogram2dcontour`)
# - Area ( `$Area`)
#
# * 'Auxiliary trace' graph objects ( `$graph-objs-meta-trace-aux`):
# - ErrorY (search for `$error_y`)
# - ErrorX ( `$error_x`)
# - XBins ( `$xbins`)
# - YBins ( `$ybins`)
# - Contours ( `$contours`)
# - Stream ( `$stream`)
#
# * 'Style' graph objects ( `$graph-objs-meta-style`)
# - Marker (search for `$marker`)
# - Line ( `$line`)
# - Font ( `$font`)
#
# * 'Axis' graph objects ( `$graph-objs-meta-layout-axis`)
# - XAxis (search for `$xaxis`)
# - YAxis ( `$yaxis`)
# - RadialAxis ( `$radialaxis`)
# - AngularAxis ( `$angularaxis`)
#
# * Other 'auxiliary layout' graph objects ( `$graph-objs-meta-layout-aux`)
# - Legend (search for `$legend`)
# - ColorBar ( `$colorbar`)
# - Margin ( `$margin`)
# - Annotation ( `$annotation`)
#
# * Layout ( `$layout`)
#
# * Figure ( `$figure`)
#
# * Other graph objects ( `$graph-objs-meta-others`)
# - Data (search for `$plotlydata`)
# - Annotations ( `$annotations`)
# - Trace ( `$trace`)
# - PlotlyList ( `$plotlylist`)
# - PlotlyDict ( `$plotlydict`)
# - PlotlyTrace ( `$plotlytrace`)
#
# Section -- Write to JSON
#
# ===============================================================================
## Required modules
# Use ordered dictionaries to list graph object keys
from collections import OrderedDict
# -------------------------------------------------------------------------------
## Shortcut definitions
# $val_types
#
# List of value types repeated over several keys
# $val_types-number
# Use this to format key accepting numbers
def _number(lt=None, le=None, gt=None, ge=None, list=False):
if any((all((lt is not None, le is not None)),
all((gt is not None, ge is not None)))):
raise Exception("over-constrained number definition")
if [lt, le, gt, ge] == [None, None, None, None]:
out = "number"
elif lt is not None and ([ge, gt] == [None, None]):
out = "number: x < {lt}".format(lt=lt)
elif le is not None and ([ge, gt] == [None, None]):
out = "number: x <= {le}".format(le=le)
elif gt is not None and ([le, lt] == [None, None]):
out = "number: x > {gt}".format(gt=gt)
elif ge is not None and ([le, lt] == [None, None]):
out = "number: x >= {ge}".format(ge=ge)
elif (lt is not None) and (gt is not None):
out = "number: x in ({gt}, {lt})".format(gt=gt, lt=lt)
elif (lt is not None) and (ge is not None):
out = "number: x in [{ge}, {lt})".format(ge=ge, lt=lt)
elif (le is not None) and (gt is not None):
out = "number: x in ({gt}, {le}]".format(gt=gt, le=le)
elif (le is not None) and (ge is not None):
out = "number: x in [{ge}, {le}]".format(le=le, ge=ge)
if list:
return out+", or list of these numbers"
else:
return out
# $val_types-required-when
# Use this for conditional booleans (e.g. for 'required' values)
def _required_when(when):
if type(when)==str:
to_be = 'is'
elif type(when)==list:
when=','.join(when[0:-1])+' and '+when[-1]
to_be = 'are'
return " when {key} {to_be} unset".format(key=when,to_be=to_be)
# $val_types-dict
val_types = dict(
bool="boolean: True | False",
required_when= _required_when,
color="string describing color",
string="string",
number= _number,
data_array="array-like of numbers, strings, datetimes",
string_array="array-like of strings",
color_array="array-like of string describing color",
matrix="matrix-like: list of lists, numpy.matrix",
object="dictionary-like",
)
# -------------------------------------------------------------------------------
# $shortcuts--
#
# List of shortcuts for repeated keys of meta-generating functions
# $shortcut-shortcuts
# $shortcut-output
def output(_required, _type, _val_types, _description, **kwargs):
'''
Outputs a dictionary of key-value pairs, given the keys.
(pos. arg. 1) _required: value of 'required' key
(pos. arg. 2) _type: value of 'type' key
(pos. arg. 3) _val_types: value of 'val_types' key
(pos. arg. 4) _description: value of 'description' key
(keyword args) kwargs: dictionary of additional key-value pairs
'''
_dict = dict(
required= _required,
type= _type,
val_types= _val_types,
description= _description)
if len(kwargs):
for k, v in kwargs.iteritems():
_dict[k] = v
return _dict
# $shortcut-x
def make_x(obj):
_required=dict(
scatter=val_types['required_when'](["'y'","'r'","'t'"]),
bar=val_types['required_when'](["'y'","'r'","'t'"]),
histogram=val_types['required_when'](["'y'","'r'","'t'"]),
box=False,
heatmap=False,
contour=False,
histogram2d=True,
histogram2dcontour=True,
)
_type='data'
_val_types=val_types['data_array']
_description=dict(
scatter="The x coordinates of the points of this scatter trace. "
"If 'x' is linked to an list or array of strings, "
"then the x coordinates are integers [0,1,2,3, ...] labeled "
"on the x-axis by the list or array of strings linked to 'x'.",
bar="The x coordinates of the bars. "
"If 'x' is linked to an list or array of strings, "
"then the x coordinates are integers [0,1,2,3, ...] labeled "
"on the x-axis by the list or array of strings linked to 'x'. "
"If 'y' is not set, the bars are plotted horizontally, "
"with their length determined by the list or array linked to 'x'.",
histogram="The data sample to be binned (done by Plotly) on the x-axis "
"and plotted as vertical bars.",
box="Usually, you do not need to set this value as "
"plotly will handle box locations for you. However "
"this allows you to have fine control over the "
"location data for the box. Unlike making a bar, "
"a box plot is made of many y values. Therefore, "
"to give location data to the values you place in "
"'y', the length of 'x' must equal the length of 'y'. "
"when making multiple box plots, you can concatenate "
"the data sets for each box into a single 'y' array. "
"then, the entries in 'x' define which box plot each "
"entry in 'y' belongs to. When making a single box "
"plot, you must set each entry in 'x' to the same "
"value, see 'x0' for a more practical way to handle "
"this case. If you don't include 'x', the box will "
"simply be assigned a location.",
heatmap="This array-like value contains the horizontal coordinates "
"referring to the columns of the 'z' matrix. "
"if strings, the x-labels are spaced evenly."
"if the dimensions of z are (n x m), "
"the length of the 'x' array should be 'm'.",
histogram2d="The data sample to be binned on the x-axis and "
"whose distribution (computed by Plotly) will correspond "
"to the x-coordinates of this 2D histogram trace."
)
_description['contour']= _description['heatmap']
_description['histogram2dcontour']= _description['histogram2d']
_streamable=True
if obj=='box': # TO DO! Sub 'code' for example link?
_code=''.join([">>> y0 = [1,2,3,1,1]",
">>> y1 = [3,2,1,2,3]",
">>> y = y0+y1 # N.B. list not numpy arrays here",
">>> x = [0,0,0,0,0,1,1,1,1,1] # len(x) == len(y)",
">>> Box(y=y, x=x, name='two boxes SHARE this name.')"
])
return output(_required[obj],_type,_val_types,_description[obj],
streamable=_streamable,code=_code)
else:
return output(_required[obj],_type,_val_types,_description[obj],
streamable=_streamable)
# $shortcut-y
def make_y(obj):
_required=dict(
scatter=val_types['required_when'](["'x'","'r'","'t'"]),
bar=val_types['required_when'](["'x'","'r'","'t'"]),
histogram=val_types['required_when'](["'x'","'r'","'t'"]),
box=True,
heatmap=False,
contour=False,
histogram2d=True,
histogram2dcontour=True,
)
_type='data'
_val_types=val_types['data_array']
_description=dict(
scatter="The y coordinates of the points of this scatter trace. "
"If 'y' is linked to an list or array of strings, "
"then the y coordinates are integers [0,1,2,3, ...] labeled "
"on the y-axis by the list or array of strings linked to 'y'.",
histogram="The data sample to be binned (done by Plotly) on the y-axis "
"and plotted as horizontal bars.",
bar="The y coordinates of the bars. "
"If 'y' is linked to an list or array of strings, "
"then the y coordinates are integers [0,1,2,3, ...] labeled "
"on the y-axis by the list or array of strings linked to 'y'. "
"If 'x' is not set, the bars are plotted vertically, "
"with their length determined by the list or array linked to 'y'.",
box="This array is used to define an individual "
"box plot, or, a concatenation of multiple boxplots. "
"Statistics from these numbers define the bounds of "
"the box, the length of the whiskers, etc. For "
"details on defining multiple boxes with locations "
"see 'x'.",
heatmap="This array-like value contains the vertical coordinates "
"referring to the rows of the 'z' matrix. "
"If strings, the y-labels are spaced evenly."
"If the dimensions of z are (n x m), "
"the length of the 'y' array should be 'n'.",
histogram2d="The data sample to be binned on the y-axis and "
"whose distribution (computed by Plotly) will correspond "
"to the y-coordinates of this 2D histogram trace."
)
_description['contour']= _description['heatmap']
_description['histogram2dcontour']= _description['histogram2d']
_streamable=True
return output(_required[obj],_type,_val_types,_description[obj],
streamable=_streamable)
# $shortcut-z
def make_z(obj):
_required=False # TO DO! How to phrase this?
_type='data'
_val_types=val_types['matrix']
_description=dict(
heatmap="The data that describes the mapping. "
"The dimensions of the 'z' matrix are (n x m) "
"where there are 'n' ROWS defining the "
"number of partitions along the y-axis; this is equal to the "
"length of the 'y' array. "
"There are 'm' COLUMNS defining the number "
"of partitions along the x-axis; "
"this is equal to the length of the 'x' array. "
"Therefore, the color of the cell z[i][j] is mapped to "
"the ith partition of the y-axis (starting from the bottom "
"of the plot) and the jth partition of the x-axis "
"(starting from the left of the plot). "
"In Python, a (non-numpy) matrix is best thought of as "
"a list of lists (of lists, of lists, etc.). "
"Therefore, running len(z) will give you the number "
"of ROWS and running len(z[0]) will give you "
"the number of COLUMNS. If you ARE using numpy, then running "
"z.shape will give you the tuple, (n, m), e.g., (3, 5)."
)
_streamable=True
_description['contour']= _description['heatmap']
return output(_required,_type,_val_types,_description[obj],
streamable=_streamable)
# $shortcut-r
def make_r(obj):
_required=dict(
scatter=val_types['required_when'](["'x'","'y'"]),
bar=val_types['required_when'](["'x'","'y'"]),
area=True
)
_type='data'
_val_types=val_types['data_array']
_description=dict( # TO DO! Better description of how the coords work
scatter="For Polar charts only. "
"The radial coordinates of the points in this "
"polar scatter trace.",
bar="For Polar charts only. "
"The radial coordinates of the bars in this polar bar trace",
area="The radial coordinates of the circle sectors in this "
"polar area trace.",
)
_streamable=True
return output(_required[obj],_type,_val_types,_description[obj],
streamable=_streamable)
# $shortcut-t
def make_t(obj):
_required=dict(
scatter=val_types['required_when'](["'x'","'y'"]),
bar=val_types['required_when'](["'x'","'y'"]),
area=True
)
_type='data'
_val_types=val_types['data_array']
_description=dict(
scatter="For Polar charts only. "
"The angular coordinates of the points in this "
"polar scatter trace.",
bar="For Polar charts only. "
"The angular coordinates of the bars in this polar bar trace.",
area="The angular coordinates of the circle sectors in this "
"polar area trace.",
)
_streamable=True
return output(_required[obj],_type,_val_types,_description[obj],
streamable=_streamable)
# $shortcuts-coordinates-alternative
# $shortcut-x0y0 $shortcut-x0 | $shortcut-y0
def make_x0y0(obj, x_or_y=False):
_required=False
_type='plot_info' # TO DO! 'data' maybe?
_val_types=val_types['number']()
S={'x':['x',], 'y':['y',], False:['',]}
s=S[x_or_y]
_description=dict( # TO DO! Add scatter?
box="The location of this box. When 'y' defines a single "
"box, 'x0' can be used to set where this box is "
"centered on the x-axis. If many boxes are set to "
"appear at the same 'x0' location, they will form a "
"box group.",
heatmap="The location of the first coordinate of the {S0}-axis. "
"Use with 'd{S0}' an alternative to an '{S0}' list/array. "
"Has no effect if '{S0}' is set.".format(S0=s[0])
)
_description['contour']= _description['heatmap']
return output(_required,_type,_val_types,_description[obj])
# $shortcut-dxdy | $shortcut-dx | $shortcut-dy
def make_dxdy(obj, x_or_y=False):
_required=False
_type='plot_info' # TO DO! 'data' maybe?
_val_types=val_types['number']()
S={'x':['x',], 'y':['y',], False:['',]}
s=S[x_or_y]
_description=dict( # TO DO! Add scatter?
heatmap="Spacing between {S0}-axis coordinates. "
"Use with '{S0}0' an alternative to an '{S0}' list/array. "
"Has no effect if '{S0}' is set.".format(S0=s[0]),
)
_description['contour']= _description['heatmap']
return output(_required,_type,_val_types,_description[obj])
# $shortcut-xytype | $shortcut-xtype | $shortcut-ytype
def make_xytype(obj, x_or_y):
_required=False
_type='data'
_val_types="'array' | 'scaled'",
S={'x':['x','horizontal'], 'y':['y','vertical'], False:['',]}
s=S[x_or_y]
_description=dict(
heatmap="If set to 'scaled' and '{S0}' is linked to a list/array, "
"then the {S1} labels are scaled to a list "
"of integers of unit step "
"starting from 0.".format(S0=s[0],S1=s[1])
)
_description['contour']= _description['heatmap']
return output(_required,_type,_val_types,_description[obj])
# $shortcuts-trace-aux
# $shortcut-text
def make_text(obj):
_required=False
_type='data'
_val_types=val_types['string_array']
_description=dict(
scatter="The text elements associated with each (x,y) pair in "
"this scatter trace. If the scatter 'mode' does not "
"include 'text' then text elements will appear on hover only. "
"In contrast, if 'text' is included in 'mode', "
"the entries in 'text' "
"will be rendered on the plot at the locations "
"specified in part by their corresponding (x,y) coordinate pair "
"and the 'textposition' key.",
bar="The text elements associated with each bar in this trace. "
"The entries in 'text' will appear on hover only, in a text "
"box located at the top of each bar."
)
_description['histogram']=_description['bar']
_streamable=True
return output(_required,_type,_val_types,_description[obj],
streamable=_streamable)
# $shortcut-error | $shortcut-error_y | $shortcut-error_x
def make_error(obj, x_or_y):
_required=False
_type='object'
_val_types=val_types['object']
S={'x':['horizontal','x'], 'y':['vetical','y']}
s=S[x_or_y]
_description=dict(
scatter="A dictionary-like object describing "
"the {S0} error bars (i.e. along the {S1}-axis) "
"that can be drawn "
"from the (x, y) coordinates.".format(S0=s[0],S1=s[1]),
bar="A dictionary-like object describing the {S0} error bars "
"(i.e. along the {S1}-axis) that can "
"be drawn from bar tops.".format(S0=s[0],S1=s[1])
)
_description['histogram']= _description['bar']
_streamable=True
return output(_required,_type,_val_types,_description[obj],
streamable=_streamable)
# $shortcuts-trace-style
# $shortcut-orientation
def make_orientation(obj):
_required=False
_type='style' # TO DO! 'plot_info' instead?
_val_types=val_types['data_array']
_description=dict(
bar="This defines the direction of the bars. "
"If set to 'v', the length of each bar will run vertically. "
"If set to 'h', the length of each bar will run horizontally",
histogram="Web GUI Artifact. Histogram orientation is determined "
"by which of 'x' or 'y' the data sample is linked to."
)
return output(_required,_type,_val_types,_description[obj])
# $shortcut-marker
def make_marker(obj):
_required=False
_type='object'
_val_types=val_types['object']
_description=dict(
scatter="A dictionary-like object containing marker style "
"parameters for this scatter trace. "
"Has an effect only if 'mode' contains 'markers'.",
bar="A dictionary-like object containing marker style "
"parameters for this bar trace, for example, "
"the bars' fill color, border width and border color.",
box="A dictionary-like object containing marker style "
"parameters for this the box points of box trace. "
"Has an effect only 'boxpoints' is set to 'outliers' or 'all'.",
area="A dictionary-like object containing marker style "
"of the area sectors of this trace, for example the sector fill "
"color and sector boundary line width and sector boundary color."
)
_description['histogram']= _description['bar']
_streamable=True
return output(_required,_type,_val_types,_description[obj],
streamable=_streamable)
# $shortcut-line
def make_line(obj):
_required=False
_type='object'
_val_types=val_types['object']
_description=dict(
scatter="A dictionary-like object containing line style "
"parameters for this scatter trace. "
"Has an effect only if 'mode' contains 'lines'.",
bar="Artifact. Has no effect.",
box="A dictionary-like object containing line style "
"parameters for the border of this box trace "
"(including the whiskers).",
contour="A dictionary-like object containing line style "
"parameters for contour lines of this contour trace "
"(including line width, dash, color and smoothing level). "
"Has no an effect if 'showlines' is set to False in Contours.",
marker="A dictionary-like object describing the line belonging to "
"the marker. For example, the line around each point "
"in a scatter trace or the line around each bar in a "
"bar trace.",
)
_description['histogram']= _description['bar']
_description['histogram2dcontour']= _description['contour']
_streamable=True
return output(_required,_type,_val_types,_description[obj],
streamable=_streamable)
# $shortcut-opacity
def make_opacity(marker=False):
_required=False
_type="style"
if not marker:
_val_types=val_types['number'](ge=0, le=1)
_description=''.join(["Sets the opacity, or transparency, ",
"of the entire object, ",
"also known as the alpha channel of colors. ",
"If the object's color is given in terms of ",
"'rgba' color ",
"model, 'opacity' is redundant."
])
else:
_val_types=val_types['number'](ge=0, le=1, list=True)
_description=''.join(["Sets the opacity, or transparency ",
"also known as the alpha channel of colors) ",
"of the marker points. ",
"If the marker points' ",
"color is given in terms of 'rgba' ",
"color model, this does not need to be defined. ",
"If 'opacity' is linked to a list or an array ",
"of numbers, opacity values are mapped to ",
"individual marker points in the ",
"same order as in the data lists or arrays."
])
return output(_required,_type,_val_types,_description)
# $shortcut-textfont
def make_textfont(obj):
_required=False
_type='object'
_val_types=val_types['object']
_description=dict(
scatter="A dictionary-like object describing the font style "
"of this scatter trace's text elements. Has only "
"an effect if 'mode' is set and includes 'text'.",
bar="Not currently supported, has no effect."
)
_description['histogram']= _description['bar']
return output(_required,_type,_val_types,_description[obj])
# $shortcut-font
def make_font(obj):
_required=False
_type='object'
_val_types=val_types['object']
_description=dict(
legend="A dictionary-like object describing the font "
"settings within the legend.",
annotation="A dictionary-like object describing the font "
"settings within this annotation.",
layout="A dictionary-like object describing the global font "
"settings for this figure (e.g. all axis titles and labels)."
)
return output(_required,_type,_val_types,_description[obj])
# $shortcuts-for-all-traces
# $shortcut-name
drop_name=dict(
required=False,
type='data',
val_types=val_types['string'],
description="The label associated with this trace. "
"This name will appear in the legend, on hover and "
"in the column header in the online spreadsheet."
)
# $shortcut-stream
drop_stream=dict(
required=False,
type='plot_info',
val_types=val_types['object'],
description="The stream dictionary-like object that initializes traces as "
"writable-streams, for use with the real-time streaming "
"API. Learn more here:\n"
"https://plot.ly/python/streaming/"
)
# $shortcut-visible
drop_visible=dict(
required=False,
type='plot_info',
val_types=val_types['bool'],
description="Toggles whether or not this object will actually be "
"visible in the rendered figure."
)
# $shortcuts-trace-and-layout
# $shortcut-showlegend
def make_showlegend(trace=False, layout=False):
_required=False
_type='style'
_val_types=val_types['bool']
if trace:
_description=''.join(["Toggle whether or not this trace will be ",
"labeled in the legend."
])
elif layout:
_description=''.join(["Toggle whether or not the legend will "
"be shown in this figure."
])
return output(_required,_type,_val_types,_description)
# $shortcut-axis | $shortcut-xaxis | $shortcut-yaxis
def make_axis(x_or_y, trace=False, layout=False):
_required=False
S={'x':['x','horizontal','X'], 'y':['y','vertical','Y']}
s=S[x_or_y]
if trace:
_type='plot_info'
_val_types="'{S0}1' | '{S0}2' | '{S0}3' | etc.".format(S0=s[0])
_description=''.join(["This key determines which {S0}-axis ",
"the {S0}-coordinates of this trace will ",
"reference in the figure. Values '{S0}1' ",
"and '{S0}' reference to layout['{S0}axis'], ",
"'{S0}2' references layout['{S0}axis2'], and ",
"so on. Note that '{S0}1' will always refer to ",
"layout['{S0}axis'] or layout['{S0}axis1'], ",
"they are the same."
]).format(S0=s[0])
elif layout:
_type='object'
_val_types=val_types['object']
_description=''.join(["A dictionary-like object describing an ",
"{S0}-axis (i.e. an {S1} axis). ",
"The first {S2}Axis object can be entered into "
"layout by linking it to '{S0}axis' OR ",
"'{S0}axis1', both keys are identical to Plotly. ",
" To create references other {S0}-axes, ",
"you need to define them in the layout ",
"dictionary-like object using keys '{S0}axis2', ",
"'{S0}axis3' and so on."
]).format(S0=s[0],S1=s[1],S2=s[2])
return output(_required,_type,_val_types,_description)
# $shortcut-type
def make_type(trace=False, axis=False, error=False):
_required=False
_type='plot_info'
if trace:
_val_types=trace
_description=''.join(["Plotly identifier for this data's trace type. ",
" This defines how this ",
" data dictionary will be handled. ",
" For example, 'scatter' type expects ",
" x and y data-arrays corresponding to ",
"(x, y) coordinates whereas a 'histogram' ",
"only requires a single x or y array ",
" and a 'heatmap' type requires a z matrix."
])
elif axis: # TO DO! Info on category
_val_types="'linear' | 'log' | 'category'"
_description="Defines format of this axis."
elif error:
_type='plot_info' # TO DO! 'data' maybe?
_val_types="'data' | 'percent' | 'constant' | 'sqrt'"
_description=''.join(["Specify how the 'value' or 'array' key in ",
"this error bar will be used to render the bars. ",
"Using 'data' will set error bar lengths to the ",
"actual numbers specified in 'array'. ",
"Using 'percent' will set bar lengths to the ",
"percent of error associated with 'value'. ",
"Using 'constant' will set each error ",
"bar length to the single value specified ",
"in 'value'. Using 'sqrt' will set ",
"each error bar length to the square root of ",
"the x data at each point ('value' and 'array' ",
"do not apply)."
])
return output(_required,_type,_val_types,_description)
# $shortcuts-histograms-specs
# $shortcut-histnorm
drop_histnorm=dict(
required=False,
type='plot_info',
val_types="'' (or 'count') | 'percent' | 'probability' | 'density' | "
"'probability density'",
description="If histnorm is not specified, or histnorm='' ("
"empty string), the height of each bar displays the "
"frequency of occurrence, i.e., the number of times this "
"value was found in the corresponding bin. If "
"histnorm='percent', the height of each bar displays the "
"percentage of total occurrences found within the "
"corresponding bin. If histnorm='probability', the height "
"of each bar displays the probability that an event will "
"fall into the corresponding bin. If histnorm='density', "
"the height of each bar is equal to the number of "
"occurrences in a bin divided by the size of the bin "
"interval such that summing the area of all bins will "
"yield the total number of occurrences. If "
"histnorm='probability density', the height of each bar "
"is equal to the number of probability that an event will "
"fall into the corresponding bin divided by the size of "
"the bin interval such that summing the area of all bins "
"will yield 1, i.e. an event must fall into one of the "
"bins."
)
# $shortcut-autobin | $shortcut-autobinx | $shortcut-autobiny
def make_autobin(x_or_y):
_required=False
_type='plot_info'
_val_types=val_types['bool']
S={'x':['x','X'], 'y':['y','Y']}
s=S[x_or_y]
_description=''.join(["Toggle whether or not the {S0}-axis bin parameters ",
"are picked automatically by Plotly. ",
"Once 'autobin{S0}' is set to False, the {S0}-axis ",
"bins parameters can be declared ",
"in the {S1}Bins object."
]).format(S0=s[0],S1=s[1])
return output(_required,_type,_val_types,_description)
# $shortcut-nbins | $shortcut-nbinsx | $shortcut-nbinsy
def make_nbins(x_or_y):
_required=False
_type='style' # TO DO! Shouldn't this be 'plot_info' ?
_val_types=val_types['number'](gt=0)
S={'x':['x',], 'y':['y',]}
s=S[x_or_y]
_description=''.join(["Specifies the number of {S0}-axis bins. ",
"No need to set 'autobin{S0}' to False ",
"for 'nbins{S0}' to apply."
]).format(S0=s[0])
return output(_required,_type,_val_types,_description)
# $shortcut-bins | $shortcut-xbins | $shortcut-ybins
def make_bins(x_or_y):
_required=False
_type='object'
_val_types=val_types['object']
S={'x':['x',], 'y':['y',]}
s=S[x_or_y]
_description=''.join(["A dictionary-like object defining the parameters ",
"of {S0}-axis bins of this trace, for example, ",
"the bin width and the bins' starting and ",
"ending value. Has an effect only if ",
"'autobin{S0}'=False."
]).format(S0=s[0])
return output(_required,_type,_val_types,_description)
# $shortcuts-2d-specs
# $shortcut-colorbar
drop_colorbar=dict(
required=False,
type='object',
val_types=val_types['object'],
description="A dictionary-like object defining the parameters of "
"the color bar associated with this trace "
"(including its title, length and width)."
)
# $shortcut-scl
drop_scl=dict(
required=False,
type="style",
val_types="array_like of value-color pairs | "
"'Greys' | 'Greens' | 'Bluered' | 'Hot' | "
"'Picnic' | 'Portland' | 'Jet' | 'RdBu' | 'Blackbody' | "
"'Earth' | 'Electric' | 'YIOrRd' | 'YIGnBu'",
description="The color scale. The strings are pre-defined color "
"scales. For custom color scales, define a list of "
"color-value pairs, where the first element of the pair "
"corresponds to a normalized value of z from 0-1, "
"i.e. (z-zmin)/ (zmax-zmin), and the second element of pair "
"corresponds to a color.",
examples=["Greys",
[[0, "rgb(0,0,0)"],
[0.5, "rgb(65, 182, 196)"],
[1, "rgb(255,255,255)"]]
]
)
# $shortcut-zauto
drop_zauto=dict(
required=False,
type='style',
val_types=val_types['bool'],
description="Toggle whether or not the default values "
"of 'zmax' and 'zmax' can be overwritten."
)
# $shortcut-zminmax | $shortcut-zmin | $shortcut-zmax
def make_zminmax(min_or_max):
_required=False
_type='style'
_val_types=val_types['number']()
S={'min': 'minimum', 'max': 'maximum'}
s=S[min_or_max]
_description=''.join(["The value used as the {S0} in the color scale ",
"normalization in 'scl'. ",
"The default value is the {S0} of the ",
"'z' data values."
]).format(S0=s)
return output(_required,_type,_val_types,_description)
# $shortcut-reversescl
drop_reversescl=dict(
required=False,
type='style',
val_types=val_types['bool'],
description="Toggle whether or not the color scale will be reversed."
)
# $shortcut-showscale
drop_showscale=dict(
required=False,
type='style',
val_types=val_types['bool'],
description="Toggle whether or not the color scale associated with "
"this mapping will be shown alongside the figure."
)
# $shortcuts-2d-specs-more
# $shortcut-zsmooth # TO DO! Describe the 2 algorithms
drop_zsmooth=dict(
required=False,
type='style',
val_types=" False | 'best' | 'fast' ",
description="Choose between algorithms ('best' or 'fast') "
"to smooth data linked to 'z'. "
"The default value is False "
"corresponding to no smoothing."
)
# $shortcut-autocontour
drop_autocontour=dict(
required=False,
type='style',
val_types=val_types['bool'],
description="Toggle whether or not the contour parameters are picked "
"automatically by Plotly. "
"If False, declare the contours parameters "
"in the Contours object."
)
# $shortcut-ncontours
drop_ncontours=dict(
required=False,
type='style',
val_types=val_types['number'](gt=1),
description="Specifies the number of contours lines "
"in the contour plot. "
"No need to set 'autocontour' to False for 'ncontours' "
"to apply."
)
# $shortcut-contours
drop_contours=dict(
required=False,
type='object',
val_types=val_types['object'],
description="A dictionary-like object defining the parameters of "
"the contours of this trace."
)
# $shortcuts-color
# $example-color
examples_color = ["'green'", "'rgb(0, 255, 0)'",
"'rgba(0, 255, 0, 0.3)'",
"'hsl(120,100%,50%)'",
"'hsla(120,100%,50%,0.3)'"]
# $shortcut-color
def make_color(obj):
_required=False
_type='style'
if obj=='marker':
_val_types=val_types['color_array']
else:
_val_types=val_types['color']
_description=dict(
marker="Sets the color of the face of the marker object. "
"If 'color' is linked to a list or an array of numbers, "
"color values are mapped to individual marker points "
"in the same order as in the data lists or arrays. "
"To set the color of the marker's bordering line, "
"use the 'line' key in Marker.",
line="Sets the color of the line object. "
"If linked within 'marker', sets the color of the marker's "
"bordering line. "
"If linked within, 'contours', sets the color of the "
"contour lines.",
font="Sets the color of the font. "
"If linked in the first level of the layout object, set the "
"color of the global font.",
error="Sets the color of the error bars."
)
_streamable=True
return output(_required,_type,_val_types,_description[obj],
streamable=_streamable,examples=examples_color)
# $shortcut-fillcolor
def make_fillcolor(obj):
_required=False
_type='style'
_val_types=val_types['color']
_description=dict(
scatter="Sets the color that will appear "
"in the specified fill area (set in 'fill'). "
"Has no effect if 'fill' is set to 'none'.",
box="Sets the color of the box interior."
)
return output(_required,_type,_val_types,_description[obj],
examples=examples_color)
# $shortcut-outlinecolor
def make_outlinecolor(obj):
_required=False
_type='style'
_val_types=val_types['color']
_description=dict(
font="For polar chart only. Sets the color of the text's outline.",
colorbar="The color of the outline surrounding this colorbar."
)
return output(_required,_type,_val_types,_description[obj],
examples=examples_color)
# $shortcut-bgcolor
def make_bgcolor(obj):
_required=False
_type='style'
_val_types=val_types['color']
_description=dict(
legend="Sets the background (bg) color for the legend.",
colorbar="Sets the background (bg) color for this colorbar.",
annotation="Sets the background (bg) color for this annotation."
)
return output(_required,_type,_val_types,_description[obj],
examples=examples_color)
# $shortcut-bordercolor
def make_bordercolor(obj):
_required=False
_type='style'
_val_types=val_types['color']
_description=dict(
legend="Sets the enclosing border color for the legend.",
colorbar="Sets the color of the enclosing boarder of this colorbar.",
annotation="The color of the enclosing boarder of this annotation."
)
return output(_required,_type,_val_types,_description[obj],
examples=examples_color)
# $shortcuts-dimensions
# $shortcut-size
def make_size(obj, x_or_y=False):
_required=False
_type=dict(
marker='style',
font='style',
bins='plot_info',
contours='plot_info'
)