简体   繁体   中英

Creating an image with imshow

I am trying to create an image when I have three arrays, the first two contain the pixel coordinates in x and y direction while the third one has the value each pixel should have. In the x direction there are 275 pixel and in the y direction there are 72. The x array consists of 72 times the entry 1, then 72 times the entry 2 and so on. The y array consists of entry counting up to 72 and then starting over again, so in total it counts to 72 275 times. For each of these pixel points I have a value for that specific pixel called rad.

fig = figure()
frame = fig.add_subplot(1,1,1)
im = frame.imshow((ix, iy, rad), cmap="inferno")
fig.colorbar(im)
show()

But the output image appears to be a flat one instead of a square one.

Output of the code

代码输出

Thanks in advance!

It looks like you want pcolormesh, rather than imshow. imshow works best when you want to display an array. As such it would only take rad as an argument. Instead you want pcolor which takes x and y coords, as well as an array showing the values at each x,y coord.

The catch is that ix, iy and rad all need to be the same dims for pcolor to work. This is easy however using numpy.meshgrid which will take them and generate the arrays you need. Try the following:

xx,yy = numpy.meshgrid(ix,iy)
frame.pcolormesh(xx,yy,rad,cmap='inferno')

This should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM