diff --git a/doc/python/dendrogram.md b/doc/python/dendrogram.md index c34bb4e45e9..0fe8968f202 100644 --- a/doc/python/dendrogram.md +++ b/doc/python/dendrogram.md @@ -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 diff --git a/doc/python/figure-labels.md b/doc/python/figure-labels.md index 633c343371f..fd939df389e 100644 --- a/doc/python/figure-labels.md +++ b/doc/python/figure-labels.md @@ -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 diff --git a/doc/python/filled-area-on-mapbox.md b/doc/python/filled-area-on-mapbox.md index 0db09233d9e..2cd389642ae 100644 --- a/doc/python/filled-area-on-mapbox.md +++ b/doc/python/filled-area-on-mapbox.md @@ -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) @@ -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}) @@ -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': { diff --git a/doc/python/icicle-charts.md b/doc/python/icicle-charts.md index ea6eeb0653c..540f9f7e82c 100644 --- a/doc/python/icicle-charts.md +++ b/doc/python/icicle-charts.md @@ -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 diff --git a/doc/python/interactive-html-export.md b/doc/python/interactive-html-export.md index bd7284beb02..013c87c286b 100644 --- a/doc/python/interactive-html-export.md +++ b/doc/python/interactive-html-export.md @@ -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: @@ -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. @@ -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`. + + + +``` +<!DOCTYPE html> +<html> +<body> +<h1>Here's a Plotly graph!</h1> +{{ fig }} +<p>And here's some text after the graph.</p> +</body> +</html> +``` + + +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)) +``` + ### HTML export in Dash diff --git a/doc/python/lines-on-mapbox.md b/doc/python/lines-on-mapbox.md index 3d7bc953175..20bf2fc2726 100644 --- a/doc/python/lines-on-mapbox.md +++ b/doc/python/lines-on-mapbox.md @@ -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() @@ -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() ``` @@ -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}) diff --git a/doc/python/mapbox-density-heatmaps.md b/doc/python/mapbox-density-heatmaps.md index a6228fb474c..85786542536 100644 --- a/doc/python/mapbox-density-heatmaps.md +++ b/doc/python/mapbox-density-heatmaps.md @@ -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/). diff --git a/doc/python/marker-style.md b/doc/python/marker-style.md index 21b0a2ac052..f68030e096e 100644 --- a/doc/python/marker-style.md +++ b/doc/python/marker-style.md @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/doc/python/sunburst-charts.md b/doc/python/sunburst-charts.md index 5e589e438fe..e22f9f9dd7b 100644 --- a/doc/python/sunburst-charts.md +++ b/doc/python/sunburst-charts.md @@ -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 diff --git a/doc/python/text-and-annotations.md b/doc/python/text-and-annotations.md index d75751d1a50..30631efd7cc 100644 --- a/doc/python/text-and-annotations.md +++ b/doc/python/text-and-annotations.md @@ -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: @@ -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 @@ -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