Skip to content

Commit 6745ef1

Browse files
authored
Merge pull request #4522 from plotly/merge-doc-prod-updates
Merge doc prod updates into master
2 parents 326d8ab + 9ae8242 commit 6745ef1

12 files changed

+123
-22
lines changed

Diff for: doc/python/bubble-maps.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_
8585
df.head()
8686

8787
df['text'] = df['name'] + '<br>Population ' + (df['pop']/1e6).astype(str)+' million'
88-
limits = [(0,2),(3,10),(11,20),(21,50),(50,3000)]
88+
limits = [(0,3),(3,11),(11,21),(21,50),(50,3000)]
8989
colors = ["royalblue","crimson","lightseagreen","orange","lightgrey"]
9090
cities = []
9191
scale = 5000

Diff for: doc/python/dendrogram.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ from scipy.spatial.distance import pdist, squareform
9292
# get data
9393
data = np.genfromtxt("http://files.figshare.com/2133304/ExpRawData_E_TABM_84_A_AFFY_44.tab",
9494
names=True,usecols=tuple(range(1,30)),dtype=float, delimiter="\t")
95-
data_array = data.view((np.float, len(data.dtype.names)))
95+
data_array = data.view((float, len(data.dtype.names)))
9696
data_array = data_array.transpose()
9797
labels = data.dtype.names
9898

Diff for: doc/python/figure-labels.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ IFrame(snippet_url + 'figure-labels', width='100%', height=1200)
124124

125125
### Manual Labelling with Graph Objects
126126

127-
When using (graph objects)[/python/graph-objects/] rather than [Plotly Express](/python/plotly-express/), you will need to explicitly label traces and axes:
127+
When using [graph objects](/python/graph-objects/) rather than [Plotly Express](/python/plotly-express/), you will need to explicitly label traces and axes:
128128

129129
```python
130130
import plotly.graph_objects as go

Diff for: doc/python/filled-area-on-mapbox.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fig = go.Figure(go.Scattermapbox(
6060

6161
fig.update_layout(
6262
mapbox = {
63-
'style': "stamen-terrain",
63+
'style': "open-street-map",
6464
'center': {'lon': -73, 'lat': 46 },
6565
'zoom': 5},
6666
showlegend = False)
@@ -81,7 +81,7 @@ fig = go.Figure(go.Scattermapbox(
8181
lat = [30, 6, 6, 30, 30, None, 20, 30, 30, 20, 20, None, 40, 50, 50, 40, 40]))
8282

8383
fig.update_layout(
84-
mapbox = {'style': "stamen-terrain", 'center': {'lon': 30, 'lat': 30}, 'zoom': 2},
84+
mapbox = {'style': "open-street-map", 'center': {'lon': 30, 'lat': 30}, 'zoom': 2},
8585
showlegend = False,
8686
margin = {'l':0, 'r':0, 'b':0, 't':0})
8787

@@ -102,7 +102,7 @@ fig = go.Figure(go.Scattermapbox(
102102

103103
fig.update_layout(
104104
mapbox = {
105-
'style': "stamen-terrain",
105+
'style': "open-street-map",
106106
'center': { 'lon': -73.6, 'lat': 45.5},
107107
'zoom': 12, 'layers': [{
108108
'source': {

Diff for: doc/python/icicle-charts.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fig.show()
232232

233233
### Large Number of Slices
234234

235-
This example uses a [plotly grid attribute](https://plotly.com/python/reference/layout/#layout-grid) for the suplots. Reference the row and column destination using the [domain](https://plotly.com/python/reference/icicle/#icicle-domain) attribute.
235+
This example uses a [plotly grid attribute](https://plotly.com/python/reference/layout/#layout-grid) for the subplots. Reference the row and column destination using the [domain](https://plotly.com/python/reference/icicle/#icicle-domain) attribute.
236236

237237
```python
238238
import plotly.graph_objects as go

Diff for: doc/python/interactive-html-export.md

+42-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.14.6
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.8.8
23+
version: 3.10.11
2424
plotly:
2525
description: Plotly allows you to save interactive HTML versions of your figures
2626
to your local disk.
@@ -55,6 +55,45 @@ fig.write_html("path/to/file.html")
5555

5656
By default, the resulting HTML file is a fully self-contained HTML file which can be uploaded to a web server or shared via email or other file-sharing mechanisms. The downside to this approach is that the file is very large (5Mb+) because it contains an inlined copy of the Plotly.js library required to make the figure interactive. This can be controlled via the `include_plotlyjs` argument (see below).
5757

