0

I have slight problem with pgfplots barplot. What I am trying to build is relatively simple, and for the life of me I can't see where my error is. The funny thing is that when I try to compile with the pgfplot code, I get all sorts of citation errors..... commenting pgfplots code out and compilign again, everything works and no errors.

The pgfplots code:

\begin{figure}[ht]
      \centering
      \begin{tikzpicture}
      \begin{axis}[
      ybar,
      width=.8\linewidth,
      height=7cm,
      title=Flutningstakmarkanir yfir spátímabilið,
      xlabel={Sviðsmyndir},
      ylabel={Milljón \$ },
      symbolic x coords={Mynd 1,Mynd 2, Mynd 3},
      xtick=data,
      legend columns=-1, % to set one line legend
      legend style={at={(0.5,-0.3)},anchor=center},
      ymajorgrids
      ]
      \addplot+[ybar] coordinates { (mynd1,98) (mynd2,59) (mynd3,43)};
      \addplot+[ybar] coordinates { (mynd1,95) (mynd2,57) (mynd3,42)};
      \end{axis}
      \end{tikzpicture}
    \end{figure}

All of the packages I am using:

\documentclass[a4paper,12pt,twoside,BCOR=10mm]{scrbook}

% Packages \usepackage[utf8]{inputenc} \usepackage[icelandic]{babel} \usepackage{t1enc} \usepackage{graphicx,booktabs} \usepackage[intoc]{nomencl} \usepackage{enumerate,color} \usepackage{url} \usepackage[pdfborder={0 0 0}]{hyperref} \BeforeTOCHead[toc]{\cleardoublepage\pdfbookmark{\contentsname}{toc}} % Add Table of Contents to PDF "bookmark" table of contents \usepackage{appendix} \usepackage{eso-pic} \usepackage{amsmath} \usepackage{amssymb} \usepackage{longtable} \usepackage[sf,normalsize]{subfigure} \usepackage[format=plain,labelformat=simple,labelsep=colon]{caption} \usepackage{placeins} \usepackage{tabularx} \usepackage{multirow} \usepackage{subfigure} \usepackage{adjustbox} % Packages used for title page layout \usepackage[dvipsnames]{xcolor} \usepackage{tikz} \usetikzlibrary{positioning} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepgfplotslibrary{external}

% Blue color according to HÍ corporate design \convertcolorspec{RGB}{16,9,159}{rgb}\tmphiblue \definecolor{hiblue}{rgb}\tmphiblue

\setlength{\parskip}{\baselineskip} \setlength{\parindent}{0cm} \raggedbottom

\setkomafont{captionlabel}{\itshape} \setkomafont{caption}{\itshape} \setkomafont{section}{\FloatBarrier\Large} \setcapwidth{\textwidth} %\setcapwidth[l]{\textwidth} % The original template had the [l] which leads to a warning that it gets ignored, so to reduce warnings, removed it. \setcapindent{1em}

\usepackage{lmodern} % Use Latin Modern (instead of the default Computer Modern that is rendered using a bitmap font). \usepackage{fixcmex} % To fix that Latin Modern large symbol math fonts has by default only one size: https://tex.stackexchange.com/a/621536 % Times new roman font instead of the standard LaTeX fonts: has not been test -- try this on your own risk \usepackage[T1]{fontenc} \usepackage{mathptmx}

%%%%%%%%%%%%%%%%% Configurations (Useful defaults, but OK to change %%%%%%%%%%%%%%%%%%% \graphicspath{{figs/}} % Figures in directory figs

% Bibliography

% \usepackage[authoryear]{natbib} % Uncoment if you want to used NatBib instead of BibLaTeX (and comment the bitlatex line below)

\usepackage[backend=biber, style=authoryear]{biblatex} % BibLaTeX used for references. \usepackage{csquotes} % BibLaTex wants to have context sensitive quotes \addbibresource{references.bib} % Name of *.bib file containing references

I do have pgfplots line plot set up in a similar way that works very beautifully. Most of the articles I look up have the pgfplots code set up in similar matter. I only want to use my language for labes, titles and stuff like that. If someone could point me to my error, I would really appreciate it :)

  • The names in symbolic x coords should be the same as in coordinates. otherwise you get error `coordinate ... is unknow, – Zarko Mar 21 '23 at 15:12

1 Answers1

2
  • please always provide MWE (Minimal Working Example), i.e. a small but complete document which reproduce your problem, not two code fragments (see an example below)
  • as I said in comment, the names insymbolic x coords should be the same as are used in coordinates at \addplot . an example of MWE, which produce desired diagram:
\documentclass[a4paper,12pt,twoside,BCOR=10mm]{scrbook}
\usepackage[icelandic]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{pgfplots} \pgfplotsset{compat=1.18}

\begin{document} \begin{figure}[ht] \centering \begin{tikzpicture} \begin{axis}[ width=.8\linewidth, height=7cm, ymajorgrids, title=Flutningstakmarkanir yfir spátímabilið, enlarge x limits = 0.25, % <--- added ybar, xlabel={Sviðsmyndir}, ylabel={Milljón $ }, xtick=data, symbolic x coords = {A, B, C}, legend columns=-1, % to set one line legend legend style={at={(0.5,-0.3)},anchor=center}, ] \addplot coordinates { (A,98) (B,59) (C,43)}; % <--- \addplot coordinates { (A,95) (B,57) (C,42)}; % <--- \legend{text 1, text 2} % <--- added \end{axis} \end{tikzpicture} \end{figure} \end{document}

Note:

  • that use of symbol coordinates is more clear, i change thewir names to A, B and C. However, you can change them to what you wish, but remember, the same names you should use in symbolic x coords and in coordinates.
  • I a wee bet shorten your code, changes are marked in code by % <---

enter image description here

Zarko
  • 296,517