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: doc/python/creating-and-updating-figures.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -39,11 +39,11 @@ jupyter:
39
39
40
40
### Representing Figures
41
41
42
-
The goal of the `plotly.py` package is to provide a pleasant Python interface for creating figure specifications which are displayed by the [`plotly.js`](https://plot.ly/javascript) JavaScript graphing library.
42
+
The goal of the plotly.py package is to provide a pleasant Python interface for creating figure specifications which are displayed by the [plotly.js](https://plot.ly/javascript) JavaScript graphing library.
43
43
44
-
In the context of the `plotly.js` library, a figure is specified by a declarative [JSON](https://www.json.org/json-en.html) data structure.
44
+
In the context of the plotly.js library, a figure is specified by a declarative [JSON](https://www.json.org/json-en.html) data structure.
45
45
46
-
Therefore, you should always keep in mind as you are creating and updating figures using the `plotly.py` package that its ultimate goal is to help users produce Python [dictionaries](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) that can be automatically [serialized](https://en.wikipedia.org/wiki/Serialization) into the JSON data structure that the `plotly.js` graphing library understands.
46
+
Therefore, you should always keep in mind as you are creating and updating figures using the plotly.py package that its ultimate goal is to help users produce Python [dictionaries](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) that can be automatically [serialized](https://en.wikipedia.org/wiki/Serialization) into the JSON data structure that the plotly.js graphing library understands.
47
47
48
48
#### Figures As Dictionaries
49
49
@@ -612,7 +612,7 @@ There are also `for_each_xaxis()` and `for_each_yaxis()` methods that are analog
612
612
613
613
### Other Update Methods
614
614
615
-
Figures created with the `plotly.graph_objects` module also support:
615
+
Figures created with the plotly.py graphing library also support:
616
616
- the `update_layout_images()` method in order to [update background layout images](/python/images/),
617
617
- `update_annotations()` in order to [update annotations](/python/text-and-annotations/#multiple-annotations),
618
618
- and `update-shapes()` in order to [update shapes](/python/shapes/).
Copy file name to clipboardExpand all lines: doc/python/renderers.md
+19-16Lines changed: 19 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -40,15 +40,15 @@ Plotly's Python graphing library, `plotly.py`, gives you a wide range of options
40
40
41
41
In general, there are three different approaches you can take in order to display figures:
42
42
43
-
1. Using the `renderers` framework in the context of a script or notebook
43
+
1. Using the renderers framework in the context of a script or notebook
44
44
2. Using [Dash](https://dash.plot.ly) in a web app context
45
45
3. Using a `FigureWidget` in an `ipywidgets` context
46
46
47
47
Each of these approaches is discussed below.
48
48
49
-
### Displaying Figures Using The `renderers` Framework
49
+
### Displaying Figures Using The renderers Framework
50
50
51
-
The `renderers` framework is a flexible approach for displaying `plotly.py` figures in a variety of contexts. To display a figure using the `renderers` framework, you call the `show()` method on a graph object figure, or pass the figure to the `plotly.io.show` function. With either approach, `plotly.py` will display the figure using the current default renderer(s).
51
+
The renderers framework is a flexible approach for displaying `plotly.py` figures in a variety of contexts. To display a figure using the renderers framework, you call the `.show()` method on a graph object figure, or pass the figure to the `plotly.io.show` function. With either approach, `plotly.py` will display the figure using the current default renderer(s).
52
52
53
53
```python
54
54
import plotly.graph_objects as go
@@ -59,7 +59,7 @@ fig = go.Figure(
59
59
fig.show()
60
60
```
61
61
62
-
In most situations, you can omit the call to `show()` and allow the figure to display itself.
62
+
In most situations, you can omit the call to `.show()` and allow the figure to display itself.
63
63
64
64
```python
65
65
import plotly.graph_objects as go
@@ -115,17 +115,17 @@ fig.show(renderer="svg")
115
115
In this section, we will describe the built-in renderers so that you can choose the one(s) that best suit your needs.
116
116
117
117
##### Interactive Renderers
118
-
Interactive renderers display figures using the Plotly.js JavaScript library and are fully interactive, supporting pan, zoom, hover tooltips, etc.
118
+
Interactive renderers display figures using the plotly.js JavaScript library and are fully interactive, supporting pan, zoom, hover tooltips, etc.
119
119
120
120
###### `notebook`
121
-
This renderer is intended for use in the classic [Jupyter Notebook](https://jupyter.org/install.html) (not JupyterLab). The full `plotly.js` JavaScript library bundle is added to the notebook the first time a figure is rendered, so this renderer will work without an Internet connection.
121
+
This renderer is intended for use in the classic [Jupyter Notebook](https://jupyter.org/install.html) (not JupyterLab). The full plotly.js JavaScript library bundle is added to the notebook the first time a figure is rendered, so this renderer will work without an Internet connection.
122
122
123
123
This renderer is a good choice for notebooks that will be exported to HTML files (Either using [nbconvert](https://nbconvert.readthedocs.io/en/latest/) or the "Download as HTML" menu action) because the exported HTML files will work without an Internet connection.
124
124
125
-
> Note: Adding the `plotly.js` bundle to the notebook adds a few megabytes to the notebook size. If you can count on always having an Internet connection, you may want to consider using the `notebook_connected` renderer if notebook size is a constraint.
125
+
> Note: Adding the plotly.js bundle to the notebook adds a few megabytes to the notebook size. If you can count on always having an Internet connection, you may want to consider using the `notebook_connected` renderer if notebook size is a constraint.
126
126
127
127
###### `notebook_connected`
128
-
This renderer is the same as `notebook` renderer, except the `plotly.js` JavaScript library bundle is loaded from an online CDN location. This saves a few megabytes in notebook size, but an Internet connection is required in order to display figures that are rendered this way.
128
+
This renderer is the same as `notebook` renderer, except the plotly.js JavaScript library bundle is loaded from an online CDN location. This saves a few megabytes in notebook size, but an Internet connection is required in order to display figures that are rendered this way.
129
129
130
130
This renderer is a good choice for notebooks that will be shared with [nbviewer](https://nbviewer.jupyter.org/) since users must have an active Internet connection to access nbviewer in the first place.
131
131
@@ -146,7 +146,7 @@ This renderer will open a figure in a browser tab using the default web browser.
146
146
These renderers are the same as the `browser` renderer, but they force the use of a particular browser.
147
147
148
148
###### `iframe` and `iframe_connected`
149
-
These renderers write figures out as standalone HTML files and then display [`iframe`](https://www.w3schools.com/html/html_iframe.asp) elements that reference these HTML files. The `iframe` renderer will include the `plotly.js` JavaScript bundle in each HTML file that is written, while the `iframe_connected` renderer includes only a reference to an online CDN location from which to load `plotly.js`. Consequently, the `iframe_connected` renderer outputs files that are smaller than the `iframe` renderer, but it requires an Internet connection while the `iframe` renderer can operate offline.
149
+
These renderers write figures out as standalone HTML files and then display [`iframe`](https://www.w3schools.com/html/html_iframe.asp) elements that reference these HTML files. The `iframe` renderer will include the plotly.js JavaScript bundle in each HTML file that is written, while the `iframe_connected` renderer includes only a reference to an online CDN location from which to load plotly.js. Consequently, the `iframe_connected` renderer outputs files that are smaller than the `iframe` renderer, but it requires an Internet connection while the `iframe` renderer can operate offline.
150
150
151
151
This renderer may be useful when working with notebooks than contain lots of large figures. When using the `notebook` or `notebook_connected` renderer, all of the data for all of the figures in a notebook are stored inline in the notebook itself. If this would result in a prohibitively large notebook size, an `iframe` or `iframe_connected` renderer could be used instead. With the `iframe` renderers, the figure data are stored in the individual HTML files rather than in the notebook itself, resulting in a smaller notebook size.
152
152
@@ -175,16 +175,16 @@ fig = go.Figure(
175
175
fig.show(renderer="png")
176
176
```
177
177
178
-
###### `pdf`
179
-
This renderer displays figures as static `.pdf` files. This is especially useful for notebooks that will be exported to `.pdf` files using the `LaTeX` export capabilities of `nbconvert`.
178
+
###### PDF
179
+
This renderer displays figures as static PDF files. This is especially useful for notebooks that will be exported to PDF files using the LaTeX export capabilities of [`nbconvert`](https://nbconvert.readthedocs.io/en/latest/).
180
180
181
181
##### Other Miscellaneous Renderers
182
182
183
-
###### `json`
183
+
###### JSON
184
184
In editors that support it (JupyterLab, nteract, and the Visual Studio Code notebook interface), this renderer displays the JSON representation of a figure in a collapsible interactive tree structure. This can be very useful for examining the structure of complex figures.
185
185
186
186
##### Multiple Renderers
187
-
You can specify that multiple renderers should be used by joining their names on `"+"` characters. This is useful when writing code that needs to support multiple contexts. For example, if a notebook specifies a default renderer string of `"notebook+plotly_mimetype+pdf"`then this notebook would be able to run in the classic Jupyter Notebook, in JupyterLab, and it would support being exported to `.pdf` using `nbconvert`.
187
+
You can specify that multiple renderers should be used by joining their names on `"+"` characters. This is useful when writing code that needs to support multiple contexts. For example, if a notebook specifies a default renderer string of `"notebook+plotly_mimetype+pdf"`then this notebook would be able to run in the classic Jupyter Notebook, in JupyterLab, and it would support being exported to PDF using `nbconvert`.
188
188
189
189
#### Customizing Built-In Renderers
190
190
Most built-in renderers have configuration options to customize their behavior. To view a description of a renderer, including its configuration options, access the renderer object using dictionary-style key lookup on the `plotly.io.renderers` configuration object and then display it. Here is an example of accessing and displaying the `png` renderer.
[Dash](https://dash.plot.ly) is a Python framework for building web applications, and it provides built-in support for displaying figures created with Plotly's graphing libraries. See the [Dash User Guide](https://dash.plot.ly/) for more information.
232
233
233
-
It is important to note that Dash does not use the renderers framework discussed above, so you should not use the `show()` figure method or the `plotly.io.show` function inside Dash applications.
234
+
It is important to note that Dash does not use the renderers framework discussed above, so you should not try to use the `.show()` figure method or the `plotly.io.show` function to render figures inside Dash applications.
234
235
235
-
Instead, pass your figure as the `figure` parameter to the `dcc.Graph` component.
236
+
Instead, pass your figure as the `figure` parameter to the [`dcc.Graph`](https://dash.plot.ly/dash-core-components/graph) component, which is part of the [Dash Core Components](https://dash.plot.ly/dash-core-components) library. The code below demonstrates how to do this.
236
237
237
-
```python
238
+
239
+
```python .noeval
238
240
import dash_core_components as dcc
239
241
import plotly.graph_objs as go
240
242
@@ -246,6 +248,7 @@ dcc.Graph(
246
248
)
247
249
```
248
250
251
+
249
252
## Displaying Figures Using `ipywidgets`
250
253
Plotly figures can be displayed in [ipywidgets](https://ipywidgets.readthedocs.io/en/stable/) contexts using `plotly.graph_objects.FigureWidget` objects. `FigureWidget` is a figure graph object (just like `plotly.graph_objects.Figure`), so you can add traces to it and update it just like a regular `Figure`. But `FigureWidget` is also an `ipywidgets` object, which means that you can display it alongside other `ipywidgets` to build user interfaces right in the notebook.
Copy file name to clipboardExpand all lines: doc/python/subplots.md
+11-13Lines changed: 11 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -37,9 +37,7 @@ jupyter:
37
37
38
38
#### Simple Subplot
39
39
40
-
Figures with subplots are created using the `make_subplots()` function from the `plotly.subplots` module.
41
-
42
-
This function accepts two integer parameters (`rows` and `cols`), which specifiy how the subplots should be laid out.
40
+
Figures with subplots are created using the `make_subplots` function from the `plotly.subplots` module.
43
41
44
42
Here is an example of creating a figure that includes two `scatter` traces which are side-by-side since there are 2 columns and 1 row in the subplot layout.
45
43
@@ -185,7 +183,7 @@ fig.show()
185
183
```
186
184
187
185
#### Customize Subplot Column Widths and Row Heights
188
-
The `column_widths` argument to `make_subplots()` can be used to customize the relative widths of the columns in a subplot grid. It should be set to a list of numbers with a length that matches the `cols` argument. These number will be normalized, so that they sum to 1, and used to compute the relative widths of the subplot grid columns. The `row_heights` argument serves the same purpose for controlling the relative heights of rows in the subplot grid.
186
+
The `column_widths` argument to `make_subplots` can be used to customize the relative widths of the columns in a subplot grid. It should be set to a list of numbers with a length that matches the `cols` argument. These number will be normalized, so that they sum to 1, and used to compute the relative widths of the subplot grid columns. The `row_heights` argument serves the same purpose for controlling the relative heights of rows in the subplot grid.
189
187
190
188
Here is an example of creating a figure with two scatter traces in side-by-side subplots. The left subplot is set to be wider than the right one.
191
189
@@ -205,9 +203,9 @@ fig.show()
205
203
```
206
204
207
205
#### Customizing Subplot Axes
208
-
After a figure with subplots is created using the `make_subplots()` function, its axis properties (title, font, range, grid style, etc.) can be customized using the `update_xaxes` and `update_yaxes` graph object figure methods. By default, these methods apply to all of the `x` axes or `y` axes in the figure. The `row` and `col` arguments can be used to control which axes are targeted by the update.
206
+
After a figure with subplots is created using the `make_subplots` function, its axis properties (title, font, range, grid style, etc.) can be customized using the `update_xaxes` and `update_yaxes` graph object figure methods. By default, these methods apply to all of the x axes or y axes in the figure. The `row` and `col` arguments can be used to control which axes are targeted by the update.
209
207
210
-
Here is an example that creates a figure with a 2 x 2 subplot grid, populates each subplot with a scatter trace, and then updates the `x` and `y` axis titles for each subplot individually.
208
+
Here is an example that creates a figure with a 2 x 2 subplot grid, populates each subplot with a scatter trace, and then updates the x and y axis titles for each subplot individually.
211
209
212
210
```python
213
211
from plotly.subplots import make_subplots
@@ -243,9 +241,9 @@ fig.show()
243
241
```
244
242
245
243
#### Subplots with Shared X-Axes
246
-
The `shared_xaxes` argument to `make_subplots()` can be used to link the x axes of subplots in the resulting figure. The `vertical_spacing` argument is used to control the vertical spacing between rows in the subplot grid.
244
+
The `shared_xaxes` argument to `make_subplots` can be used to link the x axes of subplots in the resulting figure. The `vertical_spacing` argument is used to control the vertical spacing between rows in the subplot grid.
247
245
248
-
Here is an example that creates a figure with 3 vertically stacked subplots with linked `x` axes. A small vertical spacing value is used to reduce the spacing between subplot rows.
246
+
Here is an example that creates a figure with 3 vertically stacked subplots with linked x axes. A small vertical spacing value is used to reduce the spacing between subplot rows.
249
247
250
248
```python
251
249
from plotly.subplots import make_subplots
@@ -270,9 +268,9 @@ fig.show()
270
268
```
271
269
272
270
#### Subplots with Shared Y-Axes
273
-
The `shared_yaxes` argument to `make_subplots()` can be used to link the `y` axes of subplots in the resulting figure.
271
+
The `shared_yaxes` argument to `make_subplots` can be used to link the y axes of subplots in the resulting figure.
274
272
275
-
Here is an example that creates a figure with a 2 x 2 subplot grid, where the `y` axes of each row are linked.
273
+
Here is an example that creates a figure with a 2 x 2 subplot grid, where the y axes of each row are linked.
276
274
277
275
278
276
```python
@@ -321,7 +319,7 @@ fig.show()
321
319
```
322
320
323
321
#### Custom Sized Subplot with Subplot Titles
324
-
The `specs` argument to `make_subplots()` is used to configure per-subplot options. `specs` must be a 2-dimension list with dimensions that match those provided as the `rows` and `cols` arguments. The elements of `specs` may either be `None`, indicating no subplot should be initialized starting with this grid cell, or a dictionary containing subplot options. The `colspan` subplot option specifies the number of grid columns that the subplot starting in the given cell should occupy. If unspecified, `colspan` defaults to 1.
322
+
The `specs` argument to `make_subplots` is used to configure per-subplot options. `specs` must be a 2-dimension list with dimensions that match those provided as the `rows` and `cols` arguments. The elements of `specs` may either be `None`, indicating no subplot should be initialized starting with this grid cell, or a dictionary containing subplot options. The `colspan` subplot option specifies the number of grid columns that the subplot starting in the given cell should occupy. If unspecified, `colspan` defaults to 1.
325
323
326
324
Here is an example that creates a 2 by 2 subplot grid containing 3 subplots. The subplot `specs` element for position (2, 1) has a `colspan` value of 2, causing it to span the full figure width. The subplot `specs` element for position (2, 2) is `None` because no subplot begins at this location in the grid.
327
325
@@ -348,7 +346,7 @@ fig.show()
348
346
```
349
347
350
348
#### Multiple Custom Sized Subplots
351
-
If the `print_grid` argument to `make_subplots()` is set to `True`, then a text representation of the subplot grid will be printed.
349
+
If the `print_grid` argument to `make_subplots` is set to `True`, then a text representation of the subplot grid will be printed.
352
350
353
351
Here is an example that uses the `rowspan` and `colspan` subplot options to create a custom subplot layout with subplots of mixed sizes. The `print_grid` argument is set to `True` so that the subplot grid is printed to the screen.
354
352
@@ -377,7 +375,7 @@ fig.show()
377
375
```
378
376
379
377
#### Subplots Types
380
-
By default, the `make_subplots()` function assumes that the traces that will be added to all subplots are 2-dimensional cartesian traces (e.g. `scatter`, `bar`, `histogram`, `violin`, etc.). Traces with other subplot types (e.g. `scatterpolar`, `scattergeo`, `parcoords`, etc.) are supporteed by specifying the `type` subplot option in the `specs` argument to `make_subplots`.
378
+
By default, the `make_subplots` function assumes that the traces that will be added to all subplots are 2-dimensional cartesian traces (e.g. `scatter`, `bar`, `histogram`, `violin`, etc.). Traces with other subplot types (e.g. `scatterpolar`, `scattergeo`, `parcoords`, etc.) are supporteed by specifying the `type` subplot option in the `specs` argument to `make_subplots`.
381
379
382
380
Here are the possible values for the `type` option:
0 commit comments