2
$\begingroup$

This question already has an answer here:

enter image description here

I want to know the specific spatial pattern of certain variables. I have tried to set the listdensityplot as background and add some transparency, but it's not working very well.

How can I draw the densityplot/contourplot directly on just the coast lines to show the position of each value?

Thanks a lot for your attention.

$\endgroup$

marked as duplicate by Jason B., Community Feb 14 '17 at 23:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ How did you generate the image you show? Can you show us the data and code you have so far? $\endgroup$ – MarcoB Feb 14 '17 at 19:28
  • $\begingroup$ I was using a NetCDF plot tool named Panoply. $\endgroup$ – Baoxiang Pan Feb 14 '17 at 22:55
3
$\begingroup$

It seems that I got an ugly but working solution for this question.

Firstly, we have a 2D plot of some variables, like this:

(* Import data *)
data=Import["myfile.nc",{"Datasets","var name"}]
(* ArrayPlot or ListDensityPlot or any other 2D plot here *)
image=ArrayPlot[data,
                 PlotRange->Full,
                 ColorFunction->Hue,
                 Frame->False,
                 PlotRangePadding->None, (* Important *)
                 PlotLegends->Automatic]

enter image description here

With the image as background, we can further add coastlines of Geo objects we need, using the following code:

With[{bounds = {{-90, 90}, {0, 360}}}, 
Legended[GeoGraphics[
   {{GeoStyling[{"GeoImage", image[[1]]}, 
     GeoRange -> bounds], 
     GeoBoundsRegion[bounds]},  (* image background stretched within bound area *)
    {FaceForm[],EdgeForm[Black],Polygon[Entity["GeographicRegion","NorthAmerica"]]},
    {FaceForm[],EdgeForm[Black],Polygon[Entity["GeographicRegion","SouthAmerica"]]},
    {FaceForm[],EdgeForm[Black],Polygon[Entity["GeographicRegion","Antarctic"]]},
    {FaceForm[],EdgeForm[Black],Polygon[Entity["GeographicRegion","Asia"]]},
    {FaceForm[],EdgeForm[Black],Polygon[Entity["GeographicRegion","Australia"]]},
    {FaceForm[],EdgeForm[Black],Polygon[Entity["GeographicRegion","Africa"]]},
    {FaceForm[],EdgeForm[Black],Polygon[Entity["GeographicRegion","Europe"]]},
    {FaceForm[],EdgeForm[Black],Polygon[Entity["Country","New Zealand"]]}},
   GeoProjection -> "WinkelTripel", 
   GeoGridLines -> True, 
   ImageSize -> Medium], 
image[[2]]]]

Then we have: enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.