1

I have this code:

from matplotlib.pylab import plt

abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',]

def countp(counter):
    count=0
    for i in counter:
        print(abc[count],"showed up ",i," times")
        count+=1

def checkfile(folder):     
    file = open(folder,"r")
    read=file
    abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',]
    counter = [0]*26
    #read file
    for i in file:
        # reads line
        for j in i:
            count=0
            #search one key at a time
            for k in abc:
                if (j==k.lower()):
                    #add +1 to desired letter. 
                    counter[count]+=1
                count+=1
    return counter

if __name__ == "__main__":
    folder="C:/Users/omerd/Desktop/Welp.txt"
    counter=checkfile(folder)
    countp(counter)
    x=5
    y=6
    plt.plot(x, y)

it does run, but it doesn't use the

    plt.plot(x, y)

line. It should open a chart, but it doesn't, not sure if newbie mistake or need to reinstall everything.

1
  • have a look at collections.Counter, why do you have 2 abc variables, look at the strings module, use context managers with open(...) as file: Commented Jan 12, 2021 at 14:49

2 Answers 2

2

Many Documentations Don't mention this but try adding plt.show() at the after plt.plot(). plt.show() is just to open the matplotlib plot

Sign up to request clarification or add additional context in comments.

Comments

1

The solution to your problem is to add plt.show() at the end of your code. This will display your plot.

From matplotlib's official documentation: When running in ipython with its pylab mode, display all figures and return to the ipython prompt.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.