0
votes

My dataframe columns are employee and X-Folder. This is the example of data:

enter image description here

For every unique employee I count the number of each X-Folder. In this case X-Folders are contacts, straw, conference etc. I plot graph using: from collections import Counter

for e in employees:

        topics = df1.loc[df1.employee==e , "X-Folder"]

        letter_counts = Counter(topics)

        df2 = pd.DataFrame.from_dict(letter_counts, orient='index')
        ax = df2.plot( kind='bar',figsize=(10,10))

It is working just fine. The only problem is that x-ticks are not fixed. For example for first employee conference, meetings , active international is zero. So, it won't show these on x axis and will only show contacts and straw. I want a graph that shows all the labels.

Edit: I want all the topics shown on x axis with only relevant counter values plotted Edit: This is what I have done. I have stored all the topics in a list and in the dictionary letter_counts I just assign it the value zero. It works fine for the bar graph: import matplotlib.pyplot as plt from collections import Counter topic = df1["X-Folder"].unique()

for e in employees:

        topics = df1.loc[df1.employee==e , "X-Folder"]

        letter_counts = Counter(topics)
        for t in topic:
            if str(t) not in letter_counts.keys():
                letter_counts[t] = 0

        df2 = pd.DataFrame.from_dict(letter_counts, orient='index')
        ax = df2.plot( kind='bar',figsize=(20,10))

This is the output enter image description here

But for the area graph it doesnt work (only prints 4 of the topics from a total of 23 topics):

enter image description here

1

1 Answers

0
votes

Try this, putting in your own values for x of course.

From StackOverflow: Changing the “tick frequency” on x or y axis in matplotlib?

x = [1,10,20,30,40,50,60,70,80,90]
plt.xticks(np.arange(min(x), max(x)+1, 1.0))