Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8049407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:46:38+00:00 2026-06-05T06:46:38+00:00

I am walking along a directory using walk function > searching for a .cnt

  • 0

I am walking along a directory using walk function > searching for a .cnt file > counting interested value > plotting ’em in a pie chart. But the problem is when my prog processes for the first folder and plots, it acts fine.But after that whatever folder it reads and plots it get overlapped. Can’t understand if bug in my code. I used like:

for root,dirs,files in os.walk(path):
    aspCount = 0
    gluCount = 0
    aspCountCol1 = 0
    aspCountCol2 = 0
    gluCountCol1 = 0
    gluCountCol2 = 0

    listOfFile = glob.iglob(os.path.join(root,'*.cnt'))
    for filename in listOfFile:
        inp = open(filename,'r').read().strip().split('\n')
        for line in map(str.split,inp):

            k = line[-1]
            m = line[0]
            if k == 'ASP':
               aspCountCol1 += 1
            elif m == 'ASP':
               aspCountCol2 += 1
            if k == 'GLU':
               gluCountCol1 += 1
            elif m == 'GLU'
               gluCountCol1 +=1
                     # here lies the problem for me !!!!
        aspCount = aspCountCol1 + aspCountCol1
        gluCount = gluCountCol1 + gluCountCol1
        #now plotting......
        from pylab import *
        figure(1, (figsize=(8,8))
        labels = 'asp','glu'
        fracs = [asp_count,glu_count]
        pie(fracs,explode=None,labels=labels,autopct='%1.1f%%',shadow=False)
        c = 'fig.png'
        savefig(os.path.join(root,c))

now, the problem is: with this code if i process a directory with various sub-folders containing .cnt file, it goes error free. But the graph generated by the first folder, it be fine but when prog goes to process the next folder it sucessfully process the data but the graph generated is overlapped with the previous one.
the file i was processing was:

LYS  ARG
ASP  GLU
GLU  SAP
JAS  ASP
SAK  GLU
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:46:40+00:00Added an answer on June 5, 2026 at 6:46 am

    You need to clear your pylab plots between plots with clf().

    Also, no reason to from pylab import * multiple times.

    (I prefer to use the matplotlib api when plotting in a loop like that)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On a mac in python 2.7 when walking through directories using os.walk my script
I've implemented a directory walking algorithm for the Windows Shell using IShellItem , IShellFolder
I can't figure out how to inspect a currently executing function using inspect /
I am walking through a xml definition file and I have a DOMNodeList that
I am doing motion recognition of walking using openCV and C++ and I would
I'm using google overlays to draw my walking route in real time, I have
I was walking view definitions in a database today using sqlalchemy 0.6 (using get_view_definition())
Ok, I'm certainly familiar with walking through a table using a read-only cursor, but
Above are four images of a character walking along the ground from the bottom
We have an array of heights, representing the altitude along a walking trail. Given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.