@@ -47,3 +47,113 @@ def _swatches(module_names, module_contents, template=None):
47
47
margin = dict (b = 10 ),
48
48
),
49
49
)
50
+
51
+
52
+ def _swatches_continuous (module_names , module_contents , template = None ):
53
+ """
54
+ Parameters
55
+ ----------
56
+ template : str or dict or plotly.graph_objects.layout.Template instance
57
+ The figure template name or definition.
58
+
59
+ Returns
60
+ -------
61
+ fig : graph_objects.Figure containing the displayed image
62
+ A `Figure` object. This figure demonstrates the color scales and
63
+ sequences in this module, as stacked bar charts.
64
+ """
65
+ import plotly .graph_objs as go
66
+ from plotly .express ._core import apply_default_cascade
67
+
68
+ args = dict (template = template )
69
+ apply_default_cascade (args )
70
+
71
+ sequences = [
72
+ (k , v )
73
+ for k , v in module_contents .items ()
74
+ if not (k .startswith ("_" ) or k .startswith ("swatches" ) or k .endswith ("_r" ))
75
+ ]
76
+
77
+ n = 100
78
+
79
+ return go .Figure (
80
+ data = [
81
+ go .Bar (
82
+ orientation = "h" ,
83
+ y = [name ] * n ,
84
+ x = [1 ] * n ,
85
+ marker = dict (color = list (range (n )), colorscale = name , line_width = 0 ),
86
+ )
87
+ for name , colors in reversed (sequences )
88
+ ],
89
+ layout = dict (
90
+ title = "plotly.colors." + module_names .split ("." )[- 1 ],
91
+ barmode = "stack" ,
92
+ barnorm = "fraction" ,
93
+ bargap = 0.3 ,
94
+ showlegend = False ,
95
+ xaxis = dict (range = [- 0.02 , 1.02 ], showticklabels = False , showgrid = False ),
96
+ height = max (600 , 40 * len (sequences )),
97
+ width = 500 ,
98
+ template = args ["template" ],
99
+ margin = dict (b = 10 ),
100
+ ),
101
+ )
102
+
103
+
104
+ def _swatches_cyclical (module_names , module_contents , template = None ):
105
+ """
106
+ Parameters
107
+ ----------
108
+ template : str or dict or plotly.graph_objects.layout.Template instance
109
+ The figure template name or definition.
110
+
111
+ Returns
112
+ -------
113
+ fig : graph_objects.Figure containing the displayed image
114
+ A `Figure` object. This figure demonstrates the color scales and
115
+ sequences in this module, as polar bar charts.
116
+ """
117
+ import plotly .graph_objects as go
118
+ from plotly .subplots import make_subplots
119
+ from plotly .express ._core import apply_default_cascade
120
+
121
+ args = dict (template = template )
122
+ apply_default_cascade (args )
123
+
124
+ rows = 2
125
+ cols = 4
126
+ scales = [
127
+ (k , v )
128
+ for k , v in module_contents .items ()
129
+ if not (k .startswith ("_" ) or k .startswith ("swatches" ) or k .endswith ("_r" ))
130
+ ]
131
+ names = [name for name , colors in scales ]
132
+ fig = make_subplots (
133
+ rows = rows ,
134
+ cols = cols ,
135
+ subplot_titles = names ,
136
+ specs = [[{"type" : "polar" }] * cols ] * rows ,
137
+ )
138
+
139
+ for i , (name , scale ) in enumerate (scales ):
140
+ fig .add_trace (
141
+ go .Barpolar (
142
+ r = [1 ] * int (360 / 5 ),
143
+ theta = list (range (0 , 360 , 5 )),
144
+ marker_color = list (range (0 , 360 , 5 )),
145
+ marker_cmin = 0 ,
146
+ marker_cmax = 360 ,
147
+ marker_colorscale = name ,
148
+ name = name ,
149
+ ),
150
+ row = int (i / cols ) + 1 ,
151
+ col = i % cols + 1 ,
152
+ )
153
+ fig .update_traces (width = 5.2 , marker_line_width = 0 , base = 0.5 , showlegend = False )
154
+ fig .update_polars (angularaxis_visible = False , radialaxis_visible = False )
155
+ fig .update_layout (
156
+ title = "plotly.colors." + module_names .split ("." )[- 1 ], template = args ["template" ]
157
+ )
158
+ return fig
159
+
0 commit comments