1

I am trying to make a violet horizontal bar chart. So far I managed to make a violet outline with a blue filling, but when I try to get a violet filling Latex compilation fails.

Here is an example of what I'd want:

    \documentclass[10pt]{article}

    \usepackage{color} %include colors
    \usepackage{pgfplots}
    \usetikzlibrary{patterns}

    \begin{document}

    \begin{figure}
      \begin{tikzpicture}
        \begin{axis}
          [
          axis lines*=left,
          xbar,
          xlabel={Pourcentage d'activité},
          symbolic y coords={Énergies},
          ytick=data,
          xmin=0,
          xmax=50,
          nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%},
          nodes near coords align={horizontal}
          ]
          \addplot[draw=violet, pattern=horizontal lines light violet]
          coordinates{(33,Énergies)};
        \end{axis}
      \end{tikzpicture}
    \end{figure}

    \end{document}

However if I compile with:

$ latexmk -pdf -pdflatex=lualatex -outdir=tmp test.tex

I get the following error:

! Package pgf Error: Undefined pattern `horizontal lines light violet'.

See the pgf package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.25     \end{axis}

While the error message seems clear, if I only change horizontal lines light violet for horizontal lines light blue, the code compiles and I get the following output:

Blue bars with a violet outline

Moreover, if I look at the manual for pgfplots, which I found here, there is a snippet of code about using this horizontal line pattern at page 81, and if I click on the blue in the snippet, it sends me to a list of colors page 191 of the same document that contains, among others, violet.

What I want to do: in a first time, use the color violet as a filling for my chart, and ideally I'd like to be able to define a custom color (e.g. \definecolor{myPurple}{RGB}{73,10,61}) and use it as a filling for the bar chart.

edit:

  • I am using Windows 10 pro 64bits with MikTex
  • MikTex version is 2.9.6420
  • latexmk version Latexmk, John Collins, 19 Jan. 2017. Version 4.52c
  • lualatex version This is LuaTeX, Version 1.0.4 (MiKTeX 2.9.6420 NEXT 64-bit)
  • Regarding manuals: you likely have them installed as part of MikTeX. Try opening the Start menu, type texdoc pgf in the search field and hit enter. If that doesn't work, open a command prompt and type the same thing. That should open the documentation for pgf/TikZ, corresponding to the version you have installed. If you do that, and find the description of the patterns library, you'll see that there are just a couple of such filled patterns defined by default. They are not directly linked to colours, in the sense that you can just type a different colour name (as you've seen). – Torbjørn T. Sep 15 '17 at 10:14
1

You can define a new pattern similar to horizontal lines light blue, where you set the two colours of the pattern yourself.

(pgfplots loads xcolor, so no need to load color separately.)

output of code

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\definecolor{myPurple}{RGB}{73,10,61}

% based on code in pgflibrarypatterns.code.tex
% corresponding to horizontal lines light blue, with a different colour
\pgfdeclarepatterninherentlycolored{horizontal lines Purple} % define name of pattern here
{\pgfpointorigin}{\pgfpoint{100pt}{4pt}}
{\pgfpoint{100pt}{4pt}}
{
  \pgfsetfillcolor{myPurple} % set first colour
  \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{100pt}{2.5pt}}
  \pgfusepath{fill}
  \pgfsetfillcolor{myPurple!90} % set second colour
  \pgfpathrectangle{\pgfpoint{0pt}{2pt}}{\pgfpoint{100pt}{2.5pt}}
  \pgfusepath{fill}
}

\begin{document}

\begin{figure}
  \begin{tikzpicture}
    \begin{axis}
      [
      axis lines*=left,
      xbar,
      xlabel={Pourcentage d'activité},
      symbolic y coords={Énergies},
      ytick=data,
      xmin=0,
      xmax=50,
      nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%},
      nodes near coords align={horizontal}
      ]
      \addplot[pattern=horizontal lines Purple]
      coordinates{(33,Énergies)};
    \end{axis}
  \end{tikzpicture}
\end{figure}

\end{document}
  • It worked like a charm, many thanks for that and the tip about doc ! :) – Alexandre Leonardi Sep 15 '17 at 11:14

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.