# How to plot 2D array in a rotated coordinate system?

**URL:** <https://forum.generic-mapping-tools.org/t/how-to-plot-2d-array-in-a-rotated-coordinate-system/1339>\
**Category:** Q&A\
**Tags:** gmt\
**Created:** [February 13, 2021, 12:16am UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-2d-array-in-a-rotated-coordinate-system/1339 "2021-02-13T00:16:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hzfmer](https://avatars.discourse-cdn.com/v4/letter/h/4bbf92/32.png) [@hzfmer](https://forum.generic-mapping-tools.org/u/hzfmer)\
**Post date:** [February 13, 2021, 12:16am UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-2d-array-in-a-rotated-coordinate-system/1339/1 "2021-02-13T00:16:54Z")

</div>

Hi,

I would like to plot a 2D array on top of the topography within the black box shown in the figure below.

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/6a093cf1ce53dea61cc5c6e5ca488271d3c011da.jpeg)

I have a few questions on making the plot:  
(1) The region is rotated, and thus using “JC” projection doesn’t work for me (at least I don’t know how to make it..)  
(2) Is there a way to map the 2D array to geographical coordinate GMT file (e.g. NetCDF)?  
(3) If not, I can use float-number Cartesian coordinate system (`Jx`?), but I always got errors like:

> grdimage [ERROR]: Internal Failure = GMT\_MAP\_EXCEEDS\_360  
> grdimage (GMT\_grdimage): Map region exceeds 360 degrees

```auto
range=-119.4/-116.7/33/35.2

gmt begin topography_large_gmt2 png
gmt basemap -JM15c -R${range} -Baf -BSWen
gmt makecpt -Czambezi -T0/2400
gmt grdsample @earth_relief_15s -R${range} -Ginterp.grd -I32e/32e
gmt grdimage interp.grd -I
gmt colorbar -DjMR+o-1c/0+m -I0.3 -Bxa300+lElevation -By+lm
gmt coast -JM15c -Sskyblue # -W1/1p
gmt plot -Sa0.6c -Gblack -l"2014 La Habra M5.1"<< EOF
-117.932587 33.918633
EOF

gmt plot -W1.5p,black -L << EOF
-119.3309098848646 34.149236516966624
-117.7401908038864 33.06957796456456
-116.77297541421393 34.04292416669585
-118.3704310693418 35.13480950243679
EOF

gmt end

```

A baseline script is shown above (sorry the 2D array is too large to include; I guess `gmtmath` can make a random 2d array, but I don’t know how to do it), and I appreciate any help from you!

P.S. GMT works nicely to plotting things from my very limited experience, but to be honest I always feel it hard to solve problems on our own. The modern mode helps a lot, and I hope more people can upload their scripts and output plots for future users to learn!

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 13, 2021, 12:44pm UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-2d-array-in-a-rotated-coordinate-system/1339/2 "2021-02-13T12:44:23Z")

</div>

> [@hzfmer](#):
>
> but to be honest I always feel it hard to solve problems on our own.

You are trying to do non-trivial things so you’d expect a bit of that in any software.

> [@hzfmer](#):
>
> I have a few questions on making the plot:  
> (1) The region is rotated, and thus using “JC” projection doesn’t work for me (at least I don’t know how to make it…)  
> (2) Is there a way to map the 2D array to geographical coordinate GMT file (e.g. NetCDF)?  
> (3) If not, I can use float-number Cartesian coordinate system (`Jx`?), but I always got errors like:

1- GMT does not have the concept of rotated grid so even if you have a grid in oblique Mercator GMT would always plot a rectangular area. But what you can do is to plot that grid and use the rotated rectangle to set a clip path (see the `clip` module) to make the _corners_ transparent. However, if the rotated grid has different coordinates than the base grid you’ll have to figure out the paper coordinates of the insertion point such that the rotated grid plots in the right place.

2- Yes. See `xyz2grd`.

3- If you have a grid in Cartesians you have to plot it with **-JX|x**. The error you got was because you were trying to plot such a grid using a map projection and hence GMT _thought_ your grid was in geographics.
