Heatmap plots with X and Y matrix instead of vectors

Hi all,

I want to know if it is possible to make heatmap plots type with X and Y matrix instead of using X and Y vectors. In fact my X and Y matrix are longitude and latitude and the Z matrix are geostationnary satellites radiances where all matrix have same size ; 3712x3712 up to 12000x12000.
for all matrix their corners are nan (space pixels). I didnot find examples on this website Home · Plots
later I will have to draw the cost lines over this image plot.
I used to use Matlab ( pcolor(X,Y,Z) ) but I have no more a licence for that. I manage to getting close with a scatter plot in scilab but it’s too slow to plot, didnt manage to do that with R and GNUPLOT and I try to avoid python.

Julia sounds great, but before starting and take time to learn deeply Julia I make this little survey if you don’t mind.

Many thanks,

E.F

1 Like

Maybe you are after something like this example where the Z, lon, lat matrices (but with no NaN in coordinates, the horror) are used to create a grid and display it (in this case)

https://www.generic-mapping-tools.org/RemoteS.jl/dev/gallery/Aqua_sst/remotes_L2_SST/

2 Likes

Can you clarify the content of X and Y?

For example, are all x and y built with matlab’s meshgrid?

If that is the case (a regular grid) using X and Y matrices is bad use of memory, but your could manage by extracting one row and one column of X and Y, no?

1 Like

And since you mention it, GMT.jl has a pcolor function. See Pcolor examples

1 Like

PyPlot.jl gives you access to all of the Python Matplotlib functionality in Julia, which includes pcolor and many other Matlab-like functions.

1 Like

Would the following example help?

using Plots
X = [1 2 3; 1 2 3; 1 2 3]
Y = [5 5 5; 6 6 6; 7 7 7]
Z = rand(Int8, 3, 3)
heatmap(X[1,1:end], Y[1:end,1], Z)

Yes, this is generically true (always hated the awful memory waste of Matlab functions) but for satellite data where X,Y are longitudes and latitudes, most of times plotting without projection is a … needless nearly error thing to do.

1 Like

Hi, yes and no.
Yes this is for MSG or himawari or GOES intead MODIS. But I don’t want it interpolated on a 1km space grid in a first step.
I still keep the link it still an example to work on.

thanks

If you read the functions docs you’ll see that the grid step is a variable. Just set to 1 km for those MODIS L2 scenes.

Edit; in fact, if I remember, it even tries to find a reasonable grid spacing based on coordinates pts distances.

Hi, no it would be more like

X=[0.9 2 2.85 ; 1 2 3 ; 1.1 2 3.2] ;
Y=[4.9 5 5.05 ; 6 6 6 ; 6.85 7 7.1];

E.F

How does Matlab pcolor display the data on such an irregular grid?

NB:
the Plots.jl scatter plot below is just to show the irregularity

This is what PyPlot.pcolor (i.e. the matplotlib pcolor) does for pcolor(X, Y, rand(size(X)...)):


i.e. it just plots irregular quadrilaterals. pcolormesh produces virtually the same plot, but is reportedly much faster for large meshes.

(More generally, even for an arbitrary unstructured “cloud” of points, you can do a heatmap plot via Delaunay triangulation using tripcolor, e.g. plt.tripcolor(rand(1000), rand(1000), rand(1000)).)

2 Likes

For fun (does what is mentioned above) and after warm up

using GMT

@time contourf(rand(1000,3), show=true)
  1.708162 seconds (1.00 k allocations: 89.234 KiB)

Ok, thanks for this.
Using Plots.jl’s shapes, the same type of heatmap can be produced:

Why are there 3x3 pixels and not only 2x2?
This is what I get with GMT

X=[0.9 2 2.85 ; 1 2 3 ; 1.1 2 3.2] ;
Y=[4.9 5 5.05 ; 6 6 6 ; 6.85 7 7.1];
pcolor(X, Y, rand(size(X)...), show=1)

I think the difference lies on how the X,Y coordinates are interpreted and this is another case of the pixel vs grid registration or the pixel-is-area vs pixel-is-point as it is known in the GDAL world. But while both of the above cases make sense in rectangular grids the same is less evident with these losange pixels. How to extrapolate to the corner coordinates?

We assume the data points are in the center and construct the quadrilaterals around them.

Yes, but it requires extrapolation from irregular cells to compute the border coordinates.
BTW, this is what Matlab produces.

>> X=[0.9 2 2.85 ; 1 2 3 ; 1.1 2 3.2];
>> Y=[4.9 5 5.05 ; 6 6 6 ; 6.85 7 7.1];
>> pcolor(X, Y, rand(3))

PyPlot.pcolor does 2x2 if you give it 3x3 coordinates and a 2x2 array of values:

pcolor(X, Y, rand((size(X) .- 1)...))

gives
image

This is explained in the matplotlib.pyplot.pcolor documentation:

Note that Matlab’s pcolor corresponds to shading="flat", and is silently dropping some of your data: the colors are given by a 2x2 submatrix of your 3x3 value array! (The Matlab pcolor documentation gives a 3x3 example and says explicitly that Four of the nine vertices determine the colors of the faces.)

Good to know, thanks.

I must thank all of you, this was really helping. In some ways you’ve bring better solutions than I was using in MATLAB.
Hence, I will start using Julia the community is great here.
Last request, what do you advise for developping environnement in order to fully enjoy Julia for data analysis and method developement ? Does Visual Studio code is the only one, not very satisfy about the first try I have done ? or may be notepad++ and Julia console is enough ?
E.F