From 65eed7214a449808ec42c5faad230599863a5977 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Tue, 10 Dec 2019 09:55:07 -0500 Subject: [PATCH 1/8] Update requirements.txt --- doc/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/requirements.txt b/doc/requirements.txt index 8453a529d74..11c0947ddaf 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,4 +1,4 @@ -plotly==4.3.0 +plotly==4.4.0 jupytext==1.1.1 jupyter notebook From 75ae9ff03bb5d64c0add1c49122e38241a873493 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Tue, 10 Dec 2019 10:18:38 -0500 Subject: [PATCH 2/8] Update plotly.express.rst --- doc/apidoc/plotly.express.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/apidoc/plotly.express.rst b/doc/apidoc/plotly.express.rst index 382ae7f68b2..191ca9f4a70 100644 --- a/doc/apidoc/plotly.express.rst +++ b/doc/apidoc/plotly.express.rst @@ -33,12 +33,19 @@ plotly's high-level API for rapid figure generation. :: box strip histogram + pie + treemap + sunburst + funnel + funnel_area scatter_matrix parallel_coordinates parallel_categories choropleth + choropleth_mapbox density_contour density_heatmap + density_mapbox imshow From 61fb14b0fb00f5893b691a0d9b2a6d5ba298893c Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Wed, 11 Dec 2019 13:36:39 -0500 Subject: [PATCH 3/8] example with reversed colorscale (#1997) * example with reversed colorscale * updated changelog --- CHANGELOG.md | 1 + doc/python/colorscales.md | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3ab635be68..69932340fcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). have a `range_theta` keyword argument for representing only an angular section [#1969](https://github.com/plotly/plotly.py/pull/1969). - Docstrings of plotly.py are now doctested [#1921](https://github.com/plotly/plotly.py/pull/1921). + - Reversing a predefined colorscale by appending `_r` to its name [#1933](https://github.com/plotly/plotly.py/pull/1933) ## [4.3.0] - 2019-11-11 diff --git a/doc/python/colorscales.md b/doc/python/colorscales.md index abf7d47197d..ddbff75700b 100644 --- a/doc/python/colorscales.md +++ b/doc/python/colorscales.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.2.1 + format_version: '1.2' + jupytext_version: 1.3.0 kernelspec: display_name: Python 3 language: python @@ -62,6 +62,28 @@ fig = px.scatter(iris, x="sepal_width", y="sepal_length", fig.show() ``` +### Reversing a predefined colorscale + +You can reverse a predefined colorscale by appending `_r` to its name, for colorscales given either as a string or a `plotly` object. + +```python +import plotly.express as px +iris = px.data.iris() +fig = px.scatter(iris, x="sepal_width", y="sepal_length", + color="sepal_length", color_continuous_scale='Magma_r') + +fig.show() +``` + +```python +import plotly.express as px +data = [[1, .3, .5, .9], + [.3, .1, .4, 1], + [.2, .8, .9, .3]] +fig = px.imshow(data, color_continuous_scale=px.colors.diverging.Tealrose_r) +fig.show() +``` + ### Custom Discretized Heatmap Colorscale ```python From 9ecae0aa72d3ee5ac53b8102dcabc1f04054f8ca Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Wed, 11 Dec 2019 14:08:08 -0500 Subject: [PATCH 4/8] mapbox examples with px (#1998) * mapbox examples with px * Update doc/python/mapbox-density-heatmaps.md Co-Authored-By: Nicolas Kruchten --- doc/python/mapbox-county-choropleth.md | 44 +++++++++++++++++++++++--- doc/python/mapbox-density-heatmaps.md | 33 +++++++++++++++---- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/doc/python/mapbox-county-choropleth.md b/doc/python/mapbox-county-choropleth.md index 29e8928521d..5214cd47b68 100644 --- a/doc/python/mapbox-county-choropleth.md +++ b/doc/python/mapbox-county-choropleth.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.0 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.8 + version: 3.7.3 plotly: description: How to make a Mapbox Choropleth Map of US Counties in Python with Plotly. @@ -40,7 +40,9 @@ jupyter: To plot on Mapbox maps with Plotly you *may* need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio). See our [Mapbox Map Layers](/python/mapbox-layers/) documentation for more information. -Making choropleth maps with `go.Choroplethmapbox` requires two main types of input: GeoJSON-formatted geometry information *where each `feature` has an `id`* and a list of values indexed by feature id. The GeoJSON data is passed to the `geojson` attribute, and the data is passed into the `z` attribute, in the same order as the IDs are passed into the `location` attribute. +### Introduction: main parameters for choropleth mapbox charts + +Making choropleth maps requires two main types of input: GeoJSON-formatted geometry information *where each `feature` has an `id`* and a list of values indexed by feature id. The GeoJSON data is passed to the `geojson` attribute, and the data is passed into the `z` (`color` for `px.choropleth_mapbox`) attribute, in the same order as the IDs are passed into the `location` attribute. #### GeoJSON with `feature.id` @@ -67,7 +69,39 @@ df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips- df.head() ``` -#### Carto base map: no token needed +### Choropleth map using plotly.express and carto base map (no token needed) + +[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on "tidy" data](/python/px-arguments/). + +With `px.choropleth_mapbox`, each row of the DataFrame is represented as a region of the choropleth. + +```python +from urllib.request import urlopen +import json +with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response: + counties = json.load(response) + +import pandas as pd +df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv", + dtype={"fips": str}) + +import plotly.express as px + +fig = px.choropleth_mapbox(df, geojson=counties, locations='fips', color='unemp', + color_continuous_scale="Viridis", + range_color=(0, 12), + mapbox_style="carto-positron", + zoom=3, center = {"lat": 37.0902, "lon": -95.7129}, + opacity=0.5, + labels={'unemp':'unemployment rate'} + ) +fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}) +fig.show() +``` + +### Choropleth map using plotly.graph_objects and carto base map (no token needed) + +If Plotly Express does not provide a good starting point, it is also possible to use the more generic `go.Choroplethmapbox` function from `plotly.graph_objects`. ```python from urllib.request import urlopen diff --git a/doc/python/mapbox-density-heatmaps.md b/doc/python/mapbox-density-heatmaps.md index 5da838cddcf..e17a0ae5ef8 100644 --- a/doc/python/mapbox-density-heatmaps.md +++ b/doc/python/mapbox-density-heatmaps.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.0 kernelspec: display_name: Python 3 language: python @@ -20,10 +20,9 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: - description: How to make a Mapbox Density Heatmap in Python - with Plotly. + description: How to make a Mapbox Density Heatmap in Python with Plotly. display_as: maps language: python layout: base @@ -42,14 +41,34 @@ To plot on Mapbox maps with Plotly you *may* need a Mapbox account and a public -#### Stamen Terrain base map: no token needed +### Stamen Terrain 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 "tidy" data](/python/px-arguments/). + +With `px.density_mapbox`, each row of the DataFrame is represented as a point smoothed with a given radius of influence. + +```python +import pandas as pd +df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv') + +import plotly.express as px +fig = px.density_mapbox(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10, + center=dict(lat=0, lon=180), zoom=0, + mapbox_style="stamen-terrain") +fig.show() +``` + +### Stamen Terrain base map (no token needed): density mapbox with `plotly.graph_objects` + +If Plotly Express does not provide a good starting point, it is also possible to use the more generic `go.Densitymapbox` function from `plotly.graph_objects`. ```python import pandas as pd quakes = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv') import plotly.graph_objects as go -fig = go.Figure(go.Densitymapbox(lat=quakes.Latitude, lon=quakes.Longitude, z=quakes.Magnitude, radius=10)) +fig = go.Figure(go.Densitymapbox(lat=quakes.Latitude, lon=quakes.Longitude, z=quakes.Magnitude, + radius=10)) fig.update_layout(mapbox_style="stamen-terrain", mapbox_center_lon=180) fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}) fig.show() From acfd037a8d48230fc75c225755228512d731cfea Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Wed, 11 Dec 2019 14:37:41 -0500 Subject: [PATCH 5/8] px examples for pie, funnel/funnelarea, sunburst/treemap (#1995) * pie chart tutorial using px * funnel chart * examples for sunburst and treemap * px intro --- doc/python/funnel-charts.md | 70 +++++++++++++++++++++++++++++------ doc/python/pie-charts.md | 65 ++++++++++++++++++++++++++++++-- doc/python/sunburst-charts.md | 36 +++++++++++++++--- doc/python/treemaps.md | 29 ++++++++++++--- 4 files changed, 175 insertions(+), 25 deletions(-) diff --git a/doc/python/funnel-charts.md b/doc/python/funnel-charts.md index 782b5cb24a3..e786eca4fbc 100644 --- a/doc/python/funnel-charts.md +++ b/doc/python/funnel-charts.md @@ -1,26 +1,27 @@ --- jupyter: jupytext: + notebook_metadata_filter: plotly text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.0 kernelspec: display_name: Python 3 language: python name: python3 plotly: - permalink: python/funnel-charts/ - redirect_from: python/funnel-chart/ description: How to make funnel-chart plots in Python with Plotly. - name: Funnel Chart - thumbnail: thumbnail/funnel.jpg - language: python display_as: financial - order: 4 + language: python layout: base + name: Funnel Chart + order: 4 page_type: example_index + permalink: python/funnel-charts/ + redirect_from: python/funnel-chart/ + thumbnail: thumbnail/funnel.jpg --- @@ -29,7 +30,40 @@ jupyter: Funnel charts are often used to represent data in different stages of a business process. It’s an important mechanism in Business Intelligence to identify potential problem areas of a process. For example, it’s used to observe the revenue or loss in a sales process for each stage, and displays values that are decreasing progressively. Each stage is illustrated as a percentage of the total of all values. -### Basic Funnel Plot +### Basic Funnel Plot with plotly.express + +[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on "tidy" data](/python/px-arguments/). + +With `px.funnel`, each row of the DataFrame is represented as a stage of the funnel. + + +```python +import plotly.express as px +data = dict( + number=[39, 27.4, 20.6, 11, 2], + stage=["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"]) +fig = px.funnel(data, x='number', y='stage') +fig.show() +``` + +### Stacked Funnel Plot with plotly.express + +```python +import plotly.express as px +import pandas as pd +stages = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"] +df_mtl = pd.DataFrame(dict(number=[39, 27.4, 20.6, 11, 3], stage=stages)) +df_mtl['office'] = 'Montreal' +df_toronto = pd.DataFrame(dict(number=[52, 36, 18, 14, 5], stage=stages)) +df_toronto['office'] = 'Toronto' +df = pd.concat([df_mtl, df_toronto], axis=0) +fig = px.funnel(df, x='number', y='stage', color='office') +fig.show() +``` + +### Basic Funnel Chart with graph_objects trace go.Funnel + +If Plotly Express does not provide a good starting point, it is also possible to use the more generic `go.Funnel` function from `plotly.graph_objects`. ```python from plotly import graph_objects as go @@ -60,7 +94,7 @@ fig = go.Figure(go.Funnel( fig.show() ``` -### Stacked Funnel Plot +### Stacked Funnel Plot with go.Funnel ```python from plotly import graph_objects as go @@ -92,7 +126,21 @@ fig.add_trace(go.Funnel( fig.show() ``` -#### Basic Area Funnel Plot +### Basic Area Funnel Plot with plotly.express + +With `px.funnel_area`, each row of the DataFrame is represented as a stage of +the funnel. + +```python +import plotly.express as px +fig = px.funnel_area(names=["The 1st","The 2nd", "The 3rd", "The 4th", "The 5th"], + values=[5, 4, 3, 2, 1]) +fig.show() +``` + +### Basic Area Funnel Plot with go.Funnelarea + +If Plotly Express does not provide a good starting point, it is also possible to use the more generic `go.Funnelarea` function from `plotly.graph_objects`. ```python from plotly import graph_objects as go diff --git a/doc/python/pie-charts.md b/doc/python/pie-charts.md index ca22c48a1f7..d5e8e54449d 100644 --- a/doc/python/pie-charts.md +++ b/doc/python/pie-charts.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.0 kernelspec: display_name: Python 3 language: python @@ -33,9 +33,66 @@ jupyter: thumbnail: thumbnail/pie-chart.jpg --- -### Basic Pie Chart ### +A pie chart is a circular statistical chart, which is divided into sectors to illustrate numerical proportion. -A pie chart ``go.Pie`` object is a circular statistical chart, which is divided into sectors to illustrate numerical proportion. Data visualized by the sectors of the pie is set in `values`. The sector labels are set in `labels`. The sector colors are set in `marker.colors`. +If you're looking instead for a multilevel hierarchical pie-like chart, go to the +[Sunburst tutorial](/python/sunburst-charts/). + +### Pie chart with plotly express + +[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on "tidy" data](/python/px-arguments/). + +In `px.pie`, data visualized by the sectors of the pie is set in `values`. The sector labels are set in `names`. + +```python +import plotly.express as px +df = px.data.gapminder().query("year == 2007").query("continent == 'Europe'") +df.loc[df['pop'] < 2.e6, 'country'] = 'Other countries' # Represent only large countries +fig = px.pie(df, values='pop', names='country', title='Population of European continent') +fig.show() +``` + +### Pie chart with repeated labels + +Lines of the dataframe with the same value for `names` are grouped together in the same sector. + +```python +import plotly.express as px +# This dataframe has 244 lines, but 4 distinct values for `day` +df = px.data.tips() +fig = px.pie(df, values='tip', names='day') +fig.show() +``` + +### Setting the color of pie sectors with px.pie + +```python +import plotly.express as px +df = px.data.tips() +fig = px.pie(df, values='tip', names='day', color_discrete_sequence=px.colors.sequential.RdBu) +fig.show() +``` + +### Customizing a pie chart created with px.pie + +In the example below, we first create a pie chart with `px,pie`, using some of its options such as `hover_data` (which columns should appear in the hover) or `labels` (renaming column names). For further tuning, we call `fig.update_traces` to set other parameters of the chart (you can also use `fig.update_layout` for changing the layout). + +```python +import plotly.express as px +df = px.data.gapminder().query("year == 2007").query("continent == 'Americas'") +fig = px.pie(df, values='pop', names='country', + title='Population of American continent', + hover_data=['lifeExp'], labels={'lifeExp':'life expectancy'}) +fig.update_traces(textposition='inside', textinfo='percent+label') +fig.show() +``` + +### Basic Pie Chart with go.Pie + +If Plotly Express does not provide a good starting point, it is also possible to use the more generic `go.Pie` function from `plotly.graph_objects`. + + +In `go.Pie`, data visualized by the sectors of the pie is set in `values`. The sector labels are set in `labels`. The sector colors are set in `marker.colors`. If you're looking instead for a multilevel hierarchical pie-like chart, go to the [Sunburst tutorial](/python/sunburst-charts/). diff --git a/doc/python/sunburst-charts.md b/doc/python/sunburst-charts.md index 43edfe0289e..a80d530fc08 100644 --- a/doc/python/sunburst-charts.md +++ b/doc/python/sunburst-charts.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.0 kernelspec: display_name: Python 3 language: python @@ -33,14 +33,40 @@ jupyter: thumbnail: thumbnail/sunburst.gif --- -### Basic Sunburst Plot ### -Sunburst plots visualize hierarchical data spanning outwards radially from root to leaves. The sunburst sector hierarchy is determined by the entries in `labels` and in `parents`. The root starts from the center and children are added to the outer rings. +Sunburst plots visualize hierarchical data spanning outwards radially from root to leaves. The sunburst sector hierarchy is determined by the entries in `labels` (`names` in `px.sunburst`) and in `parents`. The root starts from the center and children are added to the outer rings. Main arguments: -1. `labels`: sets the labels of sunburst sectors. +1. `labels` (`names` in `px.sunburst` since `labels` is reserved for overriding columns names): sets the labels of sunburst sectors. 2. `parents`: sets the parent sectors of sunburst sectors. An empty string `''` is used for the root node in the hierarchy. In this example, the root is "Eve". 3. `values`: sets the values associated with sunburst sectors, determining their width (See the `branchvalues` section below for different modes for setting the width). +### Basic Sunburst Plot with plotly.express + +[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on "tidy" data](/python/px-arguments/). + +With `px.sunburst`, each row of the DataFrame is represented as a sector of the sunburst. + +```python +import plotly.express as px +data = dict( + character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"], + parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ], + value=[10, 14, 12, 10, 2, 6, 6, 4, 4]) + +fig =px.sunburst( + data, + names='character', + parents='parent', + values='value', +) +fig.show() +``` + +### Basic Sunburst Plot with go.Sunburst + +If Plotly Express does not provide a good starting point, it is also possible to use the more generic `go.Sunburst` function from `plotly.graph_objects`. + + ```python import plotly.graph_objects as go diff --git a/doc/python/treemaps.md b/doc/python/treemaps.md index a241a119828..02167e3cdb8 100644 --- a/doc/python/treemaps.md +++ b/doc/python/treemaps.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.0 kernelspec: display_name: Python 3 language: python @@ -33,9 +33,28 @@ jupyter: thumbnail: thumbnail/treemap.png --- -### Basic Treemap -[Treemap charts](https://en.wikipedia.org/wiki/Treemapping) visualize hierarchical data using nested rectangles. Same as [Sunburst](https://plot.ly/python/sunburst-charts/) the hierarchy is defined by [labels](https://plot.ly/python/reference/#treemap-labels) and [parents](https://plot.ly/python/reference/#treemap-parents) attributes. Click on one sector to zoom in/out, which also displays a pathbar in the upper-left corner of your treemap. To zoom out you can use the path bar as well. +[Treemap charts](https://en.wikipedia.org/wiki/Treemapping) visualize hierarchical data using nested rectangles. Same as [Sunburst](https://plot.ly/python/sunburst-charts/) the hierarchy is defined by [labels](https://plot.ly/python/reference/#treemap-labels) (`names` for `px.treemap`) and [parents](https://plot.ly/python/reference/#treemap-parents) attributes. Click on one sector to zoom in/out, which also displays a pathbar in the upper-left corner of your treemap. To zoom out you can use the path bar as well. + +### Basic Treemap with plotly.express + +[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on "tidy" data](/python/px-arguments/). + +With `px.treemap`, each row of the DataFrame is represented as a sector of the treemap. + +```python +import plotly.express as px +fig = px.treemap( + names = ["Eve","Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"], + parents = ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"] +) +fig.show() +``` + +### Basic Treemap with go.Treemap + +If Plotly Express does not provide a good starting point, it is also possible to use the more generic `go.Treemap` function from `plotly.graph_objects`. + ```python import plotly.graph_objects as go @@ -269,4 +288,4 @@ fig.show() ``` #### Reference -See https://plot.ly/python/reference/#treemap for more information and chart attribute options! \ No newline at end of file +See https://plot.ly/python/reference/#treemap for more information and chart attribute options! From 14dc3fe3933c30fc7cdf5171ff9d74d2b5dea52f Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Wed, 11 Dec 2019 14:55:41 -0500 Subject: [PATCH 6/8] test backticks --- doc/python/box-plots.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/box-plots.md b/doc/python/box-plots.md index 779930ea7ee..d92a175a946 100644 --- a/doc/python/box-plots.md +++ b/doc/python/box-plots.md @@ -39,7 +39,7 @@ jupyter: A [box plot](https://en.wikipedia.org/wiki/Box_plot) is a statistical representation of numerical data through their quartiles. The ends of the box represent the lower and upper quartiles, while the median (second quartile) is marked by a line inside the box. For other statistical representations of numerical data, see [other statistical charts](https://plot.ly/python/statistical-charts/). -## Box Plot with Plotly Express +## Box Plot with `plotly.express` [Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on "tidy" data](/python/px-arguments/). From 78410cc3359e608e5f71fb3afcd667439ec87d5f Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Thu, 12 Dec 2019 13:16:05 -0500 Subject: [PATCH 7/8] px example in heatmap (#2000) --- doc/python/heatmaps.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/doc/python/heatmaps.md b/doc/python/heatmaps.md index 2e421dbf301..8385db5e632 100644 --- a/doc/python/heatmaps.md +++ b/doc/python/heatmaps.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.0 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: description: How to make Heatmaps in Python with Plotly. display_as: scientific @@ -34,7 +34,26 @@ jupyter: thumbnail: thumbnail/heatmap.jpg --- -### Basic Heatmap +### Heatmap with `plotly.express` and `px.imshow` + +[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly. With `px.imshow`, each value of the input array is represented as a heatmap pixel. + +`px.imshow` makes opiniated choices for representing heatmaps, such as using square pixels. To override this behaviour, you can use `fig.update_layout` or use the `go.Heatmap` trace from `plotly.graph_objects` as described below. + +For more examples using `px.imshow`, see the [tutorial on displaying image data with plotly](/python/imshow). + +```python +import plotly.express as px + +fig = px.imshow([[1, 20, 30], + [20, 1, 60], + [30, 60, 1]]) +fig.show() +``` + +### Basic Heatmap with `plotly.graph_objects` + +If Plotly Express does not provide a good starting point, it is also possible to use the more generic `go.Heatmap` function from `plotly.graph_objects`. ```python import plotly.graph_objects as go From 55be0e247e392f9f95e509614456d07b523b9639 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Thu, 12 Dec 2019 15:46:18 -0500 Subject: [PATCH 8/8] Update Makefile --- doc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Makefile b/doc/Makefile index 92003acc71a..fa8e525dd6b 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -38,7 +38,7 @@ $(HTML_DIR)/2019-07-03-%.html: $(IPYNB_DIR)/%.ipynb @echo "[nbconvert] $<" @jupyter nbconvert $< --to html --template nb.tpl \ --output-dir $(HTML_DIR) --output 2019-07-03-$*.html \ - --execute + --execute > $(FAIL_DIR)/$* 2>&1 && rm -f $(FAIL_DIR)/$* $(REDIR_DIR)/2019-07-03-redirect-next-%.html: $(IPYNB_DIR)/%.ipynb