# How to plot contour in an arbitrary shape of area?

**URL:** <https://discourse.julialang.org/t/how-to-plot-contour-in-an-arbitrary-shape-of-area/67902>\
**Category:** Visualization\
**Tags:** question, gmt\
**Created:** [September 9, 2021, 1:06am UTC](https://discourse.julialang.org/t/how-to-plot-contour-in-an-arbitrary-shape-of-area/67902 "2021-09-09T01:06:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thudjx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thudjx/32/15231_2.png) [@thudjx](https://discourse.julialang.org/u/thudjx)\
**Post date:** [September 9, 2021, 1:06am UTC](https://discourse.julialang.org/t/how-to-plot-contour-in-an-arbitrary-shape-of-area/67902/1 "2021-09-09T01:06:08Z")

</div>

How can I use `contour` to plot a contour in an arbitrary shape, say, a parallelogram?  
A simple example is:  
 ![TMDC_cv_berryCurvature](https://global.discourse-cdn.com/julialang/original/3X/d/b/db7996ba82445fd15a872379d2416137f563bce3.png)  
I tried `contour!(xgrid, ygrid, zs)` but it seems `contour` can only take vector-like objects, such as `range` rather than `xgrid`.  
By the way, I need to scatter the sampling points uniformly in the parallelogram.  
I know it’s not commended to use meshgrid in julia, [Dont use Meshgrid function in julia](https://groups.google.com/g/julia-users/c/83Pfg9HGhGQ/m/9G_0wi-GBQAJ). But how to plot in an arbitrary shape without meshgrid?

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [September 9, 2021, 1:39am UTC](https://discourse.julialang.org/t/how-to-plot-contour-in-an-arbitrary-shape-of-area/67902/2 "2021-09-09T01:39:09Z")

</div>

Interpolate your scatter points into a grid or compute one and then do like [this example](https://discourse.julialang.org/t/contour-plot-for-non-rectangular-domain/57381/5) except that you’ll have to provide the points of the clipping polygon.

---

<div class="post-metadata">

**Author:** ![thudjx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thudjx/32/15231_2.png) [@thudjx](https://discourse.julialang.org/u/thudjx)\
**Post date:** [September 9, 2021, 3:09am UTC](https://discourse.julialang.org/t/how-to-plot-contour-in-an-arbitrary-shape-of-area/67902/3 "2021-09-09T03:09:53Z")

</div>

Thanks for reply. I have read the some of the documentation of GMT.jl and I think the most proper way to plot in my case in to use grids as input. From [use file instead of grid](https://www.generic-mapping-tools.org/GMT.jl/dev/gallery/contourf/contourf/#What-if-one-has-an-*x,y,z*-file-instead-of-a-grid?), I know GMT.jl support inputting grid, but I can’t find the way to do so. Would you please help me with this?  
(I can reshape my data into file but that is kind of time consuming.)

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [September 9, 2021, 11:44am UTC](https://discourse.julialang.org/t/how-to-plot-contour-in-an-arbitrary-shape-of-area/67902/4 "2021-09-09T11:44:06Z")

</div>

A grid in GMT.jl is stored in a [GMTgrid](https://www.generic-mapping-tools.org/GMT.jl/dev/types/#Grid-type) type and there is the convenience function [mat2grid](https://www.generic-mapping-tools.org/GMT.jl/dev/#GMT.mat2grid) to help creating a GMTgrid from a plain matrix. One can use (I think) a plain matrix in `contourf` but the coordinates will the row and column numbers.

Other from that, if the first argument of `contourf` (or any other module that uses grids) is a string then that is interpreted as a file name and the grid is read from disk or, for some formats, the web. A wide range of grid formats is available and automatically recognized.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [September 9, 2021, 1:50pm UTC](https://discourse.julialang.org/t/how-to-plot-contour-in-an-arbitrary-shape-of-area/67902/5 "2021-09-09T13:50:02Z")

</div>

Linking also [this post](https://discourse.julialang.org/t/contour-plot-for-non-rectangular-domain/57381).
