You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: notebooks/orca-management.md
+44-68Lines changed: 44 additions & 68 deletions
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,21 @@ jupyter:
6
6
extension: .md
7
7
format_name: markdown
8
8
format_version: '1.1'
9
-
jupytext_version: 1.1.1
9
+
jupytext_version: 1.1.6
10
10
kernelspec:
11
-
display_name: Python 2
11
+
display_name: Python 3
12
12
language: python
13
-
name: python2
13
+
name: python3
14
+
language_info:
15
+
codemirror_mode:
16
+
name: ipython
17
+
version: 3
18
+
file_extension: .py
19
+
mimetype: text/x-python
20
+
name: python
21
+
nbconvert_exporter: python
22
+
pygments_lexer: ipython3
23
+
version: 3.7.3
14
24
plotly:
15
25
description: This section covers the low-level details of how plotly.py uses orca
16
26
to perform static image generation.
@@ -24,24 +34,9 @@ jupyter:
24
34
permalink: python/orca-management/
25
35
thumbnail: thumbnail/orca-management.png
26
36
title: Orca Management | Plotly
37
+
v4upgrade: true
27
38
---
28
39
29
-
#### New to Plotly?
30
-
Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).
31
-
<br>You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).
32
-
<br>We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!
33
-
34
-
### Version Check
35
-
Note: The static image export API is available in version <b>3.2.0.+</b><br>
36
-
37
-
```python
38
-
import plotly
39
-
import plotly.graph_objs as go
40
-
from plotly.offline import iplot, init_notebook_mode
41
-
42
-
plotly.__version__
43
-
```
44
-
45
40
### Overview
46
41
This section covers the lower-level details of how plotly.py uses orca to perform static image generation. Please refer to the [Static Image Export](../static-image-export/) section for general information on creating static images from plotly.py figures.
47
42
@@ -55,49 +50,46 @@ By default, plotly.py launches the orca server process the first time an image e
55
50
Now let's create a simple scatter plot with 100 random points of variying color and size.
56
51
57
52
```python
58
-
import plotly.graph_objs as go
59
-
import plotly.io as pio
53
+
import plotly.graph_objects as go
60
54
61
-
import os
62
55
import numpy as np
63
-
```
64
56
65
-
We'll configure the notebook for use in [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode
66
-
67
-
```python
68
-
init_notebook_mode(connected=True)
69
-
```
70
-
71
-
```python
57
+
# Generate scatter plot data
72
58
N =100
73
59
x = np.random.rand(N)
74
60
y = np.random.rand(N)
75
61
colors = np.random.rand(N)
76
-
sz = np.random.rand(N)*30
62
+
sz = np.random.rand(N)*30
77
63
64
+
# Build and display figure
78
65
fig = go.Figure()
79
-
fig.add_scatter(x=x,
80
-
y=y,
81
-
mode='markers',
82
-
marker={'size': sz,
83
-
'color': colors,
84
-
'opacity': 0.6,
85
-
'colorscale': 'Viridis'
86
-
});
87
-
iplot(fig)
66
+
fig.add_trace(go.Scatter(
67
+
x=x,
68
+
y=y,
69
+
mode="markers",
70
+
marker={"size": sz,
71
+
"color": colors,
72
+
"opacity": 0.6,
73
+
"colorscale": "Viridis"
74
+
}
75
+
))
76
+
77
+
fig.show()
88
78
```
89
79
90
80
### config
91
81
We can use the `plotly.io.orca.config` object to view the current orca configuration settings.
92
82
93
83
```python
84
+
import plotly.io as pio
94
85
pio.orca.config
95
86
```
96
87
97
88
### status
98
89
We can use the `plotly.io.orca.status` object to see the current status of the orca server
99
90
100
91
```python
92
+
import plotly.io as pio
101
93
pio.orca.status
102
94
```
103
95
@@ -107,22 +99,26 @@ Let's export this figure as an SVG image, and record the runtime.
107
99
108
100
```python
109
101
%%time
110
-
img_bytes = pio.to_image(fig, format='svg')
102
+
import plotly.io as pio
111
103
from IPython.display importSVG, display
104
+
img_bytes = pio.to_image(fig, format="svg")
112
105
display(SVG(img_bytes))
113
106
```
114
107
115
108
By checking the `status` object again, we see that the orca server is now running
116
109
117
110
```python
111
+
import plotly.io as pio
118
112
pio.orca.status
119
113
```
120
114
121
115
Let's perform this same export operation again, now that the server is already running.
122
116
123
117
```python
124
118
%%time
125
-
img_bytes = pio.to_image(fig, format='svg')
119
+
import plotly.io as pio
120
+
from IPython.display importSVG, display
121
+
img_bytes = pio.to_image(fig, format="svg")
126
122
display(SVG(img_bytes))
127
123
```
128
124
@@ -135,16 +131,19 @@ By default, the orca server will continue to run until the main Python process e
135
131
Regardless of how the server is shut down, it will start back up automatically the next time an image export operation is performed.
136
132
137
133
```python
134
+
import plotly.io as pio
138
135
pio.orca.shutdown_server()
139
136
pio.orca.status
140
137
```
141
138
142
139
```python
143
-
img_bytes = pio.to_image(fig, format='svg')
140
+
import plotly.io as pio
141
+
img_bytes = pio.to_image(fig, format="svg")
144
142
display(SVG(img_bytes))
145
143
```
146
144
147
145
```python
146
+
import plotly.io as pio
148
147
pio.orca.status
149
148
```
150
149
@@ -202,35 +201,12 @@ In addition to the `executable` property, the `plotly.io.orca.config` object can
202
201
-**`default_width`**: The default pixel width to use on image export.
203
202
-**`default_height`**: The default pixel height to use on image export.
204
203
-**`default_scale`**: The default image scale facor applied on image export.
205
-
-**`default_format`**: The default image format used on export. One of `'png'`, `'jpeg'`, `'webp'`, `'svg'`, `'pdf'`, or `'eps'`.
204
+
-**`default_format`**: The default image format used on export. One of `"png"`, `"jpeg"`, `"webp"`, `"svg"`, `"pdf"`, or `"eps"`.
206
205
-**`mathjax`**: Location of the MathJax bundle needed to render LaTeX characters. Defaults to a CDN location. If fully offline export is required, set this to a local MathJax bundle.
207
206
-**`topojson`**: Location of the topojson files needed to render choropleth traces. Defaults to a CDN location. If fully offline export is required, set this to a local directory containing the [Plotly.js topojson files](https://github.com/plotly/plotly.js/tree/master/dist/topojson).
208
207
-**`mapbox_access_token`**: Mapbox access token required to render `scattermapbox` traces.
208
+
-**`use_xvfb`**: Whether to call orca using [Xvfb](https://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml) on Linux. Xvfb is needed for orca to work in a Linux environment if an X11 display server is not available. By default, plotly.py will automatically use Xvfb if it is installed, and no active X11 display server is detected. This can be set to `True` to force the use of Xvfb, or it can be set to `False` to disable the use of Xvfb.
209
209
210
210
211
211
### Saving Configuration Settings
212
212
Configuration options can optionally be saved to the `~/.plotly/` directory by calling the `plotly.io.config.save()` method. Saved setting will be automatically loaded at the start of future sessions.
0 commit comments