from matplotlib import colors
def plot_prop_time_v2(df_list, pointcolumns, date_col, group_dates='month', normalize = False):
    '''
    plot_prop_time – функция построения графика изменения побакетного распределения с течением времени. Входные параметры:
    1) df_list – список выборок(train, val, test);
    2) group_dates – тип группировки наблюдений по датам: 'Month', 'Quart' или 'Half-year';
    3) pointcolumns – список столбцов-факторов;
    4) date_col – столбец-дата;
    5) normalize - флаг нормализации;
    6) word_template - флаг сохранения в вордовский файл шаблона для количественных тестов, по умолчанию 0 (0 - нет, 1 - да);
    '''
    
    color_list = list(colors.TABLEAU_COLORS.values())
    group_date = date_col+'_modify'

    for i in pointcolumns:
        fig, ax = plt.subplots()
        fig.set_size_inches(18,10)
        if normalize: ax.set_ylim([0, 1.055])
    
        for df_tr in df_list:
            if df_tr[i].nunique() > 10:
                    sys.exit('Too many colors for', df_tr.name, ', change this function.')
        date=[]
        q = sorted(pd.concat(df_list)[i].unique())
        for n, DF in enumerate(df_list):
            DF[group_date] = vtests.group_date_func(DF, date_col, group_dates) + '_{}'.format(n)
            test = DF.groupby([group_date, i]).size().to_frame(name="Num").reset_index()
            df = pd.DataFrame([[x,y] for x in DF[group_date].unique() for y in DF[i].unique()], columns =[group_date, i])
            test = df.merge(test, on=[group_date, i], how='left').fillna(0).sort_values(by=[group_date, i])
            if normalize == True:
                test['Num'] = test.groupby([group_date])["Num"].transform(lambda x: x/x.sum())

            DF = DF.sort_values(group_date)
            date_for_data_name=list(DF[group_date].unique())+([' '*(n+1)] if n+1<len(df_list) else [])
            date = date + date_for_data_name
            print(date)
            bot = 0
            for j in range(len(q)):
                print(n)
                bar=np.append((np.array(test[test[i] == q[j]]['Num'])),([0] if n+1<len(df_list) else []))
                plt.bar(date_for_data_name, bar, bottom = bot, color=color_list[j])        
                bot = bot + bar
        xticks =[x[:-2] if ((x[-4:-2] in ['01','04','07','10'])|(group_dates!='month')) else '' for x in date]
        plt.title(i,fontsize=36)
        plt.xlabel(group_dates, fontsize=20)
        plt.ylabel("Percentage" if normalize == True else "Count", fontsize=20)
        plt.xticks(list(range(len(date))), xticks, rotation=90,fontsize=26)
        plt.yticks(fontsize=26)
#        plt.legend([round(i, 2) for i in q],loc='upper center',bbox_to_anchor=(0.5,-0.25),
#                   fontsize='20', fancybox=True,ncol=len(q))
        plt.legend(q,loc='upper center',bbox_to_anchor=(0.5,-0.25),
                   fontsize='20', fancybox=True,ncol=len(q)/2, )    
    
    
        #расчет расположения подписей
        len_ticks=0
        for n, df_tr in enumerate(df_list):
            len_dt = len_ticks + math.ceil(len(df_tr[group_date].unique())/2)-1*((n+1)%3==0)
            plt.text(date[len_dt-1], 1.01, str.upper(df_tr.name), fontsize=26)
            len_ticks += len(df_tr[group_date].unique())+1.  ValueError                                Traceback (most recent call last)
Cell In[54], line 5
      3 for i in range(len(cat_features)):
      4     print(cat_features[i])
----> 5     plot_prop_time_v2(df_list = [data_dev,data_val,data_oot], 
      6                         pointcolumns = [cat_features[i]], 
      7                         # cont_columns = [],
      8                         date_col = 'APP_DATE_month', 
      9                         group_dates='quarter', 
     10                         normalize = True)

Cell In[53], line 42, in plot_prop_time_v2(df_list, pointcolumns, date_col, group_dates, normalize)
     40         print(n)
     41         bar=np.append((np.array(test[test[i] == q[j]]['Num'])),([0] if n+1<len(df_list) else []))
---> 42         plt.bar(date_for_data_name, bar, bottom = bot, color=color_list[j])        
     43         bot = bot + bar
     44 xticks =[x[:-2] if ((x[-4:-2] in ['01','04','07','10'])|(group_dates!='month')) else '' for x in date]

File c:\Work\Anaconda3\envs\py_modeler\lib\site-packages\matplotlib\pyplot.py:2739, in bar(x, height, width, bottom, align, data, **kwargs)
   2728 @_copy_docstring_and_deprecators(Axes.bar)
   2729 def bar(
   2730     x: float | ArrayLike,
   (...)
   2737     **kwargs,
...
    425     # ironically, np.broadcast does not properly handle np.broadcast
    426     # objects (it treats them as scalars)
    427     # use broadcasting to avoid allocating the full array

ValueError: shape mismatch: objects cannot be broadcast to a single shape.  Mismatch is between arg 0 with shape (2,) and arg 1 with shape (0,).  Как исправить эту ошибку? Из-за чего она происходит?