LaTeX forum ⇒ Graphics, Figures & TablesPgfonlayer

Information and discussion about graphics, figures & tables in LaTeX documents.
mtanner
Posts: 7
Joined: Sat Jul 22, 2017 9:55 am

Pgfonlayer

Postby mtanner » Thu Jan 10, 2019 9:44 am

I have a couple of simple charts. Pgfonlayer seems to work fine in one chartbut not the other.
First chart uses:
  1. \begin{pgfonlayer}{forground}
  2. .. several \node statements
  3. \end{pgfonlayer}

to make the nodes appear on top of the lines plotted in the graph. This works exactly as expected.

Second chart is a stacked area chart with some guidelines overlaid by
  1. \begin{pgfonlayer}(foreground}
  2. .. several \draw statements
  3. \end{pgfonlayer}


but this gives error messages
"missing } inserted"
"extra } or missing \endgroup"

The \draw statements work ok when the pgfonlayer statements are removed, except the guidelines are behind the area plot, which is what I am trying to avoid. The error messages seem to saying a } is missing so one is inserted, but then complaining that there is an extra }.

Any suggestions please?
Last edited by Stefan Kottwitz on Thu Jan 10, 2019 12:39 pm, edited 1 time in total.
Reason: code marked

User avatar
Stefan Kottwitz
Site Admin
Posts: 9336
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Thu Jan 10, 2019 12:41 pm

Hi!

I guess there's a syntax error in the \node or \draw commands that is not shown here.

Can you please post a complete code for that pgf/TikZ image?

Thanks,

Stefan
Site admin

mtanner
Posts: 7
Joined: Sat Jul 22, 2017 9:55 am

Postby mtanner » Thu Jan 10, 2019 1:17 pm

The actual tex code is on another, not connected. system, but I will arrange to copy it across. However, since the \draw statements work ok without the pgfonlayer statements, then I think that demonstrates there is no systax error in them. At most it might make a diference whether the \draw statements are terminated by a semi-colon or not but I have tried all obvious variations, and TexMaker syntax highlighter tells me that the { and } match up properly/.

I admit to being hazy about pgfplots syntax, whether things are terminated by a sem-colon or not - I generally just copy previous working code. I would like to understand this kore, but the pgfplots user guide has a daunting amount of detail, but ;littel middle-level guidance. Any pointers to good introductory documemts would be helpful - there are anumber of simple introductions but they seem tol concentrate of a cookbook approach to drawing simple and then more complex charts, without addressing the language syntax directly.

The thing that runs through my mind is that the chart that works just has sinple lines plotted, while the chart that fails has stacked area plots with \closedcycle at the end of the coordinate lists.

mtanner
Posts: 7
Joined: Sat Jul 22, 2017 9:55 am

Postby mtanner » Thu Jan 10, 2019 1:20 pm

I have a simple work-around, which is to mode the \draw statements before the \addplot statemnets for the statcked areaa. This puts the \draw lines in front of the areas, but this is a workaround rather than a solution.

User avatar
Stefan Kottwitz
Site Admin
Posts: 9336
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Thu Jan 10, 2019 1:21 pm

I guess I would see the cause immediately when I see a complete picture code or compile it myself to trigger the error. ;-)

Stefan
Site admin

mtanner
Posts: 7
Joined: Sat Jul 22, 2017 9:55 am

Postby mtanner » Thu Jan 10, 2019 1:36 pm

Here is the code. In the actual document this code is within a subfigure, and there is a preamble with a lot of \usepackage statements. The pgfonlayer statements are commented out in the code below, towards the end and surrounding some \draw statements. I am using TexMaker 4.5.

  1. \begin{tikzpicture}
  2. \pgfdeclarelayer{background}
  3. \pgfdeclarelayer{foreground}
  4. \pgfsetlayers{background,main,foreground}
  5. %--------Left axis--------
  6. \begin{axis}[width=6.0cm,height=5.0cm,scale only axis,
  7. unbounded coords=jump,
  8. stack plots=y,area style,
  9. xticklabel style={font=\scriptsize},
  10. xlabel style={font=\scriptsize},
  11. yticklabel style={font=\scriptsize},
  12. ylabel style={font=\scriptsize},
  13. xmin=10.0,xmax=60.0,
  14. ymin=20.0,ymax=40.0,
  15. xlabel={target time},
  16. ylabel={agents},
  17. legend entries={ready,
  18. talk},
  19. legend style={font=\scriptsize,rounded corners=2pt,
  20. at={(rel axis cs:0.02,0.50)},anchor=west}]
  21. \addlegendimage{area legend,black,no markers,fill=green}
  22. \addlegendimage{area legend,black,no markers,fill=blue}
  23. \addplot [mark=none,fill=green]
  24. coordinates {
  25. (10,30)(12.7,30)(12.7,30)(28.45,30)(28.45,30)(53.83,30)(53.83,30)
  26. (60,30)}\closedcycle;
  27. \addplot [mark=none,fill=blue]
  28. coordinates {
  29. (10,6)(12.7,6)(12.7,5)(28.45,5)(28.45,4)(53.83,4)(53.83,3)
  30. (60,3)}\closedcycle;
  31. %\begin{pgfonlayer}{foreground}
  32. \draw[dotted](axis cs:12.70,20.00)--(axis cs:12.70,40.00);
  33. \draw[dotted](axis cs:28.45,20.00)--(axis cs:28.45,40.00);
  34. \draw[dotted](axis cs:53.83,20.00)--(axis cs:53.83,40.00);
  35. %\end{pgfonlayer}
  36. \draw[dotted](axis cs:60.00,20.00)--(axis cs:60.00,40.00);
  37. \end{axis}
  38. \end{tikzpicture}

mtanner
Posts: 7
Joined: Sat Jul 22, 2017 9:55 am

Postby mtanner » Thu Jan 10, 2019 1:38 pm

Just had a thought. Could it be related to the "area style" command in the axis statement - do I nee to overlay another axis for the \draw?

mtanner
Posts: 7
Joined: Sat Jul 22, 2017 9:55 am

Postby mtanner » Thu Jan 10, 2019 1:43 pm

If I take out the "stack plots=y,area style" then the code workds/ Of course the areas are npot stacked so it does not give me what I want, but it does suggest I need to do the \draw's in a separate axis.

User avatar
Stefan Kottwitz
Site Admin
Posts: 9336
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Thu Jan 10, 2019 2:12 pm

Interesting!

Good that you have a workaround. I think I can take a look again later on it. It reminds me of bug #53 pgfplots and pgfonlayer incompatibility but this had been fixed: Maybe stack plots already use layers internally, but for digging deeper I will have time later today I guess.

Stefan
Site admin


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 2 guests