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 8839187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:11:02+00:00 2026-06-14T10:11:02+00:00

I am working on identifying tumors in CT images, using SciPy. Once I’ve identified

  • 0

I am working on identifying tumors in CT images, using SciPy. Once I’ve identified the slice containing the tumor, I retrieve the slice using:

slice_x, slice_y = ndimage.find_objects(label_im==label)[0]

I then plot the full image as follows:

plt.imshow(image, cmap='gray')

I want to overlay the contour of the extracted slice (containing the tumor) on top of the original image in the appropriate location. However, I can’t get the contour plot to lie on top of the proper region. Instead, the contour plot always lies in the top-left corner of the image. Here’s what I’m using:

plt.contour(mask[slice_x, slice_y], position=(slice_x.start, \
slice_y.start), linewidths=2, colors='r')

Here is the result:

CT image

How can I set the position of the contour plot inside the main plot? Thanks!

  • 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-14T10:11:03+00:00Added an answer on June 14, 2026 at 10:11 am

    You need to use the extent keyword argument instead of position. However, you’ll need to specify a maximum as well as a start (i.e. it needs to be extent=[xmin, xmax, ymin, ymax])

    In your case, it would look something like:

    extent=[xslice.start, xslice.stop+1, yslice.start, yslice.stop+1]
    plt.contour(mask[xslice, yslice], extent=extent)
    

    Note that you may need to use the origin keyword argument (or flip ymin and ymax) to control the way the input data is interpreted.

    Alternately, you could do something like the following:

    x, y = np.mgrid[xslice, yslice]
    plt.contour(x, y, mask[xslcie, yslice])
    

    It will be a bit inefficient if you’re working with a large region, but it’s much cleaner.

    As a full example of the latter approach:

    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.cm as cm
    
    data = np.random.random((100,100))
    
    xslice, yslice = slice(20, 30), slice(45, 65)
    
    plt.imshow(data, cmap=cm.gray)
    
    x, y = np.mgrid[xslice, yslice]
    plt.contour(x, y, data[xslice, yslice])
    
    plt.show()
    

    enter image description here

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

Sidebar

Related Questions

Working on a small game using an HTML5 canvas, and javascript. And it's working
Working on a project using Entity Framework (4.3.1.0). I'm trying to figure out how
I'm working a a project for a new web app. I'm identifying the key
I'm currently working on a very simple calendar using Jquery. Actually, We need a
I am trying to retrieve mysql data using php(products.php) and return the data in
I am working on my first implementation of a jqGrid . I am using
Working with an undisclosed API, I found a function that can set the number
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working with H2 I get this error when I try to write a row
Working on the problems on Project Euler to try to learn Clojure. I'm on

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.