I have a U-I-diagramm in physics of a yellow LED. I use a yellow line, because the LED is yellow. For better reading of the diagram I add a black dashed line over the yellow line. Here is my approach:
\documentclass[varwidth, margin=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{pgf, tikz}
\usetikzlibrary{datavisualization}
\begin{document}
\begin{tikzpicture}
\datavisualization [
school book axes,
x axis = {
grid,
ticks={step=1, minor steps between steps=9},
attribute=U,
label={[node style={fill=blue!20}]{$U$ in Volt}},
unit length=2cm
},
y axis = {
grid,
ticks={
step=0.01,
tick typesetter/.code={%
%https://tikz.dev/math-numberprinting
\pgfmathprintnumber[fixed, fixed zerofill, precision=2]{##1} }
},
attribute=I,
label={[node style={fill=red!20}]{$I$ in Ampere}},
unit length=100cm
},
visualize as line/.list={LEDyellow2, LEDyellow},
legend={below, rows=2},
LEDyellow={
%label in legend={text={LED yellow}},
style={yellow}
},
LEDyellow2={
label in legend={text={LED yellow}},
style={black, dashed}
},
]
data [set=LEDyellow, separator=\space]{
U I
0 0
1.7 0
1.8 0.004
1.9 0.01
2.0 0.02
2.1 0.08
%2.2 0.20
}
data [set=LEDyellow2, separator=\space]{
U I
0 0
1.7 0
1.8 0.004
1.9 0.01
2.0 0.02
2.1 0.08
%2.2 0.20
};
\end{tikzpicture}
\end{document}
Questions:
- In my workaround to make a black-yellow dashed line I printed two datavisualisations over each other. Is there a better way to achieve this? A disadvantage of my workaround is that the legend doesn't show the yellow-black dashed line.
- In my approach I use two data sets (LEDyellow and LEDyellow2). Is it possible to reuse the first dataset? This is not only interesting in my case. I think on a case where the first datavisualisation does a "line" and then the second datavisualisation does a "smooth line" of the same data set.
- What is the reason for the printing order? My first try was the order
visualize as line/.list={LEDyellow, LEDyellow2}
because it is logical to print first the pure yellow line and then the dashed black line over the yellow line. But the reverse order brings the desired result. - The grid goes into the numbers on the U- and I-axis. Why is that the default behaviour? Howto correct this?
Thanks.
postaction
, but sadly, it seems that this does not work withdatavisualization
. Would a PGFPlots solution work for you?postaction
. Qrrbrbirlbel was able to find an answer with this tip.