18
$\begingroup$

Consider the following list of countries which I would like to highlight on a world map:

MyCountries={"Germany","Hungary","Mexico","Austria","Bosnia","Turkey","SouthKorea","China"};

From the documentation center (Country Data > Applications > Application 5), I know that

Graphics[{If[CountryData[#, "AntarcticNations"], Orange, LightBrown], 
    CountryData[#, "SchematicPolygon"]} & /@ CountryData[]]

works for all antarctic nations. I replaced "AntarcticNations" by MyCountries but it does not seem to work.

$\endgroup$
0

3 Answers 3

25
$\begingroup$

In the example code, CountryData[#, "AntarcticNations"] is a built in predicate that returns True or False. You need something similar for your countries. Perhaps,

myCountries={
  "Germany","Hungary","Mexico","Austria",
  "Bosnia","Turkey","SouthKorea","China"};
Graphics[{If[MemberQ[myCountries,#],Orange,LightBrown],
  CountryData[#,"SchematicPolygon"]}& /@ CountryData[]]

enter image description here

$\endgroup$
2
  • 2
    $\begingroup$ "Bosnia" is not recognized, should be "BosniaHerzegovina". $\endgroup$
    – VLC
    May 1, 2012 at 7:55
  • 1
    $\begingroup$ I'd like to add that CountryData[#, {"Polygon", "Mollweide"}] allows to set the projection used for the map. $\endgroup$
    – Karsten W.
    Jul 22, 2012 at 12:40
11
$\begingroup$

Alternate approach:

Graphics[{
  {Orange, CountryData[#, "SchematicPolygon"] & /@ MyCountries}, 
  {LightBrown, 
      CountryData[#, "SchematicPolygon"] & /@ Complement[CountryData[], MyCountries]}
  }]

which draws all of "your countries" in one color, and then the rest of the world in another.

$\endgroup$
7
$\begingroup$

Mathematica 10 introduced new ways to highlight countries on the world map. Examples follow below. There are lots of more examples in the documentation which showcase alternative stylings.

myCountries = Map[
   Entity["Country", #] &,
   {"Germany", "Hungary", "Mexico", "Austria", "Turkey", "SouthKorea", "China"}
   ];

GeoListPlot[myCountries, ImageSize -> 800]

Map 1

GeoListPlot[myCountries, GeoBackground -> "ReliefMap", ImageSize -> 800]

Map 2

GeoRegionValuePlot[MapThread[Rule, {myCountries, RandomReal[10, Length@myCountries]}]]

Map 3

GeoGraphics[
 {EdgeForm[Black], FaceForm[Orange], Polygon /@ myCountries},
 ImageSize -> 800
 ]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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