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.


3 Answers 3


For the first try:

CountryData["Countries", "Flag"]

For the second it appears to work directly:

Mathematica graphics

  • $\begingroup$ How to control the size? For example in BarChart, if inserted directly, the flags look gigantic and overlap $\endgroup$ Commented Sep 23, 2012 at 7:16
  • $\begingroup$ @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? $\endgroup$
    – Mr.Wizard
    Commented Sep 23, 2012 at 7:18
  • $\begingroup$ 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. $\endgroup$ Commented Sep 23, 2012 at 7:25
  • $\begingroup$ @alancalvitti if you include specific examples of that in your question I shall try to address them. $\endgroup$
    – Mr.Wizard
    Commented Sep 23, 2012 at 7:26
  • $\begingroup$ @alancalvitti I'm not seeing the shifted flags, and I need to sleep. Hopefully someone has a simple solution for you. It might help to include complete code to produce your chart. $\endgroup$
    – Mr.Wizard
    Commented Sep 23, 2012 at 8:00

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


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["http://www.gosquared.com/download/pixels/flags.zip", 
countries = 
 StringDrop[#, 9] & /@ (Rest@
     StringCases[#, "flags/64/" ~~ __] & /@ 
 FileNameJoin[{$UserDocumentsDirectory, "Flags64pxPNG"}]]
MapThread[Export, {FileNameJoin[{$UserDocumentsDirectory, 
      "Flags64pxPNG", #[[1]]}] & /@ countries, flags}]

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.