58+
### Inserting Plotly Output into HTML using a Jinja2 Template
59+
60+
You can insert Plotly output and text related to your data into HTML templates using Jinja2. Use `.to_html` to send the HTML to a Python string variable rather than using `write_html` to send the HTML to a disk file. Use the `full_html=False` option to output just the code necessary to add a figure to a template. We don't want to output a full HTML page, as the template will define the rest of the page's structure — for example, the page's `HTML` and `BODY` tags. First create an HTML template file containing a Jinja `{{ variable }}`. In this example, we customize the HTML in the template file by replacing the Jinja variable `{{ fig }}` with our graphic `fig`.
61+
62+
<!-- #region -->
63+
64+
```
65+
&lt;!DOCTYPE html&gt;
66+
&lt;html&gt;
67+
&lt;body&gt;
68+
&lt;h1&gt;Here's a Plotly graph!&lt;/h1&gt;
69+
{{ fig }}
70+
&lt;p&gt;And here's some text after the graph.&lt;/p&gt;
71+
&lt;/body&gt;
72+
&lt;/html&gt;
73+
```
74+
75+
76+
Then use the following Python to replace `{{ fig }}` in the template with HTML that will display the Plotly figure "fig":
77+
78+
```python
79+
import plotly.express as px
80+
from jinja2 import Template
81+
82+
data_canada = px.data.gapminder().query("country == 'Canada'")
83+
fig = px.bar(data_canada, x='year', y='pop')
84+
85+
output_html_path=r"/path/to/output.html"
86+
input_template_path = r"/path/to/template.html"
87+
88+
plotly_jinja_data = {"fig":fig.to_html(full_html=False)}
89+
#consider also defining the include_plotlyjs parameter to point to an external Plotly.js as described above
90+
91+
with open(output_html_path, "w", encoding="utf-8") as output_file:
92+
with open(input_template_path) as template_file:
93+
j2_template = Template(template_file.read())
94+
output_file.write(j2_template.render(plotly_jinja_data))
95+
```
96+
<!-- #endregion -->
5897

5998
### HTML export in Dash
6099

Diff for: doc/python/lines-on-mapbox.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import plotly.express as px
5151

5252
fig = px.line_mapbox(us_cities, lat="lat", lon="lon", color="State", zoom=3, height=300)
5353

54-
fig.update_layout(mapbox_style="stamen-terrain", mapbox_zoom=4, mapbox_center_lat = 41,
54+
fig.update_layout(mapbox_style="open-street-map", mapbox_zoom=4, mapbox_center_lat = 41,
5555
margin={"r":0,"t":0,"l":0,"b":0})
5656

5757
fig.show()
@@ -95,7 +95,7 @@ for feature, name in zip(geo_df.geometry, geo_df.name):
9595
names = np.append(names, None)
9696

9797
fig = px.line_mapbox(lat=lats, lon=lons, hover_name=names,
98-
mapbox_style="stamen-terrain", zoom=1)
98+
mapbox_style="open-street-map", zoom=1)
9999
fig.show()
100100
```
101101

@@ -123,7 +123,7 @@ fig.update_layout(
123123
margin ={'l':0,'t':0,'b':0,'r':0},
124124
mapbox = {
125125
'center': {'lon': 10, 'lat': 10},
126-
'style': "stamen-terrain",
126+
'style': "open-street-map",
127127
'center': {'lon': -20, 'lat': -20},
128128
'zoom': 1})
129129

Diff for: doc/python/mapbox-density-heatmaps.md

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ jupyter:
3737

3838
To plot on Mapbox maps with Plotly, you may need a [Mapbox account and token](https://www.mapbox.com/studio) or a [Stadia Maps account and token](https://www.stadiamaps.com), depending on base map (`mapbox_style`) you use. On this page, we show how to use the "open-street-map" base map, which doesn't require a token, and a "stamen" base map, which requires a Stadia Maps token. See our [Mapbox Map Layers](/python/mapbox-layers/) documentation for more examples.
3939

40-
4140
### OpenStreetMap base map (no token needed): density mapbox with `plotly.express`
4241

4342
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on a variety of types of data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/).

Diff for: doc/python/mapbox-layers.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ If you basemap in `layout.mapbox.style` uses maps from the [Stadia Maps service]
6767
The accepted values for `layout.mapbox.style` are one of:
6868

6969
- `"white-bg"` yields an empty white canvas which results in no external HTTP requests
70-
- `"open-street-map"`, `"carto-positron"`, or `"carto-darkmatter"` yield maps composed of _raster_ tiles from various public tile servers which do not require signups or access tokens.
70+
- `"open-street-map"`, `"carto-positron"`, and `"carto-darkmatter"` yield maps composed of _raster_ tiles from various public tile servers which do not require signups or access tokens.
7171
- `"basic"`, `"streets"`, `"outdoors"`, `"light"`, `"dark"`, `"satellite"`, or `"satellite-streets"` yield maps composed of _vector_ tiles from the Mapbox service, and _do_ require a Mapbox Access Token or an on-premise Mapbox installation.
7272
- `"stamen-terrain"`, `"stamen-toner"` or `"stamen-watercolor"` yield maps composed of _raster_ tiles from the [Stadia Maps service](https://www.stadiamaps.com), and require a Stadia Maps account and token.
7373
- A Mapbox service style URL, which requires a Mapbox Access Token or an on-premise Mapbox installation.

Diff for: doc/python/marker-style.md

+28-3
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.1
9+
jupytext_version: 1.14.6
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.8.0
23+
version: 3.10.11
2424
plotly:
2525
description: How to style markers in Python with Plotly.
2626
display_as: file_settings
@@ -361,7 +361,7 @@ fig.show()
361361

362362
### Using a Custom Marker
363363

364-
To use a custom marker, set the `symbol` on the `marker`. Here we set it to `diamond`.
364+
To use a custom marker, set the `symbol` on the `marker`. Here we set it to `diamond`.
365365

366366

367367
```python
@@ -378,6 +378,31 @@ fig.show()
378378

