@@ -26,18 +26,21 @@ jupyter:
26
26
display_as : file_settings
27
27
language : python
28
28
layout : base
29
- name : Supported Colors and Fonts
30
- order : 40
29
+ name : Changes in Version 6
30
+ order : 8
31
31
page_type : example_index
32
32
permalink : python/colors-fonts/
33
33
thumbnail : null
34
34
---
35
35
36
36
# Supported Colors and Fonts
37
37
38
-
38
+ The following are supported colors in Plotly.
39
39
40
40
``` python hide_code=true
41
+ import plotly.graph_objects as go
42
+ import pandas as pd
43
+
41
44
supported_colors = [" aliceblue" , " antiquewhite" , " aqua" , " aquamarine" , " azure" ,
42
45
" beige" , " bisque" , " black" , " blanchedalmond" , " blue" ,
43
46
" blueviolet" , " brown" , " burlywood" , " cadetblue" ,
@@ -73,20 +76,58 @@ supported_colors = ["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure",
73
76
" springgreen" , " steelblue" , " tan" , " teal" , " thistle" , " tomato" ,
74
77
" turquoise" , " violet" , " wheat" , " white" , " whitesmoke" ,
75
78
" yellow" , " yellowgreen" ]
76
- ```
77
-
78
- ``` python hide_code=true
79
- from IPython.display import HTML , display
80
-
81
- def show_color (color_name ):
82
- display(HTML(f ' <div style="background-color: { color_name} ; width:100px; height:50px; border:1px solid black"></div> ' ))
83
-
84
- # Example usage
85
- for color in supported_colors:
86
- print (color)
87
- show_color(color)
88
- ```
89
79
90
- ``` python
80
+ def display_colors_as_shapes (color_names ):
81
+ fig = go.Figure()
82
+
83
+ # Add a colored rectangle for each color name
84
+ for i, color in enumerate (color_names):
85
+ # Position rectangles in a grid
86
+ row, col = i // 5 , i % 5
87
+ x0, y0 = col * 1.2 , - row * 1.2
88
+
89
+ # Add the colored rectangle
90
+ fig.add_shape(
91
+ type = " rect" ,
92
+ x0 = x0, y0 = y0,
93
+ x1 = x0+ 1 , y1 = y0+ 1 ,
94
+ fillcolor = color,
95
+ line = dict (color = " black" , width = 1 ),
96
+ )
97
+
98
+ fig.add_annotation(
99
+ x = x0+ 0.5 , y = y0- 0.1 ,
100
+ text = color,
101
+ showarrow = False ,
102
+ font = dict (size = 10 )
103
+ )
104
+
105
+ height = ((len (color_names) // 5 ) + (1 if len (color_names) % 5 else 0 )) * 120
106
+
107
+ fig.update_layout(
108
+ height = height,
109
+ width = 800 ,
110
+ showlegend = False ,
111
+ plot_bgcolor = ' rgba(0,0,0,0)' ,
112
+ margin = dict (l = 50 , r = 50 , t = 50 , b = 50 ),
113
+ xaxis = dict (
114
+ showgrid = False ,
115
+ zeroline = False ,
116
+ showticklabels = False ,
117
+ range = [- 0.5 , 6 ]
118
+ ),
119
+ yaxis = dict (
120
+ showgrid = False ,
121
+ zeroline = False ,
122
+ showticklabels = False ,
123
+ scaleanchor = " x" ,
124
+ scaleratio = 1 ,
125
+ range = [- ((len (color_names) // 5 ) + 1 ) * 1.2 , 1.5 ]
126
+ )
127
+ )
128
+
129
+ return fig
91
130
131
+ fig = display_colors_as_shapes(supported_colors)
132
+ fig.show()
92
133
```
0 commit comments