Some of the functionality of the World Plotting Package is now available in CountryData.

World Plotting Package

WorldPlot[countrylist]generate a map of the countries named in countrylist
WorldPlot[{countrylist,RandomColors}]color the countries with randomly chosen colors
WorldPlot[{countrylist,RandomGrays}]use randomly chosen gray levels

Displaying a map.

To make a map of an entire continent, you can give the name of the continent in place of the list of country names. Thus, for example, WorldPlot[Oceania] is equivalent to WorldPlot[{"Indonesia", "Papua New Guinea", "Fiji", "Australia", . The names of the countries that can be mapped are listed at the end of this tutorial. Note that the names of countries are strings. This means they must be surrounded by quotes when you use them in a list of countries. However, the continent names represent lists and therefore are not strings but symbols. They should not be put in quotes.

This loads the package.
In[1]:=
Click for copyable input
This gives a map of Africa with all countries drawn as white with black outlines.
In[2]:=
Click for copyable input
Out[2]=
Here is a map of the world with each country colored with a randomly chosen gray level.
In[3]:=
Click for copyable input
Out[3]=
WorldPlot[{countrylist,colorfunc}]color the countries as specified by colorfunc
WorldPlot[{countrylist,colorlist}]color the countries using the list of color directives

Specifying the color gray level of maps.

When you make a map, you can specify the color of each country in several ways. The first is to give an explicit list of graphics directives such as GrayLevel, RGBColor, or Hue. The ^(th) element in this list specifies the color of the map of the ^(th) element in your list of country names. You can also specify the colors by defining your own color function. This color function must take names of countries as arguments and return a color directive. Perhaps the simplest way to create maps with colors is to specify the color function as RandomColors or RandomGrays. These two functions use random numbers to assign a color or gray level to each country on your list.

Here is a simple color function.
In[4]:=
Click for copyable input
The color function causes Canada to be drawn black, Mexico dark gray, and other countries a lighter gray.
In[5]:=
Click for copyable input
Out[5]=

A map is simply the representation of a portion of the Earth's surface on a flat page. Since the Earth is nearly spherical, this representation requires that we adopt some scheme for taking the surface of a spherical object and representing it as a flat two-dimensional image. These schemes are called projections. By their very nature, all projections give rise to certain distortions. Various projections have been developed that preserve certain properties of the surface of the Earth while distorting others. An equal-area projection has the property that two regions that have the same area on the map have the same area on the globe. A projection is called conformal if it preserves angular relationships and therefore directions. An azimuthal projection preserves true directions from a central point.

The projection for a map is specified by the option WorldProjection. You can define your own projection by giving a pure function of two arguments. For example, the default setting for WorldProjection is Equirectangular, which as a pure function is given as WorldProjection->({#2, #1}&). The parentheses around the pure function ensure that Mathematica recognizes it as a single expression. If you define your own projections, it is important to remember that the coordinates in the database are given in minutes. This means that you must convert them to radians before using a built-in Mathematica trigonometric function. Also, the coordinates of the boundaries of countries are given as pairs with the latitude first.

Projections.

You can also give the name of a projection as a value for the option WorldProjection. Many of the standard projections are included in this package. These are described below.

The simplest projection is the equirectangular projection Equirectangular. This projection simply takes the latitude as the coordinate and the longitude as the coordinate. This projection does not preserve angles or area. Equirectangular is the default setting for WorldProjection.

The Lambert cylindrical projection LambertCylindrical is just an equirectangular projection with the spacing between parallels adjusted so the projection is equal area. This projection is sometimes called the cylindrical equal-area projection.

In the Lambert azimuthal projection LambertAzimuthal the globe is projected onto a plane that is tangential to the globe at one point, and then the spacing of parallel circles around the projection point is adjusted to make it equal area. This projection gives true directions from the center point and is sometimes called the azimuthal equal-area projection.

Another azimuthal projection is the orthographic projection. Orthographic specifies a projection of the sphere with the projection point at infinity. The result looks like a view of the planet as seen from very far away. The projection preserves neither area nor angles.

The sinusoidal projection Sinusoidal belongs to the class of pseudo-cylindrical projections, that is, parallels are straight lines, meridians are curved, and their spacing is adjusted to make it equal area.

The most popular equal-area projection for world maps is the Mollweide projection Mollweide. The adjustment used to achieve equal areas is fairly sophisticated and involves the solution of a trigonometric equation. This projection is sometimes also called elliptical or homolographic.

The Mercator projection Mercator is a cylindrical projection that preserves angles but is not equal area. It is produced by adjusting a cylindrical projection that is projected from the center of the Earth. This projection is particularly useful for navigation, as a straight line on the map corresponds to a fixed directional bearing.

A conic projection is produced by projecting the surface of the Earth onto a cone that is tangential to the Earth along a circle. The Albers conic projection Albers is a conic projection that is adjusted to make it equal area. Unlike the other projections, Albers requires you to specify additional information. This takes the form of Albers[par1, par2]. The two parallels you specify are the parallels along which the scale is correct. A good projection for the United States is Albers[20, 60]. The Albers conic projection is sometimes called the Albers equal-area projection.

The sinusoidal projection gives little distortion near the equator and the prime meridian, and is therefore very good for showing Africa.
In[6]:=
Click for copyable input
Out[6]=
option name
default value
WorldBordersAutomaticstyle to display borders of countries; with None, no borders are drawn
WorldCountriesWorldname of the list of allowable country names
WorldDatabaseWorldDataname of the database containing polygon data for countries
WorldToGraphicsFalsewhether to return a standard Graphics object

Some options for WorldPlot.

option name
default value
WorldBackgroundNonestyle to use for the background polygon
WorldClippingFullspecify what happens to lines or polygons that are partially outside the plot range
WorldFrameAutomaticstyle to use for the frame around the map; with None, no boundary is drawn
WorldFrameParts{1,1,1,1}what parts of the frame to draw
WorldGridAutomaticlocations of parallels and meridians to be drawn
WorldGridBehindTruewhether the grid is drawn behind (True) or in front (False) of the countries
WorldGridStyleThickness[.001]style for the grid
WorldPoints100number of divisions used in plotting grid lines and clipping polygons
WorldProjectionEquirectangularfunction to use for the projection
WorldRangeAutomaticportion of the surface of the Earth to be drawn; specifications must be of form ,
WorldRotatedRangeFalsecoordinate system to which the range specification is applied; with True, it is applied to the system resulting from WorldRotation
WorldRotation{0,0,0}rotation to be applied to coordinates before projection

More options for WorldPlot. These options can also be used in WorldGraphics.

To specify how the borders of countries are to be drawn, you set the WorldBorders option. The settings for this option can be None, Automatic, or a style list. With the setting Automatic the borders are drawn with the style {GrayLevel[0], Thickness[.001]} unless a style list for the shading of the countries is given. If this is the case, no borders are drawn.

The style of the frame around the map is controlled by the WorldFrame option. To determine which portion of the frame is to be drawn, specify WorldFrameParts->{s1, s2, s3, s4}. Each is either 0 or 1 and specifies whether a portion of the frame is drawn (1) or not (0). The sides are ordered clockwise, with the eastern side given first.

WorldGrid controls the drawing of parallels and meridians. A setting for this option of the form WorldGrid->{deg1, deg2} specifies the spacing of the latitude and longitude lines that are drawn beginning with the equator or a prime meridian. A setting of WorldGrid->deg is the same as WorldGrid->{deg, deg}. You can explicitly specify which latitude and longitude lines you want drawn with WorldGrid->{{lat1, lat2, ...}, {lon1, lon2, ...}}. The default setting Automatic is equivalent to WorldGrid->30. Note that all settings are given in degrees.

One of the most time-intensive parts of the plot is clipping polygons or lines that are partially outside the plot range. The way this clipping is done is determined by the option WorldClipping. The default setting Full causes these objects to be properly clipped at the edge of the plot range. To save rendering time you can reset this option at Simple, which causes objects outside the plot range not to be rendered, or None, which causes the entire object to be rendered.

In this map of Africa the background is light gray, there are no grid lines, and the frame around the map is somewhat thicker than usual.
In[7]:=
Click for copyable input
Out[7]=

As noted previously, a projection is a scheme for transforming latitudes and longitudes on the Earth into and coordinates on a flat page. Each projection involves certain fixed geometric choices. For example, the Lambert azimuthal projection projects the surface of the Earth onto a plane that is tangent at one point. When you specify LambertAzimuthal as the projection, this point is fixed at zero degrees latitude and longitude. You can change the choice of this point by setting the WorldRotation option.

A value for WorldRotation must be a list of three numbers with the first two between 0 and 180 and the last between 180 and 180. To understand the effect of these numbers, you can imagine the globe in a standard coordinate system with the positive axis coming out of the North Pole and the axis through the equator at the Prime Meridian. The three numbers give the amount of rotation (in degrees) of three sequential rotations. The first is about the axis, the second is about the axis, and the third is about the North Pole in the position where it is after the first two rotations.

This setting for WorldRotation causes the Earth to be rotated by 90 degrees before the projection is applied. The result is a view of the Northern Hemisphere centered at the North Pole.
In[8]:=
Click for copyable input
Out[8]=

WorldPlot works by creating a Mathematica graphics object that represents the map. Each country on the map is given as a Polygon primitive. To make a map from a list of countries, Mathematica must know the vertices of these polygons for each country in your list. This data is contained in the package , which is automatically loaded when is loaded. As noted above, the vertex data is given as ordered pairs of latitude and longitude expressed in minutes. By convention, latitudes north of the equator are positive while those to the south are negative, and longitudes east of Greenwich are positive and those to the west are negative.

You can specify your own database of geographic coordinates by setting the option WorldDatabase. The setting for this option is the name of the function that is applied to a country name to yield its polygonal vertices. The names of the countries that appear in your database are specified using the option WorldCountries. The setting for this option is the name of the Mathematica list that contains the allowable country names. The default value is , which is a list given in the package . This package is also automatically loaded when you load .

WorldGraphics[primitives,options]a graphics object representing a planetary map
Show[wg,options]display a WorldGraphics object using the options specified
Graphics[WorldGraphics[primitives,options]]convert a WorldGraphics object to a Graphics object

Creating and displaying WorldGraphics objects.

Built-in Mathematica functions like Plot and ListPlot work by building up a Graphics object, and then displaying it. The resulting Graphics object can be manipulated and redisplayed using various options. WorldPlot works in a very similar way, creating a WorldGraphics object and then displaying it. A WorldGraphics object is essentially a Graphics object that has been adapted to work with geographic data. All coordinates given in the primitives Polygon, Line, Point, and Text are given as with the latitude and longitude given in minutes of an arc. You can convert data given in degrees and minutes into minutes using the function ToMinutes. Thus Point[ToMinutes[{{41, 49}, -{87, 37}}]] represents a point displayed at the location of Chicago, Illinois, which is at latitude 41 degrees, 49 seconds North and longitude 87 degrees, 37 minutes West. Before a WorldGraphics object is displayed, it is internally converted to a standard Graphics object using the projection specified by the value of WorldProjection.

Here is the list of the vertices of the polygon that give the map of Ireland.
In[9]:=
Click for copyable input
Out[9]=
This is a list of the latitude and longitude in minutes of two cities in Africa.
In[10]:=
Click for copyable input
Out[10]=
You can combine maps with WorldGraphics objects using Show. The map of Africa given by was defined above.
In[11]:=
Click for copyable input
Out[11]=
ToMinutes[deg]convert deg into minutes
ToMinutes[{deg,min}]convert when the argument is in degrees and minutes
ToMinutes[{deg,min,sec}]convert when the argument is in degrees, minutes, and seconds

Converting into minutes.

Giving the name of the continent is the same as giving the list of names of countries in that continent. gives the list of all the countries in the world. As previously noted, the names of countries are strings and need to be included in quotes. The names of continents are symbols and do not require quotes. The following countries can be given:

BelizeBermuda
CanadaCosta Rica
CubaDominican Republic
El SalvadorGreenland
GuatemalaHaiti
HondurasJamaica
MexicoNicaragua
PanamaPuerto Rico
USA

Countries in the list .

AlbaniaAndorra
AustriaBelarus
BelgiumBosnia and Herzegovina
BulgariaCroatia
CyprusCzech Republic
DenmarkEstonia
FinlandFrance
GermanyGibraltar
GreeceHungary
IcelandIreland
ItalyLatvia
LiechtensteinLithuania
LuxembourgMacedonia
MoldovaMonaco
NetherlandsNorway
PolandPortugal
RomaniaRussia
San MarinoSerbia and Montenegro
SlovakiaSlovenia
SpainSweden
SwitzerlandTurkey
UkraineUnited Kingdom

Countries in the list .

ArgentinaBolivia
BrazilChile
ColombiaEcuador
French GuianaGuyana
ParaguayPeru
SurinameUruguay
Venezuela

Countries in the list .

AustraliaFiji
IndonesiaNew Zealand
Papua New Guinea

Countries in the list .

AfghanistanArmenia
AzerbaijanBahrain
BangladeshBhutan
BruneiBurma
CambodiaChina
GeorgiaIndia
IndonesiaIran
IraqIsrael
JapanJordan
KazakhstanKuwait
KyrgyzstanLaos
LebanonMalaysia
MongoliaNepal
North KoreaOman
PakistanPhilippines
QatarRussia
Saudi ArabiaSingapore
South KoreaSri Lanka
SyriaTaiwan
TajikistanThailand
TurkeyTurkmenistan
UzbekistanVietnam

Countries in the list .

BahrainEgypt
IranIraq
IsraelJordan
KuwaitLebanon
OmanQatar
Saudi ArabiaSyria
TurkeyUAE
Yemen

Countries in the list .

AlgeriaAngola
BeninBotswana
BurkinaBurundi
CameroonCAR
ChadCongo
Cote d'IvoireDjibouti
EgyptEquatorial Guinea
EritreaEthiopia
GabonGhana
GuineaGuinea-Bissau
KenyaLesotho
LiberiaLibya
MadagascarMalawi
MaliMauritania
MoroccoMozambique
NamibiaNiger
NigeriaRwanda
SenegalSierra Leone
SomaliaSouth Africa
SudanSwaziland
TanzaniaThe Gambia
TogoTunisia
UgandaWestern Sahara
ZaireZambia
Zimbabwe

Countries in the list .

New to Mathematica? Find your learning path »
Have a question? Ask support »