Skip to content

Commit

Permalink
Merge pull request #4522 from plotly/merge-doc-prod-updates
Browse files Browse the repository at this point in the history
Merge doc prod updates into master
  • Loading branch information
LiamConnors committed Feb 15, 2024
2 parents 326d8ab + 9ae8242 commit 6745ef1
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 22 deletions.
2 changes: 1 addition & 1 deletion doc/python/bubble-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_
df.head()

df['text'] = df['name'] + '<br>Population ' + (df['pop']/1e6).astype(str)+' million'
limits = [(0,2),(3,10),(11,20),(21,50),(50,3000)]
limits = [(0,3),(3,11),(11,21),(21,50),(50,3000)]
colors = ["royalblue","crimson","lightseagreen","orange","lightgrey"]
cities = []
scale = 5000
Expand Down
2 changes: 1 addition & 1 deletion doc/python/dendrogram.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ from scipy.spatial.distance import pdist, squareform
# get data
data = np.genfromtxt("http://files.figshare.com/2133304/ExpRawData_E_TABM_84_A_AFFY_44.tab",
names=True,usecols=tuple(range(1,30)),dtype=float, delimiter="\t")
data_array = data.view((np.float, len(data.dtype.names)))
data_array = data.view((float, len(data.dtype.names)))
data_array = data_array.transpose()
labels = data.dtype.names

Expand Down
2 changes: 1 addition & 1 deletion doc/python/figure-labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ IFrame(snippet_url + 'figure-labels', width='100%', height=1200)

### Manual Labelling with Graph Objects

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

```python
import plotly.graph_objects as go
Expand Down
6 changes: 3 additions & 3 deletions doc/python/filled-area-on-mapbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fig = go.Figure(go.Scattermapbox(

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

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

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

fig.update_layout(
mapbox = {
'style': "stamen-terrain",
'style': "open-street-map",
'center': { 'lon': -73.6, 'lat': 45.5},
'zoom': 12, 'layers': [{
'source': {
Expand Down
2 changes: 1 addition & 1 deletion doc/python/icicle-charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ fig.show()

### Large Number of Slices

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.
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.

```python
import plotly.graph_objects as go
Expand Down
45 changes: 42 additions & 3 deletions doc/python/interactive-html-export.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.3'
jupytext_version: 1.14.1
jupytext_version: 1.14.6
kernelspec:
display_name: Python 3
display_name: Python 3 (ipykernel)
language: python
name: python3
language_info:
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.8.8
version: 3.10.11
plotly:
description: Plotly allows you to save interactive HTML versions of your figures
to your local disk.
Expand Down Expand Up @@ -55,6 +55,45 @@ fig.write_html("path/to/file.html")

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).

### Inserting Plotly Output into HTML using a Jinja2 Template

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`.

<!-- #region -->

```
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;h1&gt;Here's a Plotly graph!&lt;/h1&gt;
{{ fig }}
&lt;p&gt;And here's some text after the graph.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
```


Then use the following Python to replace `{{ fig }}` in the template with HTML that will display the Plotly figure "fig":

```python
import plotly.express as px
from jinja2 import Template

data_canada = px.data.gapminder().query("country == 'Canada'")
fig = px.bar(data_canada, x='year', y='pop')

output_html_path=r"/path/to/output.html"
input_template_path = r"/path/to/template.html"

plotly_jinja_data = {"fig":fig.to_html(full_html=False)}
#consider also defining the include_plotlyjs parameter to point to an external Plotly.js as described above

with open(output_html_path, "w", encoding="utf-8") as output_file:
with open(input_template_path) as template_file:
j2_template = Template(template_file.read())
output_file.write(j2_template.render(plotly_jinja_data))
```
<!-- #endregion -->

### HTML export in Dash

Expand Down
6 changes: 3 additions & 3 deletions doc/python/lines-on-mapbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import plotly.express as px

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

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

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

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

Expand Down Expand Up @@ -123,7 +123,7 @@ fig.update_layout(
margin ={'l':0,'t':0,'b':0,'r':0},
mapbox = {
'center': {'lon': 10, 'lat': 10},
'style': "stamen-terrain",
'style': "open-street-map",
'center': {'lon': -20, 'lat': -20},
'zoom': 1})

Expand Down
1 change: 0 additions & 1 deletion doc/python/mapbox-density-heatmaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jupyter:

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.


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

[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/).
Expand Down
2 changes: 1 addition & 1 deletion doc/python/mapbox-layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ If you basemap in `layout.mapbox.style` uses maps from the [Stadia Maps service]
The accepted values for `layout.mapbox.style` are one of:

- `"white-bg"` yields an empty white canvas which results in no external HTTP requests
- `"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.
- `"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.
- `"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.
- `"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.
- A Mapbox service style URL, which requires a Mapbox Access Token or an on-premise Mapbox installation.
Expand Down
31 changes: 28 additions & 3 deletions doc/python/marker-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.3'
jupytext_version: 1.14.1
jupytext_version: 1.14.6
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.8.0
version: 3.10.11
plotly:
description: How to style markers in Python with Plotly.
display_as: file_settings
Expand Down Expand Up @@ -361,7 +361,7 @@ fig.show()

### Using a Custom Marker

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


```python
Expand All @@ -378,6 +378,31 @@ fig.show()

```

#### Open Marker Colors

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.

```python
import plotly.express as px

df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")

fig.update_traces(
marker=dict(
size=8,
symbol="diamond-open",
line=dict(
width=2,
# color="DarkSlateGrey" Line colors don't apply to open markers
)
),
selector=dict(mode="markers"),
)

fig.show()
```

### Setting Marker Angles


Expand Down
2 changes: 1 addition & 1 deletion doc/python/sunburst-charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fig.show()

### Large Number of Slices

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.
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.

```python
import plotly.graph_objects as go
Expand Down
44 changes: 41 additions & 3 deletions doc/python/text-and-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.3'
jupytext_version: 1.14.1
jupytext_version: 1.16.1
kernelspec:
display_name: Python 3
display_name: Python 3 (ipykernel)
language: python
name: python3
language_info:
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.8.8
version: 3.10.11
plotly:
description: How to add text labels and annotations to plots in python.
display_as: file_settings
Expand Down Expand Up @@ -207,6 +207,44 @@ fig.update_layout(showlegend=False)
fig.show()
```

#### Text Annotations with Log Axes

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.

```python
import plotly.graph_objects as go
import math

dates = [
"2024-01-01",
"2024-01-02",
"2024-01-03",
"2024-01-04",
"2024-01-05",
"2024-01-06",
]
y_values = [1, 30, 70, 100, 1000, 10000000]

fig = go.Figure(
data=[go.Scatter(x=dates, y=y_values, mode="lines+markers")],
layout=go.Layout(
yaxis=dict(
type="log",
)
),
)

fig.add_annotation(
x="2024-01-05",
y=math.log10(1000),
text="Log axis annotation",
showarrow=True,
xanchor="right",
)

fig.show()
```

### 3D Annotations

```python
Expand Down

0 comments on commit 6745ef1

Please sign in to comment.