Why ax patches has 2 bars 0?

def plot_categorical_vs_dummy(dataframe, categorical_var, dummy_var):
    """
    Plots a count plot of a categorical variable against a dummy variable,
    showing percentages instead of counts, with enhanced aesthetics.

    Parameters:
    dataframe (pd.DataFrame): The input DataFrame containing data.
    categorical_var (str): The name of the categorical variable column.
    dummy_var (str): The name of the dummy variable column (binary).

    Returns:
    None: Displays a count plot with percentages.
    """
    
    # Input validation
    if categorical_var not in dataframe.columns:
        raise ValueError(f"{categorical_var} is not a column in the DataFrame")
    if dummy_var not in dataframe.columns:
        raise ValueError(f"{dummy_var} is not a column in the DataFrame")

    # Set the aesthetic style of the plots
    sns.set(style="whitegrid")

    # Create a smaller figure
    plt.figure(figsize=(8, 5))  # Adjusted figure size for a smaller graph

    # Calculate percentages
    total_counts = dataframe.groupby(categorical_var)[dummy_var].value_counts(normalize=True).unstack().fillna(0) * 100
    total_counts = total_counts.reset_index().melt(id_vars=categorical_var, value_vars=total_counts.columns, var_name=dummy_var, value_name='percentage')
    
    # Create the bar plot showing percentages
    ax = sns.barplot(data=total_counts, x=categorical_var, y='percentage', hue=dummy_var, palette="Set2", edgecolor=".2")

    # Title and labels
    plt.title(f'Percentage of {categorical_var} by {dummy_var}', fontsize=14)
    plt.xlabel(categorical_var, fontsize=12)
    plt.ylabel('Percentage (%)', fontsize=12)

    # Adding annotations on bars
    for p in ax.patches:
        print(p)
        ax.annotate(f'{p.get_height():.1f}%', 
                    (p.get_x() + p.get_width() / 2, p.get_height()), 
                    ha='center', va='bottom', 
                    fontsize=10, color='black', 
                    rotation=0, 
                    xytext=(0, 3),  # 3 points vertical offset
                    textcoords='offset points')

    # Customize the legend
    plt.legend(title=dummy_var, title_fontsize='10', fontsize='10', loc='upper right')

    # Rotate x-axis labels for better readability
    plt.xticks(rotation=45)
    plt.tight_layout()

    # Show the plot
    plt.show()



def plot_categorical_vs_dummy(dataframe, categorical_var, dummy_var):
    """
    Plots a count plot of a categorical variable against a dummy variable,
    showing percentages instead of counts, with enhanced aesthetics.

    Parameters:
    dataframe (pd.DataFrame): The input DataFrame containing data.
    categorical_var (str): The name of the categorical variable column.
    dummy_var (str): The name of the dummy variable column (binary).

    Returns:
    None: Displays a count plot with percentages.
    """
    
    # Input validation
    if categorical_var not in dataframe.columns:
        raise ValueError(f"{categorical_var} is not a column in the DataFrame")
    if dummy_var not in dataframe.columns:
        raise ValueError(f"{dummy_var} is not a column in the DataFrame")

    # Set the aesthetic style of the plots
    sns.set(style="whitegrid")

    # Create a smaller figure
    plt.figure(figsize=(8, 5))  # Adjusted figure size for a smaller graph

    # Calculate percentages
    total_counts = dataframe.groupby(categorical_var)[dummy_var].value_counts(normalize=True).unstack().fillna(0) * 100
    total_counts = total_counts.reset_index().melt(id_vars=categorical_var, value_vars=total_counts.columns, var_name=dummy_var, value_name='percentage')
    
    # Create the bar plot showing percentages
    ax = sns.barplot(data=total_counts, x=categorical_var, y='percentage', hue=dummy_var, palette="Set2", edgecolor=".2")

    # Title and labels
    plt.title(f'Percentage of {categorical_var} by {dummy_var}', fontsize=14)
    plt.xlabel(categorical_var, fontsize=12)
    plt.ylabel('Percentage (%)', fontsize=12)

    # Adding annotations on bars
    for p in ax.patches:
        print(p)
        ax.annotate(f'{p.get_height():.1f}%', 
                    (p.get_x() + p.get_width() / 2, p.get_height()), 
                    ha='center', va='bottom', 
                    fontsize=10, color='black', 
                    rotation=0, 
                    xytext=(0, 3),  # 3 points vertical offset
                    textcoords='offset points')

    # Customize the legend
    plt.legend(title=dummy_var, title_fontsize='10', fontsize='10', loc='upper right')

    # Rotate x-axis labels for better readability
    plt.xticks(rotation=45)
    plt.tight_layout()

    # Show the plot
    plt.show()