GNU Astronomy Utilities


Next: , Previous: , Up: 2D Histograms   [Contents][Index]


7.1.2.1 2D histogram as a table

When called with the --histogram=table option, Statistics will output a table file with three columns that have the information of every box as a column. If you asked for --numbins=N and --numbins2=M, all three columns will have \(M\times N\) rows (one row for every box/pixel of the 2D histogram). The first and second columns are the position of the box along the first and second dimensions. The third column has the number of input points that fall within that box/pixel.

For example, you can make high-quality plots within your paper (using the same LaTeX engine, thus blending very nicely with your text) using PGFPlots. Below you can see one such minimal example, using your favorite text editor, save it into a file, make the two small corrections in it, then run the commands shown at the top. This assumes that you have LaTeX installed, if not the steps to install a minimally sufficient LaTeX package on your system, see the respective section in Bootstrapping dependencies.

The two parts that need to be corrected are marked with ’%% <--’: the first one (XXXXXXXXX) should be replaced by the value to the --numbins option which is the number of bins along the first dimension. The second one (FILE.txt) should be replaced with the name of the file generated by Statistics.

%% Replace 'XXXXXXXXX' with your selected number of bins in the first
%% dimension.
%%
%% Then run these commands to build the plot in a LaTeX command.
%%    mkdir tikz
%%    pdflatex -shell-escape -halt-on-error plot.tex
\documentclass{article}

%% Load PGFPlots and set it to build the figure separately in a 'tikz'
%% directory (which has to exist before LaTeX is run). This
%% "externalization" is very useful to include the commands of multiple
%% plots in the middle of your paper/report, but also have the plots
%% separately to use in slides or other scenarios.
\usepackage{pgfplots}
\usetikzlibrary{external}
\tikzexternalize
\tikzsetexternalprefix{tikz/}

%% Start the document
\begin{document}

  You can actually write a full paper here and include many figures!
  Feel free to change this text.

  %% Define the colormap.
  \pgfplotsset{
    /pgfplots/colormap={coldredux}{
      [1cm]
      rgb255(0cm)=(255,255,255)
      rgb255(2cm)=(0,192,255)
      rgb255(4cm)=(0,0,255)
      rgb255(6cm)=(0,0,0)
    }
  }

  %% Draw the plot.
  \begin{tikzpicture}
    \small
    \begin{axis}[
      width=\linewidth,
      view={0}{90},
      colorbar horizontal,
      xlabel=X axis,
      ylabel=Y axis,
      ylabel shift=-0.1cm,
      colorbar style={at={(0,1.01)}, anchor=south west,
                      xticklabel pos=upper},
    ]
      \addplot3[
        surf,
        shader=flat corner,
        mesh/ordering=rowwise,
        mesh/cols=XXXXXXXXX,     %% <-- Number of bins in 1st column.
      ] file {FILE.txt};         %% <-- Name of aststatistics output.

  \end{axis}
\end{tikzpicture}

\end{document}

Next: 2D histogram as an image, Previous: 2D Histograms, Up: 2D Histograms   [Contents][Index]