Skip to content

Commit a27e2a9

Browse files
committed
Update static-image-export.md
1 parent 41d72f0 commit a27e2a9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

doc/python/static-image-export.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,44 @@ fig.write_image("fig1", format="png")
149149
~~~
150150

151151

152+
<!-- #region -->
153+
### Write Multiple Images
154+
155+
*Kaleido v1 and later*
156+
157+
`plotly.io` provides a `write_images` function for writing multiple figures to images. Using `write_images` is faster than calling `fig.write_image` multiple times.
158+
159+
`write_images` takes a list of figure objects or dicts representing figures as its first argument, `fig`. The second argument `file` is a list of paths to export to. These paths can be specified as `str`s or [`pathlib.Path` objects](https://docs.python.org/3/library/pathlib.html).
160+
161+
~~~python
162+
import plotly.graph_objects as go
163+
import plotly.express as px
164+
import plotly.io as pio
165+
166+
167+
fig1 = go.Figure(
168+
data=go.Scatter(x=[1, 2, 3], y=[4, 5, 6], mode='lines+markers'),
169+
layout=go.Layout(title='Line Chart')
170+
)
171+
172+
fig2 = go.Figure(
173+
data=go.Bar(x=['A', 'B', 'C'], y=[10, 5, 15]),
174+
layout=go.Layout(title='Bar Chart')
175+
)
176+
177+
fig3 = px.pie(
178+
values=[30, 20, 10, 40],
179+
names=['A', 'B', 'C', 'D'],
180+
title='Pie Chart'
181+
)
182+
183+
pio.write_images(
184+
fig=[fig1, fig2, fig3],
185+
file=['export_images/line_chart.png', 'export_images/bar_chart.png', 'export_images/pie_chart.png']
186+
)
187+
~~~
188+
189+
<!-- #endregion -->
152190

153191
## Get Image as Bytes
154192

0 commit comments

Comments
 (0)