Official pandas documentation. Specifications of plot.bar.
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.bar.html
sample.csv
Fictitious data created by myself. Shows the sales of companies that sell alcoholic beverages. Monthly sales amount of beer and sake (100 million yen). For example, in February, beer (beer) sold 43.1 billion yen and sake (sake) sold 26.7 billion yen.
month,beer,sake
1,1024,667
2,431,267
3,341,166
4,530,461
5,482,367
6,339,331
7,1203,227
8,1376,312
9,896,211
10,754,361
11,561,325
12,938,452
Below, implementation in python.
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
df = pd.read_csv('csv/sample.csv')
The contents of df are as follows.
df.plot.bar('month', 'beer')
The horizontal axis is "month" and the vertical axis is "beer sales amount (100 million yen)".
df.plot.bar('month', 'sake')
The horizontal axis is "month" and the vertical axis is "sake sales amount (100 million yen)".
df.plot.bar('month',{'beer','sake'} )
The horizontal axis is "month" and the vertical axis is "sales amount of beer (blue) and sake (orange) (100 million yen)".
You can see the following.
Add stacked = True
to make a stacked graph.
df.plot.bar('month',{'beer','sake'}, stacked=True)
The horizontal axis is "month" and the vertical axis is "sales amount (100 million yen) of beer (blue) and sake (orange)" (accumulated).
You can see the following.
df.plot.bar(
'month',{'beer','sake'},
color={"beer": "red", "sake": "green"}
)
df.plot.bar(
'month',{'beer','sake'},
color={"beer": "red", "sake": "green"},
stacked=True
)
Specify with figsize
.
figsize=(5,5)
df.plot.bar(
'month',{'beer','sake'},
figsize=(5,5)
)
figsize=(8,5)
figsize=(5,10)
Recommended Posts