This is a follow-up to a previous question of mine, with a slight addition. I would like to loop over data in a file and give the plot styles as a list. In the old question I gave only a color and an index and Christian Hupfer came up with a working solution as did, with a slight variation, cmhughes.
Now, I would like to specify the style more precisely. For example, I would like to be able to draw dotted or dashed lines like in the following MWE
\documentclass{article}
\usepackage{xcolor}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\pgfplotsforeachungrouped \foridx/\forcol/\forstyle in {1/black/solid,2/red/dashed,3/green/dotted,4/blue/solid,5/orange/dotted}{
\expandafter\addplot\expandafter[\forcol,\forstyle]{x^\foridx};
}
\end{axis}
\end{tikzpicture}
\end{document}
If I leave out \forstyle
and the third arguments in the list, I get Christian Hupfer's solution which is working. Like this, it produces many errors:
! Undefined control sequence.
<argument> ...pgfplots@foreach@loc@TMPb \forstyle
l.9 }
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
Missing character: There is no 1 in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no b in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no c in font nullfont!
Missing character: There is no k in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no s in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no i in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no , in font nullfont!
Missing character: There is no 2 in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no s in font nullfont!
Missing character: There is no h in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no , in font nullfont!
Missing character: There is no 3 in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no g in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no n in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no , in font nullfont!
Missing character: There is no 4 in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no b in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no u in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no s in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no i in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no , in font nullfont!
Missing character: There is no 5 in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no n in font nullfont!
Missing character: There is no g in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no d in font nullfont!
! Undefined control sequence.
\pgfkeyscurrentkey ->\forstyle
l.9 }
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.
NOTE: coordinate (2Y5.0e0],3Y0.0e0]) has been dropped because it is unbounded (
in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y4.5833334e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y4.1666669e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y3.7500003e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y3.3333337e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y2.9166672e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y2.5000006e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y2.083334e0],3Y0.0e0]) has been dropped because it is unboun
ded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y1.6666675e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y1.2500009e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y8.333344e-1],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y4.166677e-1],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (2Y9.9e-7],3Y0.0e0]) has been dropped because it is unbounded
(in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y4.1666573e-1],3Y0.0e0]) has been dropped because it is unbo
unded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y8.3333243e-1],3Y0.0e0]) has been dropped because it is unbo
unded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y1.24999913e0],3Y0.0e0]) has been dropped because it is unbo
unded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y1.6666656e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y2.0833322e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y2.4999988e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y2.9166653e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y3.3333319e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y3.7499985e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y4.166665e0],3Y0.0e0]) has been dropped because it is unboun
ded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y4.5833316e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
! Package PGF Math Error: Could not parse input '' as a floating point number,
sorry. The unreadable part was near ''. (in 'x^').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.9 }
(That was another \errmessage.)
NOTE: coordinate (1Y4.9999982e0],3Y0.0e0]) has been dropped because it is unbou
nded (in y). (see also unbounded coords=jump).
With the linked code snippet from cmhughes, I couldn't get it to work either with similar errors (probably the same problem)
So I tried to give the arguments to \addplot
in a list:
\pgfplotsforeachungrouped \foridx/\forstyle in {1/{black,solid},2/{red,dashed},3/{green,dotted},4/{blue,solid},5/{orange,dotted}}{
\expandafter\addplot\expandafter[\forstyle]{x^\foridx};
}
This compiles but it produces only a solid black line (it loops only over the first element)
In fact, I could not get any example with three variables working. How do I use pgffor
with three or more variables?