@@ -46,7 +46,7 @@ fig = go.Figure([
|
46 | 46 | y=[20, 14, 25, 16],
|
47 | 47 | name='Primary Product',
|
48 | 48 | # Named CSS color
|
49 |
| -marker_color='lightblue' |
| 49 | +marker_color='indianred' |
50 | 50 | )
|
51 | 51 | ])
|
52 | 52 |
|
@@ -95,45 +95,54 @@ supported_colors = ["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure",
|
95 | 95 | "turquoise", "violet", "wheat", "white", "whitesmoke",
|
96 | 96 | "yellow", "yellowgreen"]
|
97 | 97 |
|
98 |
| -fig = go.Figure(layout=dict(title="Supported CSS Colors in Plotly.py")) |
99 |
| - |
100 |
| -for i, color in enumerate(supported_colors): |
101 |
| -row, col = i // 5, i % 5 |
102 |
| -x0, y0 = col * 1.2, -row * 1.2 |
| 98 | +def display_colors_as_shapes(color_names): |
| 99 | +fig = go.Figure(layout=dict(title="Supported CSS Colors in Plotly.py")) |
103 | 100 |
|
104 |
| -fig.add_shape( |
105 |
| -type="rect", |
106 |
| -x0=x0, y0=y0, |
107 |
| -x1=x0+1, y1=y0+1, |
108 |
| -fillcolor=color, |
109 |
| -line=dict(color="black", width=0.1), |
110 |
| -) |
| 101 | +for i, color in enumerate(color_names): |
| 102 | +row, col = i // 5, i % 5 |
| 103 | +x0, y0 = col * 1.2, -row * 1.2 |
| 104 | + |
| 105 | +fig.add_shape( |
| 106 | +type="rect", |
| 107 | +x0=x0, y0=y0, |
| 108 | +x1=x0+1, y1=y0+1, |
| 109 | +fillcolor=color, |
| 110 | +line=dict(color="black", width=1), |
| 111 | +) |
| 112 | + |
| 113 | +fig.add_annotation( |
| 114 | +x=x0+0.5, y=y0-0.1, |
| 115 | +text=color, |
| 116 | +showarrow=False, |
| 117 | +font=dict(size=10) |
| 118 | +) |
111 | 119 |
|
112 |
| -fig.add_annotation( |
113 |
| -x=x0+0.5, y=y0-0.1, |
114 |
| -text=color, |
115 |
| -showarrow=False, |
116 |
| -font=dict(size=10) |
117 |
| -) |
118 |
| - |
119 |
| -fig.update_layout( |
120 |
| -height=((len(supported_colors) // 5) + (1 if len(supported_colors) % 5 else 0)) * 120, |
121 |
| -margin=dict(l=0, r=0, t=50, b=0), |
122 |
| -showlegend=False, |
123 |
| -plot_bgcolor='rgba(0,0,0,0)', |
124 |
| -xaxis=dict( |
125 |
| -showticklabels=False, |
126 |
| -range=[-0.5, 6] |
127 |
| -), |
128 |
| -yaxis=dict( |
129 |
| -showticklabels=False, |
130 |
| -range=[-((len(supported_colors) // 5) + 1) * 1.2, 1.5] |
| 120 | +height = ((len(color_names) // 5) + (1 if len(color_names) % 5 else 0)) * 120 |
| 121 | + |
| 122 | +fig.update_layout( |
| 123 | +height=height, |
| 124 | +width=800, |
| 125 | +showlegend=False, |
| 126 | +plot_bgcolor='rgba(0,0,0,0)', |
| 127 | +margin=dict(l=50, r=50, t=50, b=50), |
| 128 | +xaxis=dict( |
| 129 | +showgrid=False, |
| 130 | +zeroline=False, |
| 131 | +showticklabels=False, |
| 132 | +range=[-0.5, 6] |
| 133 | +), |
| 134 | +yaxis=dict( |
| 135 | +showgrid=False, |
| 136 | +zeroline=False, |
| 137 | +showticklabels=False, |
| 138 | +scaleanchor="x", |
| 139 | +scaleratio=1, |
| 140 | +range=[-((len(color_names) // 5) + 1) * 1.2, 1.5] |
| 141 | +) |
131 | 142 | )
|
132 |
| -) |
| 143 | + |
| 144 | +return fig |
133 | 145 |
|
| 146 | +fig = display_colors_as_shapes(supported_colors) |
134 | 147 | fig.show()
|
135 | 148 | ```
|
136 |
| - |
137 |
| -```python |
138 |
| - |
139 |
| -``` |
|
0 commit comments