Skip to content

Instantly share code, notes, and snippets.

View grouped_bar_chart_show_label.py
import pandas as pd
import matplotlib.pyplot as plt
# get input data
df = pd.read_csv('./gdp_capita.csv')
ax = df.plot.bar(x='Year', width=0.8)
ax.set_ylabel('GDP/capita (USD)')
for container in ax.containers:
View grouped_bar_chart.py
import pandas as pd
import matplotlib.pyplot as plt
# get input data
df = pd.read_csv('./gdp_capita.csv')
ax = df.plot.bar(x='Year')
ax.set_ylabel('GDP/capita (USD)')
plt.tight_layout()
plt.show()
View bar_chart_show_value.py
# import necessary libraries
import pandas as pd
import matplotlib.pyplot as plt
# get input data
df = pd.read_csv('./data.csv')
ax = df.plot(x='Year', y='Item 1',
kind='bar')
ax.set_ylabel("Price (USD)")
View bar_chart.py
# import necessary libraries
import pandas as pd
import matplotlib.pyplot as plt
# get input data
df = pd.read_csv('./data.csv')
ax = df.plot(x='Year', y='Item 1',
kind='bar')
ax.set_ylabel("Price (USD)")
View data.csv
Year Item 1
1990 5
1995 7
2000 10
2005 12
2010 15
2015 18
2020 22
View data_multiple_line.csv
Year Item 1 Item 2
1990 5 2
1995 7 4
2000 10 6
2005 12 8
2010 15 10
2015 18 12
2020 22 14