python - How do I change the scale of imshow in matplotlib without stretching the image? -
i wanted plot using imshow in manner similar second example here http://www.scipy.org/plotting_tutorial redefine scale axis. i'd image stay still while this!
the code example:
from scipy import * pylab import * # creating 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 line plot slicing z matrix fun. plot(x[:], z[50, :]) show()
if modify extent wider, eg:
imshow(z, origin='lower', extent=[-4,4,-1,1])
then resulting image stretched. wanted change ticks coincide data. know can use pcolor conserve x , y data, though has other ramifications it.
i found answer allows me manually redo ticks:
how convert (or scale) axis values , redefine tick frequency in matplotlib?
but seems bit overkill.
is there way change extent shown labels?
a help(imshow)
find aspect
argument, after bit of experimentation seems give want (a square image of spiral x scale -4 4 , y -1 1) when used this:
imshow(z, origin='lower', extent=[-4,4,-1,1], aspect=4)
but plot
still -1 1, you'd have modify well...
plot(x[:]*4, z[50, :])
i think when have several elements have modified, using one-line tick relabeling instead isn't overkill:
xticks(xticks()[0], [str(t*4) t in xticks()[0]])
Comments
Post a Comment