@@ -34,6 +34,7 @@ jupyter:
34
34
permalink : python/bar-charts/
35
35
thumbnail : thumbnail/bar.jpg
36
36
title : Bar Charts | plotly
37
+ v4upgrade : true
37
38
---
38
39
39
40
### Bar chart with plotly express
@@ -43,7 +44,7 @@ Plotly express functions (here needs link to stable px doc entry) take as argume
43
44
In a bar plot, each row of the DataFrame is represented as a rectangular mark.
44
45
45
46
``` python
46
- import plotly_express as px
47
+ import plotly.express as px
47
48
data_canada = px.data.gapminder().query(" country == 'Canada'" )
48
49
fig = px.bar(data_canada, x = ' year' , y = ' pop' )
49
50
fig.show()
@@ -58,7 +59,7 @@ data_canada
58
59
The bar plot can be customized using keyword arguments * TODO here link to meta doc page on customizing plotly plots?* .
59
60
60
61
``` python
61
- import plotly_express as px
62
+ import plotly.express as px
62
63
data = px.data.gapminder()
63
64
64
65
data_canada = data[data.country == ' Canada' ]
@@ -71,14 +72,15 @@ fig.show()
71
72
When several rows share the same value of ` x ` (here Female or Male), the rectangles are stacked on top of one another by default.
72
73
73
74
``` python
74
- import plotly_express as px
75
+ import plotly.express as px
75
76
tips = px.data.tips()
76
77
fig = px.bar(tips, x = " sex" , y = " total_bill" , color = ' time' )
77
78
fig.show()
78
79
```
79
80
80
81
``` python
81
82
# Change the default stacking
83
+ import plotly.express as px
82
84
fig = px.bar(tips, x = " sex" , y = " total_bill" , color = ' smoker' , barmode = ' group' ,
83
85
height = 400 )
84
86
fig.show()
@@ -89,6 +91,7 @@ fig.show()
89
91
Use the keyword arguments ` facet_row ` (resp. ` facet_col ` ) to create facetted subplots, where different rows (resp. columns) correspond to different values of the dataframe column specified in ` facet_row ` .
90
92
91
93
``` python
94
+ import plotly.express as px
92
95
fig = px.bar(tips, x = " sex" , y = " total_bill" , color = " smoker" , barmode = " group" ,
93
96
facet_row = " time" , facet_col = " day" ,
94
97
category_orders = {" day" : [" Thur" , " Fri" , " Sat" , " Sun" ],
0 commit comments