@@ -47,3 +47,115 @@ def _swatches(module_names, module_contents, template=None):
4747 margin = dict (b = 10 ),
4848 ),
4949 )
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+ customdata = [(x + 1 ) / n for x in range (n )],
86+ marker = dict (color = list (range (n )), colorscale = name , line_width = 0 ),
87+ hovertemplate = "%{customdata}" ,
88+ name = name ,
89+ )
90+ for name , colors in reversed (sequences )
91+ ],
92+ layout = dict (
93+ title = "plotly.colors." + module_names .split ("." )[- 1 ],
94+ barmode = "stack" ,
95+ barnorm = "fraction" ,
96+ bargap = 0.3 ,
97+ showlegend = False ,
98+ xaxis = dict (range = [- 0.02 , 1.02 ], showticklabels = False , showgrid = False ),
99+ height = max (600 , 40 * len (sequences )),
100+ width = 500 ,
101+ template = args ["template" ],
102+ margin = dict (b = 10 ),
103+ ),
104+ )
105+
106+
107+ def _swatches_cyclical (module_names , module_contents , template = None ):
108+ """
109+ Parameters
110+ ----------
111+ template : str or dict or plotly.graph_objects.layout.Template instance
112+ The figure template name or definition.
113+
114+ Returns
115+ -------
116+ fig : graph_objects.Figure containing the displayed image
117+ A `Figure` object. This figure demonstrates the color scales and
118+ sequences in this module, as polar bar charts.
119+ """
120+ import plotly .graph_objects as go
121+ from plotly .subplots import make_subplots
122+ from plotly .express ._core import apply_default_cascade
123+
124+ args = dict (template = template )
125+ apply_default_cascade (args )
126+
127+ rows = 2
128+ cols = 4
129+ scales = [
130+ (k , v )
131+ for k , v in module_contents .items ()
132+ if not (k .startswith ("_" ) or k .startswith ("swatches" ) or k .endswith ("_r" ))
133+ ]
134+ names = [name for name , colors in scales ]
135+ fig = make_subplots (
136+ rows = rows ,
137+ cols = cols ,
138+ subplot_titles = names ,
139+ specs = [[{"type" : "polar" }] * cols ] * rows ,
140+ )
141+
142+ for i , (name , scale ) in enumerate (scales ):
143+ fig .add_trace (
144+ go .Barpolar (
145+ r = [1 ] * int (360 / 5 ),
146+ theta = list (range (0 , 360 , 5 )),
147+ marker_color = list (range (0 , 360 , 5 )),
148+ marker_cmin = 0 ,
149+ marker_cmax = 360 ,
150+ marker_colorscale = name ,
151+ name = name ,
152+ ),
153+ row = int (i / cols ) + 1 ,
154+ col = i % cols + 1 ,
155+ )
156+ fig .update_traces (width = 5.2 , marker_line_width = 0 , base = 0.5 , showlegend = False )
157+ fig .update_polars (angularaxis_visible = False , radialaxis_visible = False )
158+ fig .update_layout (
159+ title = "plotly.colors." + module_names .split ("." )[- 1 ], template = args ["template" ]
160+ )
161+ return fig
0 commit comments