我会尝试在一个时间序列上做一个堆叠的条形图,但我得到了图片上的下图。如何更改代码以放弃图表X轴上的周末
事先谢谢你,罗兰
import numpy as np
import matplotlib.pyplot as plt
a = profit[t0:]['FX'].tolist()
b = profit[t0:]['Price'].tolist()
ind = np.array(profit[t0:].index.values)
data = np.array([a, b])
data_shape = np.shape(data)
# Take negative and positive data apart and cumulate
def get_cumulated_array(data, **kwargs):
cum = data.clip(**kwargs)
cum = np.cumsum(cum, axis=0)
d = np.zeros(np.shape(data))
d[1:] = cum[:-1]
return d
cumulated_data = get_cumulated_array(data, min=0)
cumulated_data_neg = get_cumulated_array(data, max=0)
# Re-merge negative and positive data.
row_mask = (data<0)
cumulated_data[row_mask] = cumulated_data_neg[row_mask]
data_stack = cumulated_data
cols= ["#1da1f1", "#02395b"]
fig = plt.figure()
ax5 = plt.subplot(111)
for i in np.arange(0, data_shape[0]):
ax5.bar(ind, data[i], bottom=data_stack[i], color=cols[i],)
ax5.xaxis.set_major_formatter(myFmt);
plt.tight_layout()
plt.show()
目前没有回答
相关问题 更多 >
编程相关推荐