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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:31:29+00:00 2026-06-05T10:31:29+00:00

I wanted to plot using imshow in a manner similar to the second example

  • 0

I wanted to plot using imshow in a manner similar to the second example here http://www.scipy.org/Plotting_Tutorial but to redefine the scale for the axis. I’d also like the image to stay still while I do this!

The code from the example:

from scipy import *
from pylab import *

# Creating the grid of coordinates x,y 
x,y = ogrid[-1.:1.:.01, -1.:1.:.01]

z = 3*y*(3*x**2-y**2)/4 + .5*cos(6*pi * sqrt(x**2 +y**2) + arctan2(x,y))

hold(True)
# Creating image
imshow(z, origin='lower', extent=[-1,1,-1,1])

xlabel('x')
ylabel('y')
title('A spiral !')

# Adding a line plot slicing the z matrix just for fun. 
plot(x[:], z[50, :])

show()

If I modify the extent to be wider, eg:

imshow(z, origin='lower', extent=[-4,4,-1,1])

Then the resulting image is stretched. But all I wanted to do was change the ticks to coincide with my data. I know I can use pcolor to conserve the X and Y data, though that has other ramifications to it.

I found this answer which allows me to manually redo all the ticks:

How do I convert (or scale) axis values and redefine the tick frequency in matplotlib?

But that seems a bit overkill.

Is there a way to only change the extent shown by the labels?

  • 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-05T10:31:31+00:00Added an answer on June 5, 2026 at 10:31 am

    A help(imshow) will find the aspect argument, which after a bit of experimentation seems to give what you want (a square image of the spiral but with x scale from -4 to 4 and y from -1 to 1) when used like this:

    imshow(z, origin='lower', extent=[-4,4,-1,1], aspect=4)
    

    But now your plot is still from -1 to 1, so you’d have to modify that as well…

    plot(x[:]*4, z[50, :])
    

    I think when you have several elements that would have to be modified, just using a one-line tick relabeling instead isn’t overkill:

    xticks(xticks()[0], [str(t*4) for t in xticks()[0]])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to write something basic in assembly under Windows. I'm using NASM, but
I am using an example program from this code http://sicktoolbox.sourceforge.net/ > http://sourceforge.net/projects/sicktoolbox/files/ . It's
I wanted to check whether the variable is defined or not. For example, the
Just wanted to know if anyone is really using Objects and Collections in Oracle
I wanted to implement python com server using win32com extensions. Then consume the server
I made a line graph (with a data-line indicator and plotsymbols) using core plot.
I wanted to make a simple R plot with y-axis labels centered above the
I have several plt.plot instances and I wanted to only plt.show() certain objects. To
Several times I have wanted to detect single keystrokes in R but have failed
In my work, I frequently display scatterplots using text labels. That's meant a plot()

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.