Skip to content

Commit b6833c1

Browse files
committed
test color changes
1 parent b5cc034 commit b6833c1

File tree

1 file changed

+58
-17
lines changed

1 file changed

+58
-17
lines changed

doc/python/colors-fonts.md

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@ jupyter:
2626
display_as: file_settings
2727
language: python
2828
layout: base
29-
name: Supported Colors and Fonts
30-
order: 40
29+
name: Changes in Version 6
30+
order: 8
3131
page_type: example_index
3232
permalink: python/colors-fonts/
3333
thumbnail: null
3434
---
3535

3636
# Supported Colors and Fonts
3737

38-
38+
The following are supported colors in Plotly.
3939

4040
```python hide_code=true
41+
import plotly.graph_objects as go
42+
import pandas as pd
43+
4144
supported_colors = ["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure",
4245
"beige", "bisque", "black", "blanchedalmond", "blue",
4346
"blueviolet", "brown", "burlywood", "cadetblue",
@@ -73,20 +76,58 @@ supported_colors = ["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure",
7376
"springgreen", "steelblue", "tan", "teal", "thistle", "tomato",
7477
"turquoise", "violet", "wheat", "white", "whitesmoke",
7578
"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-
```
8979

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
91130

131+
fig = display_colors_as_shapes(supported_colors)
132+
fig.show()
92133
```

0 commit comments

Comments
 (0)