379379
```
380380

381+
#### Open Marker Colors
382+
383+
In the previous example, each marker has two colors, a marker color (set in Plotly Express with `color="species"`) and a line color (set on the line with `color="DarkSlateGrey"`. All open markers, like "diamond-open" in the following example, have a transparent fill, which means you can specify only one color. Specify this color using the marker color parameter. This controls the outline color and any dot or cross. For open markers, the line color does nothing.
384+
385+
```python
386+
import plotly.express as px
387+
388+
df = px.data.iris()
389+
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
390+
391+
fig.update_traces(
392+
marker=dict(
393+
size=8,
394+
symbol="diamond-open",
395+
line=dict(
396+
width=2,
397+
# color="DarkSlateGrey" Line colors don't apply to open markers
398+
)
399+
),
400+
selector=dict(mode="markers"),
401+
)
402+
403+
fig.show()
404+
```
405+
381406
### Setting Marker Angles
382407

383408

Diff for: doc/python/sunburst-charts.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fig.show()
214214

215215
### Large Number of Slices
216216

217-
This example uses a [plotly grid attribute](https://plotly.com/python/reference/layout/#layout-grid) for the suplots. Reference the row and column destination using the [domain](https://plotly.com/python/reference/sunburst/#sunburst-domain) attribute.
217+
This example uses a [plotly grid attribute](https://plotly.com/python/reference/layout/#layout-grid) for the subplots. Reference the row and column destination using the [domain](https://plotly.com/python/reference/sunburst/#sunburst-domain) attribute.
218218

219219
```python
220220
import plotly.graph_objects as go

Diff for: doc/python/text-and-annotations.md

+41-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.16.1
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.8.8
23+
version: 3.10.11
2424
plotly:
2525
description: How to add text labels and annotations to plots in python.
2626
display_as: file_settings
@@ -207,6 +207,44 @@ fig.update_layout(showlegend=False)
207207
fig.show()
208208
```
209209

210+
#### Text Annotations with Log Axes
211+
212+
If the `x` or `y` positions of an annotation reference a log axis, you need to provide that position as a `log10` value when adding the annotation. In this example, the `yaxis` is a log axis so we pass the `log10` value of `1000` to the annotation's `y` position.
213+
214+
```python
215+
import plotly.graph_objects as go
216+
import math
217+
218+
dates = [
219+
"2024-01-01",
220+
"2024-01-02",
221+
"2024-01-03",
222+
"2024-01-04",
223+
"2024-01-05",
224+
"2024-01-06",
225+
]
226+
y_values = [1, 30, 70, 100, 1000, 10000000]
227+
228+
fig = go.Figure(
229+
data=[go.Scatter(x=dates, y=y_values, mode="lines+markers")],
230+
layout=go.Layout(
231+
yaxis=dict(
232+
type="log",
233+
)
234+
),
235+
)
236+
237+
fig.add_annotation(
238+
x="2024-01-05",
239+
y=math.log10(1000),
240+
text="Log axis annotation",
241+
showarrow=True,
242+
xanchor="right",
243+
)
244+
245+
fig.show()
246+
```
247+
210248
### 3D Annotations
211249

212250
```python

0 commit comments

Comments
 (0)