我有一个2 * 4的方框图,每个方框包含21个方框。对于它们每个,我想绘制每个数据框列的最后一个值。
fig,axes = plt.subplots(2, 4, figsize = (40,20))
deltas = np.arange(0.0, 1.05, 0.05)
l_stringss = [['call_this_month_', 'call_next_month_', 'call_this_quarter_','call_next_quarter_'],
['put_this_month_','put_next_month_', 'put_this_quarter_', 'put_next_quarter_']]
for l_strings in l_stringss:
i = l_stringss.index(l_strings)
for string in l_strings:
j = l_strings.index(string)
vol_dict = {}
for delta in deltas:
option = pd.read_csv(string + str(delta) + '.csv')
vol_dict[delta] = option.vol.values
vols = pd.DataFrame(dict([(k,pd.Series(v)) for k, v in vol_dict.items()]))
if 'call' in string:
order = deltas
elif 'put' in string:
order = deltas[::-1]
sns.boxplot(data = vols, order = order, ax = axes[i][j]).set_title(string[:-1])
输入数据示例:
date id strike vol delta
0 2015-03-24 10000097 2.8 0.441618 0.005203
1 2015-03-25 10000097 2.8 0.013609 0.008506
2 2015-04-20 10000175 3.4 0.564792 0.015379
3 2015-04-21 10000167 3.3 0.366533 0.005255
4 2015-04-22 10000175 3.4 0.003894 0.021423