File size: 1,291 Bytes
dc06294
 
f8e763e
 
dc06294
b8b708a
 
dc06294
b8b708a
 
 
 
 
 
 
 
 
 
 
 
cc58222
 
 
 
b8b708a
 
 
 
 
 
 
bd38b84
b8b708a
 
 
 
 
 
dc06294
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from excel_chat import get_columns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np


def create_bar_plot(file, x_values, y_values):
    df = pd.read_excel(file)

    df['Simple_Source'] = df[x_values].apply(lambda x: x.split()[0].split(',')[0] if type(x)==str else np.nan)

    if y_values == "":
        counts = df['Simple_Source'].value_counts()
        fig = plt.figure(figsize=(10, 6))
        counts.plot(kind='bar')
        plt.title(f'Count of First Words in {x_values}')
        plt.xlabel('First Word')
        plt.ylabel('Count')
    else:
        count_df = df.groupby(['Type', 'Simple_Source']).size().unstack(fill_value=0)
        fig, ax = plt.subplots(figsize=(10, 7))

        count_df.plot(kind='bar', stacked=True, ax=ax)

        
        plt.legend(title='Shop', bbox_to_anchor=(1.05, 1), loc='upper left')
        
        plt.xlabel(y_values)
        plt.ylabel('Number of Contributions')
        plt.title(f'Number of Contributions by {y_values} and {x_values}')

        for i, bar in enumerate(fig.patches):
            h = bar.get_height()
            w = bar.get_width()
            x = bar.get_x()
            y = bar.get_y()
            if h > 0:
                plt.text(x + w/2, y + h/2, int(h), ha='center', va='center')
    return fig