Trying to understand how imagesc works compared to scatter.
Mostrar comentarios más antiguos
I have gridded data of mean tropopause temperature along with its longitude-latitude coordinates. I have done a scatter plot with this data so I know what it's supposed to look like. I recently saw a video about Matlab's Climate Toolbox, and in it, they used the function imagescn. I wanted to try out imagesc first to understand it a bit better but found that the output that I got had my data rotated 90 degrees compared to when I used a scatter plot. The grid of z-values were rotated but that x and y-axis stayed where it should be. Attached is an example of the data that I'm using.
To explain, I started off with an array of coordinates with attached mean temperature in no particular order. I then organize the temperature data in a grid with the coordinates as you would in an (x,y) graph, from bottom left to right, you go up one row, left to right, until you end up at top right. (Temperature is in Kelvin, also ignore the NaNs)
load('imagesc_confusion.mat')
meantemp
Because of the way MATLAB displays matrices, the longitude increases from top to bottom, and latitude increases from left to right. So the "origin" meantemp(1,1) would be at the top left. So if this were a map, you would be tilting your head to the right. The data can't fit in this post, but the temperature gets warmer as you get nearer the right most edge (meaning it gets warmer at the higher latitudes).
meantemp(:)
When you lay out the 2D matrix down in order, it starts going through the 'longitude' values first before going up a latitude (when looking at the data above, it goes to the next column to the right). Because of this, I would do the scatter plot like this:
scatter(xlon,ylat,50,meantemp(:),'filled'); colorbar;
...so that it would be displayed correctly. I then tried this out with imagesc:
imagesc(114:145,4:28,meantemp); axis xy; colorbar;
The warmer temps seem to be at the right edge instead of the top. I tried using some smaller data to see what would happen.
x = [100 110 120 100 110 120 100 110 120];
y = [3 3 3 4 4 4 5 5 5];
tempgrid = [0 20 70;5 30 100; 10 50 200]
scatter(x,y,50,tempgrid(:),'filled');
Okay, the 'warmer' temperature seems to be correctly rotated and is on the top right.
I tried it with imagesc:
imagesc(100:10:120,3:5,tempgrid);
axis xy;
The top row on the scatter plot seems to be on the right and sideways on the figure above. Is this just the nature of how imagesc displays data? Is there something wrong with my data? Have I missed something? Am I somehow misunderstanding how to use imagesc? How would I go about putting the "origin" on the bottom left? Switching the x and y values around sort of solves it, but it would still be sideways.
Anyway, some help would be appreciated, thanks!
imagesc(4:28,114:145,meantemp)
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 27 de Ag. de 2024
Scatter is an x-y plot where the origin is at the lower left, by convention. And imagesc plots an image (or matrix) where the origin is at the upper left, by convention. To reverse the y direction you can use either
axis xy % Put origin at the lower left.
or
axis ij % Put origin at the upper left.
until it looks like you want. Using axis ij is the default for images, imagesc, imshow, etc. and axis xy is the default for plots, plot(), scatter(), etc. You can change it with the axis command if you want.
Also, scatter takes (x,y) coordinates that do not necessarily lie on a perfect grid, while images must have pixel intensities on a perfect grid.
Plus scatter() puts down a marker (which you can optionally change the size and color of) while imagesc() puts down a dot (single pixel on your screen) where the intensity of the dot is the value of the matrix. They're different and I hope you understand why.
1 comentario
Ryan Eugenio
el 30 de Ag. de 2024
Categorías
Más información sobre Polar Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!








