2

Basically what I have to do is draw a NxN grid within certain boundaries given by a boundingBox and write a function for that. My idea is that I should draw horizontal and vertical lines and calculating the width and height by dividing the range of the boundaries by N. Then I want to draw the lines with pyplot using the ends of the lines, and this is where I'm having trouble. I have something like this, but it's not well thought out. The boundingBox is basically coordinates.

def drawGridLines(boundingBox, N):
    lonrange = boundingBox[1][0] - boundingBox[0][0]
    latrange = boundingBox[1][1] - boundingBox[0][1]
    lonpieces = lonrange/N
    latpieces = latrange/N

    while (lonpieces <= N):
        lon = lonpieces
        pylab.plot(lon)
        lonpieces = lonpieces + (lonrange/N)

This is what I have

This is what I want to have now

1
  • 1
    See axhline and axvline in the matplotlib module. They're used for drawing horizontal and vertical lines (respectively) on graphs. Commented Nov 22, 2011 at 4:30

1 Answer 1

1

I don't know too much about Python or Pylab, so I'm not sure I can fully answer your question, but I might be able to give some insight. It seems like you want each iteration of the loop to draw a line. It seems then like you may need two loops, not just one.

I would imagine your first loop may look something like:

//introduce some sort of counter variable
count =0
while(count <= N):
    //draw a vertical line at appropriate spot
    drawSpot = boundingBox[0][0] + count * lonPieces
    count = count +1

and your second loop may look like:

count =0
while(count <= N):
    //draw a horizontal line at appropriate spot
    drawSpot = boundingBox[0][1] + count * latPieces
    count = count +1

I may have horizontal and vertical mixed up, but I hope the pattern is clear. If you you have any questions , please leave a comment. Good luck!

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

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.