Skip to content

Commit 9465de3

Browse files
Merge branch 'doc-prod'
2 parents 141aa6d + a61fad5 commit 9465de3

12 files changed

+608
-207
lines changed

binder/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
jupytext
2-
plotly==4.5.4
2+
plotly==4.6.0
33
jupyter
44
notebook
55
pandas

doc/apidoc/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# The short X.Y version
2929
version = ""
3030
# The full version, including alpha/beta/rc tags
31-
release = "4.5.4"
31+
release = "4.6.0"
3232

3333

3434
# -- General configuration ---------------------------------------------------

doc/python/2D-Histogram.md

+68-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.3.0
9+
jupytext_version: 1.3.1
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.5
23+
version: 3.6.8
2424
plotly:
2525
description: How to make 2D Histograms in Python with Plotly.
2626
display_as: statistical
@@ -30,9 +30,75 @@ jupyter:
3030
order: 6
3131
page_type: u-guide
3232
permalink: python/2D-Histogram/
33+
redirect_from:
34+
- python/2d-histogram/
35+
- python/2d-histograms/
3336
thumbnail: thumbnail/histogram2d.jpg
3437
---
3538

39+
## 2D Histograms or Density Heatmaps
40+
41+
A 2D histogram, also known as a density heatmap, is the 2-dimensional generalization of a [histogram](/python/histograms/) which resembles a [heatmap](/python/heatmaps/) but is computed by grouping a set of points specified by their `x` and `y` coordinates into bins, and applying an aggregation function such as `count` or `sum` (if `z` is provided) to compute the color of the tile representing the bin. This kind of visualization (and the related [2D histogram contour, or density contour](https://plotly.com/python/2d-histogram-contour/)) is often used to manage over-plotting, or situations where showing large data sets as [scatter plots](/python/line-and-scatter/) would result in points overlapping each other and hiding patterns. For data sets of more than a few thousand points, a better approach than the ones listed here would be to [use Plotly with Datashader](/python/datashader/) to precompute the aggregations before displaying the data with Plotly.
42+
43+
## Density Heatmaps with Plotly Express
44+
45+
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on "tidy" data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/). The Plotly Express function `density_heatmap()` can be used to produce density heatmaps.
46+
47+
```python
48+
import plotly.express as px
49+
df = px.data.tips()
50+
51+
fig = px.density_heatmap(df, x="total_bill", y="tip")
52+
fig.show()
53+
```
54+
55+
The number of bins can be controlled with `nbinsx` and `nbinsy` and the [color scale](/python/colorscales/) with `color_continuous_scale`.
56+
57+
```python
58+
import plotly.express as px
59+
df = px.data.tips()
60+
61+
fig = px.density_heatmap(df, x="total_bill", y="tip", nbinsx=20, nbinsy=20, color_continuous_scale="Viridis")
62+
fig.show()
63+
```
64+
65+
Marginal plots can be added to visualize the 1-dimensional distributions of the two variables. Here we use a marginal [`histogram`](/python/histograms/). Other allowable values are `violin`, `box` and `rug`.
66+
67+
```python
68+
import plotly.express as px
69+
df = px.data.tips()
70+
71+
fig = px.density_heatmap(df, x="total_bill", y="tip", marginal_x="histogram", marginal_y="histogram")
72+
fig.show()
73+
```
74+
75+
Density heatmaps can also be [faceted](/python/facet-plots/):
76+
77+
```python
78+
import plotly.express as px
79+
df = px.data.tips()
80+
81+
fig = px.density_heatmap(df, x="total_bill", y="tip", facet_row="sex", facet_col="smoker")
82+
fig.show()
83+
```
84+
85+
### Other aggregation functions than `count`
86+
87+
By passing in a `z` value and a `histfunc`, density heatmaps can perform basic aggregation operations. Here we show average Sepal Length grouped by Petal Length and Petal Width for the Iris dataset.
88+
89+
```python
90+
import plotly.express as px
91+
df = px.data.iris()
92+
93+
fig = px.density_heatmap(df, x="petal_length", y="petal_width", z="sepal_length", histfunc="avg")
94+
fig.show()
95+
```
96+
97+
### 2D Histograms with Graph Objects
98+
99+
To build this kind of plot without using Plotly Express, we can use the `go.Histogram2d` class.
100+
101+
36102
### 2D Histogram of a Bivariate Normal Distribution ###
37103

38104
```python

doc/python/2d-histogram-contour.md

+67-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.1'
9-
jupytext_version: 1.1.1
8+
format_version: '1.2'
9+
jupytext_version: 1.3.1
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.7
23+
version: 3.6.8
2424
plotly:
2525
description: How to make 2D Histogram Contour plots in Python with Plotly.
2626
display_as: statistical
@@ -30,9 +30,73 @@ jupyter:
3030
order: 12
3131
page_type: u-guide
3232
permalink: python/2d-histogram-contour/
33+
redirect_from: python/2d-density-plots/
3334
thumbnail: thumbnail/hist2dcontour.png
3435
---
3536

37+
## 2D Histogram Contours or Density Contours
38+
39+
A 2D histogram contour plot, also known as a density contour plot, is a 2-dimensional generalization of a [histogram](/python/histograms/) which resembles a [contour plot](/python/contour-plots/) but is computed by grouping a set of points specified by their `x` and `y` coordinates into bins, and applying an aggregation function such as `count` or `sum` (if `z` is provided) to compute the value to be used to compute contours. This kind of visualization (and the related [2D histogram, or density heatmap](/python/2d-histogram/)) is often used to manage over-plotting, or situations where showing large data sets as [scatter plots](/python/line-and-scatter/) would result in points overlapping each other and hiding patterns.
40+
41+
## Density Contours with Plotly Express
42+
43+
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on "tidy" data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/). The Plotly Express function `density_contour()` can be used to produce density contours.
44+
45+
```python
46+
import plotly.express as px
47+
df = px.data.tips()
48+
49+
fig = px.density_contour(df, x="total_bill", y="tip")
50+
fig.show()
51+
```
52+
53+
Marginal plots can be added to visualize the 1-dimensional distributions of the two variables. Here we use a marginal [`histogram`](/python/histograms/). Other allowable values are `violin`, `box` and `rug`.
54+
55+
```python
56+
import plotly.express as px
57+
df = px.data.tips()
58+
59+
fig = px.density_contour(df, x="total_bill", y="tip", marginal_x="histogram", marginal_y="histogram")
60+
fig.show()
61+
```
62+
63+
Density contours can also be [faceted](/python/facet-plots/) and [discretely colored](/python/discrete-color/):
64+
65+
```python
66+
import plotly.express as px
67+
df = px.data.tips()
68+
69+
fig = px.density_contour(df, x="total_bill", y="tip", facet_col="sex", color="smoker")
70+
fig.show()
71+
```
72+
73+
Plotly Express density contours can be [continuously-colored](/python/colorscales/) and labeled:
74+
75+
```python
76+
import plotly.express as px
77+
df = px.data.tips()
78+
79+
fig = px.density_contour(df, x="total_bill", y="tip")
80+
fig.update_traces(contours_coloring="fill", contours_showlabels = True)
81+
fig.show()
82+
```
83+
84+
### Other aggregation functions than `count`
85+
86+
By passing in a `z` value and a `histfunc`, density contours can perform basic aggregation operations. Here we show average Sepal Length grouped by Petal Length and Petal Width for the Iris dataset.
87+
88+
```python
89+
import plotly.express as px
90+
df = px.data.iris()
91+
92+
fig = px.density_contour(df, x="petal_length", y="petal_width", z="sepal_length", histfunc="avg")
93+
fig.show()
94+
```
95+
96+
### 2D Histograms with Graph Objects
97+
98+
To build this kind of plot without using Plotly Express, we can use the `go.Histogram2d` class.
99+
36100
#### Basic 2D Histogram Contour
37101

38102
```python

0 commit comments

Comments
 (0)