6
6
extension : .md
7
7
format_name : markdown
8
8
format_version : ' 1.3'
9
- jupytext_version : 1.14.6
9
+ jupytext_version : 1.17.2
10
10
kernelspec :
11
11
display_name : Python 3 (ipykernel)
12
12
language : python
@@ -20,7 +20,7 @@ jupyter:
20
20
name : python
21
21
nbconvert_exporter : python
22
22
pygments_lexer : ipython3
23
- version : 3.10.11
23
+ version : 3.9.0
24
24
plotly :
25
25
description : How to use patterns (also known as hatching or texture) with bar
26
26
charts.
@@ -150,6 +150,55 @@ fig.add_trace(go.Bar(x=["a","b"], y=[2,3], marker_pattern_shape="+"))
150
150
fig.show()
151
151
```
152
152
153
+ ### Patterns Using SVG Paths
154
+
155
+ * New in 6.3*
156
+
157
+ You can make custom patterns for graphs by using an SVG path. Set ` marker.pattern.path ` to the SVG path to use:
158
+
159
+ ``` python
160
+ import plotly.graph_objects as go
161
+ import plotly.data
162
+
163
+ df = plotly.data.gapminder().query(" year == 2007 and continent == 'Europe'" ).copy()
164
+ df[' gdp' ] = df[' gdpPercap' ] * df[' pop' ]
165
+ df = df.sort_values(' gdp' , ascending = False ).head(4 )
166
+
167
+ fig = go.Figure(
168
+ data = [go.Bar(
169
+ x = df[' country' ],
170
+ y = df[' gdp' ],
171
+ marker = dict (
172
+ color = [" lightsteelblue" , " mistyrose" , " palegreen" , " thistle" ],
173
+ pattern = dict (
174
+ path = [
175
+ " M0,0H4V4H0Z" ,
176
+ " M0,0H6V6Z" ,
177
+ " M0,0V4H4Z" ,
178
+ " M0,0C0,2,4,2,4,4C4,6,0,6,0,8H2C2,6,6,6,6,4C6,2,2,2,2,0Z"
179
+ ],
180
+ fgcolor = [" midnightblue" , " crimson" , " seagreen" , " indigo" ],
181
+ bgcolor = [" mintcream" , " lavenderblush" , " azure" , " honeydew" ],
182
+ size = 20 ,
183
+ solidity = 0.7
184
+ )
185
+ ),
186
+ name = " GDP (2007)"
187
+ )],
188
+ layout = dict (
189
+ title = " Top 4 European Countries by GDP (Gapminder 2007) with Custom SVG Path Patterns" ,
190
+ xaxis_title = " Country" ,
191
+ yaxis_title = " GDP (USD)" ,
192
+ yaxis_tickformat = " $.2s" ,
193
+ width = 800 ,
194
+ height = 500 ,
195
+ bargap = 0.3
196
+ )
197
+ )
198
+
199
+ fig.show()
200
+ ```
201
+
153
202
#### Reference
154
203
155
204
See https://plotly.com/python/reference/bar/ for more information and chart attribute options!
0 commit comments