graph_analysis.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:workout-analyzer 作者: mctrinkle 项目源码 文件源码
def plot_volume_inensity_analysis_stacked_bar_graph(mus_names, wo_dates_list,
                                                    mus_vol, mus_int):

    x = wo_dates_list

    c_1 = np.array(mus_vol)
    c_1_colors = colors
    c_1_labels = mus_names
    c_2 = np.array(mus_int)
    c_2_colors = colors
    c_2_labels = c_1_labels
    ind = np.arange(len(c_1[0]))    
    width = .8   
    f, ax = plt.subplots(2, 1, sharex=True, figsize=(17,11))
    f.subplots_adjust(bottom=0.5) #make room for the legend
    locs, labels = plt.xticks()
    plt.setp(labels, rotation=25)
    p = [] # list of bar properties

    def create_subplot(matrix, colors, axis, title, dates):
        bar_renderers = []
        #ind = np.arange(matrix.shape[1])
        ind = dates
        bottoms = np.cumsum(np.vstack((np.zeros(matrix.shape[1]), matrix)), axis=0)[:-1]
        for i, row in enumerate(matrix):
            r = axis.bar(ind, row, width=0.5, color=colors[i], bottom=bottoms[i])
            bar_renderers.append(r)
        axis.set_title(title)
        axis.set_xlim((x[0],x[-1]))
        axis.xaxis_date()
        return bar_renderers

    p.extend(create_subplot(c_1, c_1_colors, ax[0], 'Volume', x))
    p.extend(create_subplot(c_2, c_2_colors, ax[1], 'Intensity', x))

    plt.suptitle('Volume and Intensity by Muscle Group')
    ax[0].set_ylabel('Total Volume') # add left y label
    ax[1].set_ylabel('Total Intensity') # add left y label
    ax[0].grid(True, color='w')
    ax[0].set_axis_bgcolor('black')
    ax[1].grid(True, color='w')
    ax[1].set_axis_bgcolor('black')
    f.legend(((x[0] for x in p)), # bar properties
             (c_1_labels), 
             bbox_to_anchor=(0.5, 0), 
             loc='lower center',
             ncol=4)
    f.canvas.set_window_title('WorkoutAnalyzer - Volume and Intensity by Muscle Group')
    f.set_size_inches(20,20)
    plt.subplots_adjust(left=0.08, bottom=0.20, right=0.9, top=0.93, wspace=0.20, hspace=0.10)
    plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号