Skip to content

Commit 3465529

Browse files
committed
add pattern path example
1 parent 4911830 commit 3465529

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

doc/python/pattern-hatching-texture.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.6
9+
jupytext_version: 1.17.2
1010
kernelspec:
1111
display_name: Python 3 (ipykernel)
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.10.11
23+
version: 3.9.0
2424
plotly:
2525
description: How to use patterns (also known as hatching or texture) with bar
2626
charts.
@@ -150,6 +150,55 @@ fig.add_trace(go.Bar(x=["a","b"], y=[2,3], marker_pattern_shape="+"))
150150
fig.show()
151151
```
152152

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+
153202
#### Reference
154203

155204
See https://plotly.com/python/reference/bar/ for more information and chart attribute options!

0 commit comments

Comments
 (0)