Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to draw maps similar to these in a LaTeX pdf document:

enter image description here enter image description here enter image description here

I want to auto-generate them from a list of pairs (country,color) to determine the colors.

I have found the package pst-map2dII in pst-geo, however its documentation is from 2004, is in French and the tutorial examples in it no longer seem to work (or I failed to understand something important in the French part).

Is this package still working somehow, and if so how do I get a basic version to work? Either an English manual or a simple tutorial example similar to the world map above, would greatly be welcomed. If not, other packages or methods to auto-generate them outside LaTeX would be equally welcome.

share|improve this question
    
I would start from this svg map and edit either in Inkscape (that can export in PDF) or transform it to pgf/tikz using this script –  Bordaigorl Jun 4 at 15:36
    
I think you can make this sort of map using "R". visit the following link: blog.revolutionanalytics.com/2012/02/… –  Ahmad Jun 4 at 15:52
    
Not a TeX solution, but for large data-driven visualizations, you might like to try d3.js (see this for US map example) –  morbusg Jun 4 at 15:56
    
Unfortunately the documentation is really in French and my French is not good enough, although living near the border to France ;-) Perhaps our French native speakers of TeX.SX can provide a rough translation of it? –  Christian Hupfer Jun 4 at 16:02
    
Related: Large datasets on CTAN –  Werner Jun 4 at 16:34

2 Answers 2

up vote 30 down vote accepted

Here's a TikZ picture producing the USA map. I produced it as follows:

  1. I downloaded the svg map from wikipedia
  2. I used Inkscape to translate the svg to tikz code (in verbose mode)
  3. the verbose mode annotated the paths with the abbreviated names of the states so I just copied the names and put them as the style of each path (you can do it with a regex)
  4. I defined a state style and a style for each state.

You can repeat the same steps starting from https://commons.wikimedia.org/wiki/File:BlankMap-World6.svg to get a World map.

Now you can color colorado (or modify many aspects of its rendering) just by redefining the CO style. You can wrap all this in a macro if you want with an optional style parameter that you can use to overwrite the state's styles.

The code is too long for this answer I posted it as a gist at

https://gist.github.com/bordaigorl/fce575813ff943f47505

Update

The Gist above now contains two files: USAmap.tex and main.tex. The first defines a command \USA with an optional argument. The main.tex file shows how to use it:

\documentclass{standalone}
\usepackage{tikz}

\input{USAmap.tex}

\begin{document}

\begin{tikzpicture}
\USA[every state={draw=white, ultra thick, fill=black!10},CA={fill=blue},NY={fill=red}]

\draw[dashed] (TX.center) -- (CA.center) -- (AL.center);
\node at (CO) {CO};
\end{tikzpicture}

\end{document}

generates the following

preview

The main addition is the definition of styles to control the appearance of each state and the creation of (approximate) nodes for each state so you can for example attach labels to states or draw paths etc. The only drawback is that the shape of the node is the bounding box of the path of the state (for simplicity and performance reasons) so the center may lay outside it (see FL for example) but it should be enough to give you an idea of what can be done with this approach.

The styles of the states can also be set globally using tikz as in

\tikzset{set state val/.style args={#1/#2}{#1={fill=blue!#2}}}
\tikzset{set state val/.list={CA/100,FL/80,TX/55,NY/20}}

which would interpret the list {CA/100,FL/80,TX/55,NY/20} as couples state/percentage and assign to each mentioned state a shade of blue with intensity proportional to the percentage.

share|improve this answer
    
Really neat, nicely done. –  Nit Jun 4 at 22:57
4  
If there is enough interest, we could try to write a package for simple maps with a \loadmapof command to load the map's definitions on demand and a command \drawmapof{name}[style] command to produce it with custom shadings and labels... –  Bordaigorl Jun 5 at 7:41
    
Good solution!!! –  Christian Hupfer Jun 5 at 12:33

Not a full solution, but perhaps a way to go on with it.

You have to install, if not done already, all map data files into some place, like pst-geo/data of your tex distribution and add the path to the \WorldMap command.

All data files can be obtained from ctan also: http://www.ctan.org/tex-archive/graphics/pstricks/contrib/pst-geo/data

Running with xelatex works, for some reason latex and consequent conversion with dvipdf fails.

The example is taken from the book of Herbert Voss (Example 25-3-1), available from http://www.ctan.org/tex-archive/info/examples/PSTricks_en

\documentclass{article}

\usepackage{pstricks,pst-map2d}

\begin{document}
\psset{unit=3.7,linewidth=.75pt}
\begin{pspicture*}(-6.5,1)(-3,3)
  \WorldMap[rivers=true,city=true,USA=true,maillage=true,path=/usr/local/texlive/2013/texmf-dist/tex/latex/pst-geo/data]
\end{pspicture*}

\end{document}

enter image description here

share|improve this answer
    
I assume you need to go through PostScript, i.e. latex -> dvips -> ps2pdf. –  Torbjørn T. Jun 4 at 17:11
    
@TorbjørnT. Yes and no: I works only after disabling -dSAFER option of ps2pdf or dvipdf scripts. It is stated in Herbert Voss' book as well, I should have read it before ;-) –  Christian Hupfer Jun 5 at 12:25

Your Answer

 
discard

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.