You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: notebooks/histograms.md
+33-33Lines changed: 33 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ jupyter:
40
40
41
41
## Histogram with plotly express
42
42
43
-
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.
43
+
In statistics, 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. More generally, in plotly a histogram is an aggregated bar chart, with several possible aggregation functions (e.g. sum, average, count...). Also, the data to be binned can be numerical data but also categorical or date data.
44
44
45
45
Plotly express functions take as argument a tidy [pandas DataFrame](https://pandas.pydata.org/pandas-docs/stable/getting_started/10min.html).
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.
@@ -81,9 +89,9 @@ tips = px.data.tips()
81
89
fig = px.histogram(tips, x="total_bill",
82
90
title='Histogram of bills',
83
91
labels={'total_bill':'total bill'}, # can specify one label per df column
84
-
opacity=0.6,
92
+
opacity=0.8,
85
93
log_y=True, # represent bars with log scale
86
-
color_discrete_sequence=['red'] # color of histogram bars
94
+
color_discrete_sequence=['indianred'] # color of histogram bars
87
95
)
88
96
fig.show()
89
97
```
@@ -122,12 +130,12 @@ fig.show()
122
130
123
131
## Histograms with go.Histogram
124
132
125
-
When data are not available as tidy dataframes, it is also possible to use the more generic `go.Histogram` from `plotly.graph_objs`. All of the available histogram options are described in the histogram section of the reference page: https://plot.ly/python/reference#histogram.
133
+
When data are not available as tidy dataframes, it is also possible to use the more generic `go.Histogram` from `plotly.graph_objects`. All of the available histogram options are described in the histogram section of the reference page: https://plot.ly/python/reference#histogram.
For custom binning along x-axis, use the attribute [`nbinsx`](https://plot.ly/python/reference/#histogram-nbinsx). Please note that the autobin algorithm will choose a 'nice' round bin size that may result in somewhat fewer than `nbinsx` total bins. Alternatively, you can set the exact values for [`xbins`](https://plot.ly/python/reference/#histogram-xbins) along with `autobinx = False`.
292
292
293
293
```python
294
-
import plotly.graph_objsas go
294
+
import plotly.graph_objectsas go
295
295
from plotly.subplots import make_subplots
296
296
297
297
x = ['1970-01-01', '1970-01-01', '1970-02-01', '1970-04-01', '1970-01-02',
0 commit comments