【发布时间】:2017-11-23 22:29:25
【问题描述】:
我正在尝试将多个条形图垂直叠加。应该有一个标记为 x 轴(带有星期几)。我到目前为止的代码是:
import pandas as pd
import matplotlib.pyplot as plt
import calendar
df = pd.read_csv("health.csv", header = None, names = ['Physical', 'Emotional'])
# Get Dayofweek index number (start with 6 for sunday) 6,0,1....
df['DayOfTheWeek'] = [(i+6) % 7 for i in range(len(df))]
# Get a map to translate to day of week
d = dict(zip(range(7),list(calendar.day_name)))
df['DayOfTheWeek'] = df['DayOfTheWeek'].map(d)
# Loop through the df (splitting week by week)
for i in range(int(round(len(df)/7))):
plt.ylim([0,10])
df.iloc[i*7:(i+1)*7].set_index('DayOfTheWeek').plot(kind='bar')
plt.show()
这有以下问题:
- 由于某些原因,生成的第一张图是空白的。
- 我希望同一图表上的子图垂直分开,而不是许多单独的图
- 我的数据框有 39 行,但上面的方法根本没有绘制最后 4 个点。
完整的输入数据是:
5,5
6,7
6,9
6,7
5,6
7,9
5,9
6,7
7,6
7,4
7,5
6,7
7,9
7,9
5,6
8,7
9,9
7,7
7,6
7,8
7,9
7,9
7,6
7,8
6,6
6,6
6,7
6,6
6,5
6,6
7,5
7,5
7,5
7,6
7,5
8,6
7,6
7,7
6,6
【问题讨论】:
标签: python pandas matplotlib