Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What's the code to list all the world's flags?

CountryData["G8", "Flag"]

works to get those particular flags, but what about all the world's flags?

CountryData["World", "Flag"]

(* Missing["NotApplicable"] *)

This works, but seems contrived; is there a shortcut?

CountryData[#, "Flag"] & /@ CountryData[]

More importantly, is it possible to insert the flags as ChartLabels in, say, BarChart?


Following up on Mr. Wizard's solution, I find that some flags, when inserted as ChartLabels, are shifted down:

chart with flag labels

The rule used to create the flags is:

# -> Image[CountryData[#, "Flag"], ImageSize -> {15, 20}] & /@ 

which is necessary in this application since the data is associated to country code.

The code to generate the bar chart is somewhat lengthy and irrelevant, but essentially, it just calls ChartLabels to insert the images.

Any idea why Philippines and United Kingdom are translated downwards?

A related question is how to rotate the flags $90^\circ$ to render the BarChart on its side.

share|improve this question
@J.M. thanks for the edits, but I purposely wrote UnitedKingdom without a space to match CountryData though I should have code-highlighted it. – alancalvitti Sep 23 '12 at 17:28
up vote 8 down vote accepted

For the first try:

CountryData["Countries", "Flag"]

For the second it appears to work directly:

Mathematica graphics

share|improve this answer
How to control the size? For example in BarChart, if inserted directly, the flags look gigantic and overlap – alancalvitti Sep 23 '12 at 7:16
@alancalvitti either resize them with the mouse (drag the orange frame handle) or apply an Image[#, ImageSize -> n] & operation or similar. Perhaps I don't understand? – Mr.Wizard Sep 23 '12 at 7:18
Thanks that just about works. The issues are: flag aspect ratios differ, so it appears that specifying a constant ImageSize (or even both dimensions, ie, ImageSize->{x,y}) results in a ragged array ... Also, some flags, like Philippines and UnitedKingdom are somehow translated down by almost half the vertical spacing. – alancalvitti Sep 23 '12 at 7:25
@alancalvitti if you include specific examples of that in your question I shall try to address them. – Mr.Wizard Sep 23 '12 at 7:26
Added edit..... – alancalvitti Sep 23 '12 at 7:35

Re your last two questions:

I can't reproduce the flags misalignment. All flags are shown OK in my machine

enter image description here

The other question is how to rotate the BarChart and flags.

im = Image[CountryData[#, "Flag"], ImageSize -> {15, 20}] & /@ CountryData[];

BarChart[Range[5], BarOrigin -> Left, 
 ChartLabels -> (Image[#,  ImageSize -> {15, 20}] & /@ (ImageRotate /@ (im[[180 ;; 185]])))]

Mathematica graphics

share|improve this answer

GoSquared has made available a 2400 flag icon set

enter image description here

Here is how you can quickely grab the 64px versions:

flags = Import["", 
countries = 
 StringDrop[#, 9] & /@ (Rest@
     StringCases[#, "flags/64/" ~~ __] & /@ 
 FileNameJoin[{$UserDocumentsDirectory, "Flags64pxPNG"}]]
    MapThread[Export, {FileNameJoin[{$UserDocumentsDirectory, 
      "Flags64pxPNG", #[[1]]}] & /@ countries, flags}]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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