Skip to content

Commit 1d0ccf3

Browse files
committed
Updated orca management notebook
1 parent 31945aa commit 1d0ccf3

File tree

2 files changed

+45
-69
lines changed

2 files changed

+45
-69
lines changed

notebooks/orca-management.md

Lines changed: 44 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.1'
9-
jupytext_version: 1.1.1
9+
jupytext_version: 1.1.6
1010
kernelspec:
11-
display_name: Python 2
11+
display_name: Python 3
1212
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
1424
plotly:
1525
description: This section covers the low-level details of how plotly.py uses orca
1626
to perform static image generation.
@@ -24,24 +34,9 @@ jupyter:
2434
permalink: python/orca-management/
2535
thumbnail: thumbnail/orca-management.png
2636
title: Orca Management | Plotly
37+
v4upgrade: true
2738
---
2839

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-
4540
### Overview
4641
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.
4742

@@ -55,49 +50,46 @@ By default, plotly.py launches the orca server process the first time an image e
5550
Now let's create a simple scatter plot with 100 random points of variying color and size.
5651

5752
```python
58-
import plotly.graph_objs as go
59-
import plotly.io as pio
53+
import plotly.graph_objects as go
6054

61-
import os
6255
import numpy as np
63-
```
6456

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
7258
N = 100
7359
x = np.random.rand(N)
7460
y = np.random.rand(N)
7561
colors = np.random.rand(N)
76-
sz = np.random.rand(N)*30
62+
sz = np.random.rand(N) * 30
7763

64+
# Build and display figure
7865
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()
8878
```
8979

9080
### config
9181
We can use the `plotly.io.orca.config` object to view the current orca configuration settings.
9282

9383
```python
84+
import plotly.io as pio
9485
pio.orca.config
9586
```
9687

9788
### status
9889
We can use the `plotly.io.orca.status` object to see the current status of the orca server
9990

10091
```python
92+
import plotly.io as pio
10193
pio.orca.status
10294
```
10395

@@ -107,22 +99,26 @@ Let's export this figure as an SVG image, and record the runtime.
10799

108100
```python
109101
%%time
110-
img_bytes = pio.to_image(fig, format='svg')
102+
import plotly.io as pio
111103
from IPython.display import SVG, display
104+
img_bytes = pio.to_image(fig, format="svg")
112105
display(SVG(img_bytes))
113106
```
114107

115108
By checking the `status` object again, we see that the orca server is now running
116109

117110
```python
111+
import plotly.io as pio
118112
pio.orca.status
119113
```
120114

121115
Let's perform this same export operation again, now that the server is already running.
122116

123117
```python
124118
%%time
125-
img_bytes = pio.to_image(fig, format='svg')
119+
import plotly.io as pio
120+
from IPython.display import SVG, display
121+
img_bytes = pio.to_image(fig, format="svg")
126122
display(SVG(img_bytes))
127123
```
128124

@@ -135,16 +131,19 @@ By default, the orca server will continue to run until the main Python process e
135131
Regardless of how the server is shut down, it will start back up automatically the next time an image export operation is performed.
136132

137133
```python
134+
import plotly.io as pio
138135
pio.orca.shutdown_server()
139136
pio.orca.status
140137
```
141138

142139
```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")
144142
display(SVG(img_bytes))
145143
```
146144

147145
```python
146+
import plotly.io as pio
148147
pio.orca.status
149148
```
150149

@@ -202,35 +201,12 @@ In addition to the `executable` property, the `plotly.io.orca.config` object can
202201
- **`default_width`**: The default pixel width to use on image export.
203202
- **`default_height`**: The default pixel height to use on image export.
204203
- **`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"`.
206205
- **`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.
207206
- **`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).
208207
- **`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.
209209

210210

211211
### Saving Configuration Settings
212212
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.
213-
214-
```python
215-
from IPython.display import display, HTML
216-
217-
display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
218-
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))
219-
220-
! pip install git+https://github.com/plotly/publisher.git --upgrade
221-
import publisher
222-
publisher.publish(
223-
'orca-management.ipynb', 'python/orca-management/', 'Orca Management | plotly',
224-
'This section covers the low-level details of how plotly.py uses orca to perform static image generation.',
225-
title = 'Orca Management | Plotly',
226-
name = 'Orca Management',
227-
thumbnail='thumbnail/orca-management.png',
228-
language='python',
229-
uses_plotly_offline=True,
230-
has_thumbnail='true', display_as='file_settings', order=1.5,
231-
ipynb='~notebook_demo/253')
232-
```
233-
234-
```python
235-
236-
```

notebooks/static-image-export.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ $ pip install psutil requests
7474
Now let's create a simple scatter plot with 100 random points of variying color and size.
7575

7676
```python
77-
import plotly.graph_objs as go
77+
import plotly.graph_objects as go
7878
import numpy as np
7979

8080
N = 100

0 commit comments

Comments
 (0)