Visualizador de Tikz

Código fuente

zipfColombia.es.tex

% Enrique Acosta
% 2025
\documentclass[border=2pt, tikz, convert={command=\unexpanded{magick -density 600 \infile\space "\jobname.png"}}]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}

\pagecolor{white} % Set the background color to white

\pgfplotstableread{
rank  pop       city
1     7937898   Bogotá
2     2634570   Medellín
3     2285099   Cali
4     1342818   Barranquilla
5     1065881   Cartagena
6     828947    Soacha
7     815891    Cúcuta
8     686339    Soledad
9     623881    Bucaramanga
10    593273    Villavicencio
11    575225    Valledupar
12    570329    Bello
13    566650    {Santa Marta}
14    546003    Ibagué
15    531424    Montería
16    482824    Pereira
17    459262    Manizales
18    415937    Pasto
19    388229    Neiva
20    359888    Palmira
}\citydata

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    width=12cm,
    height=8cm,
    xlabel={Puesto en orden de población},
    ylabel={Población},
    title={Población de cuidades de Colombia en 2025},
    xmin=0.5, xmax=20.5,
    ymin=0, ymax=8.5e6,
    xtick={1,...,20},
    grid=both,
    tick label style={font=\small},
    ymajorgrids=true,
    xmajorgrids=true,
    scaled ticks=false,
    y tick label style={
        /pgf/number format/fixed,
        /pgf/number format/precision=0
    },
]

% Fit function 
\addplot [
    domain=1:20,
    samples=100,
    very thick,
    dashed,
    cyan,
] {5544989 * x^(-0.92)};

% Fit equation label
\node[rectangle, draw, fill=white, text=cyan!70!black, anchor=south west] at (axis cs: 6.5, 4500000) {$P(r)=\displaystyle\frac{5544989}{r^{0.92}}$};

% Data and labels
\addplot[
    only marks,
    mark=*,
    black,
    mark size=2.5pt,
    nodes near coords,
    point meta=explicit symbolic, % for city names as the nodes
    every node near coord/.append style={
      font=\scriptsize, anchor=south west, yshift=3pt, xshift=2pt, rotate=30, inner sep=1pt, fill=white
    }
] table [x=rank, y=pop, meta=city] {\citydata};

\end{axis}

% link at the bottom
\node[anchor=south east, font=\tiny, text=gray!80!black, inner sep=2pt] at (current bounding box.south east) {enriqueacosta.github.io 2025};


\end{tikzpicture}
\end{document}

Versión vectorial en formato pdf

Download here

Entradas en las que sale esta imagen

Suscríbase

¿Quiere recibir un email cuando haya una nueva entrada de blog? Suscríbase acá.