Mathematica中的“自定义”CountryData条目

时间:2014-12-23 19:23:32

标签: wolfram-mathematica

我有以下数据集 - 可能没有为此任务正确格式化 - 它指的是我想在地图上指示的值,使用地图作为一种图形:

Dat2Countries = {{"Argentina", 32.63969016}, {"Australia", 
   65.6986192}, {"Bolivia", 13.19444444}, {"Brazil", 
   27.55511788}, {"Canada", 66.49547068}, {"Chile", 
   27.14539357}, {"China", 17.94765891}, {"Czech Republic", 
   58.45414706}, {"Egypt", 18.07371757}, {"El Salvador", 
   23.94366197}, {"France", 63.86621123}, {"Germany", 
   58.68321579}, {"Ghana", 21.39232133}, {"Greece", 
   57.06734961}, {"Indonesia", 17.46457699}, {"Israel", 
   90.84112638}, {"Italy", 57.48221752}, {"Japan", 
   54.9704008}, {"Jordan", 22.93290207}, {"Kenya", 
   23.60066645}, {"Lebanon", 19.74186819}, {"Malaysia", 
   16.5620438}, {"Mexico", 31.72258783}, {"Nigeria", 
   24.38177507}, {"Pakistan" , 20.4777854}, {"Poland", 
   60.54096673}, {"Russia", 28.77358356}, {"Senegal", 
   21.91780822}, {"South Africa", 19.03936205}, {"South Korea", 
   53.20728589}, {"Spain", 58.12532901}, {"Tunisia", 
   24.67799831}, {"Turkey", 45.59516911}, {"Uganda", 
   19.08127926}, {"United Kingdom", 66.5450176}, {"Venezuela", 
   14.66666667}}

我想覆盖'这个索引在地图上使用这样的东西(对不起,我知道这远非优雅):

Graphics[{If[MemberQ[Map[First, Dat2Countries, {1}], #], 
     If[Map[Last, Dat2Countries, {1}] < 20, 
      RGBColor[0.0352941, 0.254902, 0.352941], 
      If[Map[Last, Dat2Countries, {1}] < 40 && 
        Map[Last, Dat2Countries, {1}] >= 20, 
       RGBColor[0.305882, 0.498039, 0.592157], 
       If[Map[Last, Dat2Countries, {1}] < 60 && 
         Map[Last, Dat2Countries, {1}] >= 40, 
        RGBColor[0.0705882, 0.568627, 0.835294], 
        If[Map[Last, Dat2Countries, {1}] < 80 && 
          Map[Last, Dat2Countries, {1}] >= 60, 
         RGBColor[0.372549, 0.776471, 0.952941], 
         If[Map[Last, Dat2Countries, {1}] < 100 && 
           Map[Last, Dat2Countries, {1}] >= 80, 
          RGBColor[0.368627, 0.694118, 0.701961], LightBrown]]]]]], 
    CountryData[#, "SchematicPolygon"]} & /@ CountryData[]]

但是我对CountryData软件包不太熟悉 - 是否可以使用软件包来指示地图中未包含在内容中的值?

谢谢, arebearit

1 个答案:

答案 0 :(得分:1)

使用您提供的数据列表Dat2Countries,可以如下绘制地图: -

colourfunction[country_String] := Module[{cases, value},
  Catch[
   cases = Cases[Dat2Countries, {country, _}]; 
   If[cases == {}, Throw[LightGray]];
   value = cases[[1, 2]]; 
   Which[
    value < 20, RGBColor[0.0352941, 0.254902, 0.352941], 
    value < 40, RGBColor[0.305882, 0.498039, 0.592157],
    value < 60, RGBColor[0.0705882, 0.568627, 0.835294],
    value < 80, RGBColor[0.372549, 0.776471, 0.952941],
    value < 100, RGBColor[0.368627, 0.694118, 0.701961],
    True, LightBrown]]]

Graphics[{colourfunction[CountryData[#, "Name"]],
    CountryData[#, "SchematicPolygon"]} & /@ CountryData[]]

enter image description here