3

I am preparing some presentations using Beamer and XeLaTeX. There are a few images which I would like to draw using TikZ, as follows:

enter image description here

My sample presentation goes as follows:

\documentclass[aspectratio=149,presentation,10pt]{beamer}
\setbeamertemplate{navigation symbols}{}
\usefonttheme{professionalfonts}
\usepackage{tikz}

\definecolor{lightgray}{RGB}{204,204,204}
\definecolor{tomato}{RGB}{231,76,60}
\definecolor{snow}{RGB}{236,240,241}

\setbeamercolor{background canvas}{bg=snow}

\begin{document}
\begin{frame}[fragile]
    \begin{tikzpicture}[R/.style={fill=lightgray,color=lightgray},L/.style={-,line width=2pt,color=tomato}]
        \node (f) at (-0.5,2) [rotate=90] {Frequency};
        \node (h) at (5,6) {\bf{Histogram of rdist}};
        \node (r) at (5.5,-0.5) {rdist};
        \draw [R] (0,3.75) rectangle (1,0);
        \draw [L] (3,0) -- (3,5);
        \draw [R] (3.05,4.9) rectangle (4.05,0);
        \draw [R] (4.1,4.9) rectangle (5.1,0);
        \draw [R] (5.15,1.75) rectangle (6.15,0);
        \draw [R] (8.15,1.75) rectangle (9.15,0);
    \end{tikzpicture}
\end{frame}

\end{document}

And which produces below output:

enter image description here

Now I do not know how to draw the axes.

I am new to TikZ...to get accustomed with it, I already have started to read the manual (pgfmanual.pdf) from start...it is big and I am learning many new ideas. Based on that I have also prepared some diagrams. But, for the graph plot I am nearly clueless.

It would be highly appreciable if someone guides me in a step by step mode on the topic. As I already mentioned I am learning TikZ.

  • 1
    can you please shorten your example to the most related part to your question? A minimum working example will be sufficient to answer your question. – Sina Ahmadi Nov 16 '18 at 11:37
  • Well, this code isn't even a MWE! – user156344 Nov 16 '18 at 11:58
  • Your MWE does not compile, you cannot use font commands in beamer colour definitions. You also don't need the graphicx package with beamer, nor etoolbox if your beamer version if reasonable up-to-date – user36296 Nov 16 '18 at 12:01
  • That said, you could have a look at the pgfplots package to plot such bar plots – user36296 Nov 16 '18 at 12:02
  • 2
    A nice example how to draw a bar plot in pgfplots: pgfplots.net/tikz/examples/bar-plot – user36296 Nov 16 '18 at 12:06
2

As far as I can see only the axes are missing. While it is arguably more convenient to draw them with pgfplots, it is easy enough to implement them using TikZ "only". (Some seemingly unnecessary stretches are in because otherwise the line joins at the ends of the axes would not look good.)

\documentclass[aspectratio=149,presentation,10pt]{beamer}
\setbeamertemplate{navigation symbols}{}
\usefonttheme{professionalfonts}
\usepackage{tikz}

\definecolor{lightgray}{RGB}{204,204,204}
\definecolor{tomato}{RGB}{231,76,60}
\definecolor{snow}{RGB}{236,240,241}

\setbeamercolor{background canvas}{bg=snow}

\begin{document}
\begin{frame}[fragile]
    \begin{tikzpicture}[R/.style={fill=lightgray,color=lightgray},L/.style={-,line width=2pt,color=tomato}]
        \node (f) at (-1.2,2) [rotate=90] {Frequency};
        \node[font=\bfseries] (h) at (5,6) {Histogram of rdist};
        \node (r) at (5.5,-1.5) {rdist};
        \draw [R] (0,3.75) rectangle (1,0);
        \draw [L] (3,0) -- (3,5);
        \draw [R] (3.05,4.9) rectangle (4.05,0);
        \draw [R] (4.1,4.9) rectangle (5.1,0);
        \draw [R] (5.15,1.75) rectangle (6.15,0);
        \draw [R] (8.15,1.75) rectangle (9.15,0);
        % axes
        \pgfmathsetmacro{\vfactor}{4.9/6}
        \draw[thick] (-0.5,0) -| (-0.2,6*\vfactor)--(-0.5,6*\vfactor);
        \foreach \X in {0,...,6}
        {\draw[thick] (-0.2,\X*\vfactor) -- (-0.5,\X*\vfactor) node[left] {\X};}
        \pgfmathsetmacro{\hfactor}{9.15/4}
        \draw[thick] (0,-0.5)|-(4*\hfactor,-0.2)--(4*\hfactor,-0.5);
        \foreach \X in {0,...,4}
        {\draw[thick] (\X*\hfactor,-0.2) -- (\X*\hfactor,-0.5) node[below] {\X};}
    \end{tikzpicture}
\end{frame}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.