Skip to content

[MRG] histogram nb #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 21, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
plotly.express
  • Loading branch information
emmanuelle committed Jun 16, 2019
commit 4d285aef58e99a4c18115062029c8ba3db7b8c6f
18 changes: 9 additions & 9 deletions notebooks/histograms.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jupyter:

A [histogram](https://en.wikipedia.org/wiki/Histogram) is representation of the distribution of numerical data, where the data are binned and the count for each bin is represented.

Plotly express functions *(TODO here needs link to stable px doc entry)* take as argument a tidy [pandas DataFrame](https://pandas.pydata.org/pandas-docs/stable/getting_started/10min.html).
Plotly express functions take as argument a tidy [pandas DataFrame](https://pandas.pydata.org/pandas-docs/stable/getting_started/10min.html).

```python
import plotly_express as px
import plotly.express as px
tips = px.data.tips()
fig = px.histogram(tips, x="total_bill")
fig.show()
Expand All @@ -56,7 +56,7 @@ fig.show()
By default, the number of bins is chosen so that this number is comparable to the typical number of samples in a bin. This number can be customized, as well as the range of values.

```python
import plotly_express as px
import plotly.express as px
tips = px.data.tips()
fig = px.histogram(tips, x="total_bill", nbins=20)
fig.show()
Expand All @@ -67,7 +67,7 @@ fig.show()
The default mode is to represent the count of samples in each bin. With the `histnorm` argument, it is also possible to represent the percentage or fraction of samples in each bin (`histnorm='percent'` or `probability`), or a density histogram (the sum of bars is equal to 100, `density`), or a probability density histogram (sum equal to 1, `probability density`).

```python
import plotly_express as px
import plotly.express as px
tips = px.data.tips()
fig = px.histogram(tips, x="total_bill", histnorm='probability density')
fig.show()
Expand All @@ -76,7 +76,7 @@ fig.show()
#### Aspect of the histogram plot

```python
import plotly_express as px
import plotly.express as px
tips = px.data.tips()
fig = px.histogram(tips, x="total_bill",
title='Histogram of bills',
Expand All @@ -91,7 +91,7 @@ fig.show()
#### Several histograms for the different values of one column

```python
import plotly_express as px
import plotly.express as px
tips = px.data.tips()
fig = px.histogram(tips, x="total_bill", color="sex")
fig.show()
Expand All @@ -102,18 +102,18 @@ fig.show()
For each bin of `x`, one can compute a function of data using `histfunc`. The argument of `histfunc` is the dataframe column given as the `y` argument. Below the plot shows that the average tip increases with the total bill.

```python
import plotly_express as px
import plotly.express as px
tips = px.data.tips()
fig = px.histogram(tips, x="total_bill", y="tip", histfunc='avg')
fig.show()
```

#### Visualizing the distribution

With the `marginal` keyword, a subplot is drawn alongside the histogram, visualizing the distribution.
With the `marginal` keyword, a subplot is drawn alongside the histogram, visualizing the distribution. See [the distplot page](https://plot.ly/python/distplot/)for more examples of combined statistical representations.

```python
import plotly_express as px
import plotly.express as px
tips = px.data.tips()
fig = px.histogram(tips, x="total_bill", color="sex", marginal="rug", # can be `box`, `violin`
hover_data=tips.columns)
Expand Down