2

So here's my beautiful work so far. Looking good, except that now I've miraculously discovered that sometimes I need negative y-axis. However, simply adding ymin and ymax to \begin{axis} for the problematic U_L graph did not do the trick.

What to do?

Thank you.

\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{decorations, arrows}
\usepackage{amsmath}

\pgfplotsset{Diagram/.style={
            axis lines = left,
    xmax=9,
    xmin=0,
    ymax=1.5,
    ymin=0,
    xlabel = {$t$},
    xlabel style={at={(1,0)},anchor=west},
    ylabel style={at={(0,1)},rotate={-90},anchor=north east},
    ytick=\empty,
    no marks,
    every axis plot post/.append style={very thick, red},
                    }% end of Diagram style
            }% end of pgfplotsset


\begin{document}
%%%%%%%%%%%% Diagramme f. 4TPPC %%%%%%%%%%%%
\begin{figure}

\pgfplotsset{xticklabels={ , , , $T/2$, , $T$}, height=4cm, width=0.8\textwidth}

\centering

\begin{tikzpicture}[trim axis left]

\begin{axis}[Diagram, ylabel = $U_{GS_{1,4}}$, extra x ticks={3,7}, extra x tick labels={\mbox{\tiny $DT$},\mbox{\tiny ${T/2+DT}$}}]

\addplot coordinates {(0,1)  (3,1) (3,0)  (8,0) };
\end{axis}

\end{tikzpicture}

\begin{tikzpicture}[trim axis left]

\begin{axis}[Diagram, ylabel = $U_{GS_{2,3}}$, extra x ticks={3,7}, extra x tick labels={\mbox{\tiny $DT$},\mbox{\tiny ${T/2+DT}$}}]
\addplot coordinates {(0,0)  (4,0)  (4,1)  (7,1) (7,0) (8,0)};
\end{axis}

\end{tikzpicture}

\begin{tikzpicture}[trim axis left]

\begin{axis}[Diagram, ylabel = $U_L$, extra x ticks={3,7}, extra x tick labels={\mbox{\tiny $DT$},\mbox{\tiny ${T/2+DT}$}}, ymin=-2, ymax=2]
\addplot coordinates {(0,.5)  (3,.5) (3,-1.5)  (8,-1.5) };



\end{axis}

\end{tikzpicture}

\begin{tikzpicture}[trim axis left]

\begin{axis}[Diagram, ylabel = $i_L$, extra x ticks={3,7}, extra x tick labels={\mbox{\tiny $DT$},\mbox{\tiny ${T/2+DT}$}}]
\addplot coordinates {(0,.4)  (3,.7)  (4,.4)  (7,.7) (8,.4) };
\draw [ultra thin, blue, dashed] (0,0.7)  --  (8,0.7) ;
\draw [ultra thin, blue, dashed] (0,.4) -- (8,0.4) ;
\draw [thick, blue, <->] (8,.4) -- (8,.7);
\node [right] at (8,.55){$\Delta i_L$};


\end{axis}

\end{tikzpicture}

\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}
4
  • 1
    Not entirely sure what you mean, but I guess you want to use axis lines = middle and not axis lines = left in the Diagram style. – Torbjørn T. Nov 1 '17 at 14:56
  • That does the trick. Do I understand correctly, that this command sets the x-Achis in the middle of y, except there are no negative y values present? – SF6 Nov 1 '17 at 21:36
  • Not entirely sure what you mean, with that the x-axis is placed at y=0, the y-axis at x=0. – Torbjørn T. Nov 1 '17 at 21:44
  • One problem I've discovered, if I use axis lines = middle, the i_L graph changes and all of the sudden the curve starts at (0,0) event though I've set\addplot coordinates {(0,.4)... – SF6 Nov 1 '17 at 22:42
3
  1. in my answer i anticipated that your diagrams will be only in the first quadrant, but extend proposed solution is quite simple. instead there defined common pgfplots style (Diagram) use the following:

\pgfplotsset{Diagram/.style={
            axis lines = middle,
    xmax=9,
%    xmin=0,                                % <--- removed
    ymax=1.5,
    ymin=0,
    xlabel = {$t$},
    xlabel style={anchor=west},             % <--- changed
    xticklabel style={font=\scriptsize},    % <--- added
%    ylabel style={at={(0,1)}},             % <--- removed
    ytick=\empty,
    no marks,
    every axis plot post/.append style={very thick, red},
                    }% end of Diagram style
            }% end of pgfplotsset
  1. you can always overriding global (common) settings locally with new \pgfplotssset. it will valid only in used tikzzpicture or in figure as is done in mwe below
  2. if the diagrams in one figure has common additional style, it is sensible (for shorter code) defined it in local pgfplotsset as is done in mwe below
  3. for ticks labels instead your solution is better to define font size in common pgfplots style

like this?

enter image description here

\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\pgfplotsset{Diagram/.style={
            axis lines = middle,
    xmax=9,
%    xmin=0,                                % <--- removed
    ymax=1.5,
    ymin=0,
    xlabel = {$t$},
    xlabel style={anchor=west},             % <--- changed
    xticklabel style={font=\scriptsize},    % <--- added
%    ylabel style={at={(0,1)}},             % <--- removed
    ytick=\empty,
    no marks,
    every axis plot post/.append style={very thick, red},
                    }% end of Diagram style
            }% end of pgfplotsset


\begin{document}
%%%%%%%%%%%% Diagramme f. 4TPPC %%%%%%%%%%%%
\begin{figure}
\pgfplotsset{xticklabels={ , , , $T/2$, , $T$},
             height=4cm, width=0.8\textwidth,
             extra x ticks={3,7},
             extra x tick labels={$DT$,${T/2+DT}$}
             }
\centering
\begin{tikzpicture}
\begin{axis}[Diagram, ylabel = $U_{GS_{1,4}}$]
\addplot coordinates {(-1,1)  (3,1) (3,0)  (8,0) };
\end{axis}
\end{tikzpicture}

\medskip
\begin{tikzpicture}
\begin{axis}[Diagram, ylabel = $U_{GS_{2,3}}$]
\addplot coordinates {(-1,0)  (4,0)  (4,1)  (7,1) (7,0) (8,0)};
\end{axis}
\end{tikzpicture}

\medskip
\begin{tikzpicture}
\begin{axis}[Diagram,
             ymin=-1.5,                % <---- added
             ylabel = $U_L$]
\addplot coordinates {(-1,.5) (0,.5)  (3,.5) (3,-1.5)  (8,-1.5) };
\end{axis}
\end{tikzpicture}

\medskip
\begin{tikzpicture}
\begin{axis}[Diagram,
             xmin=-1,               % <---- added
             ylabel = $i_L$, ]
\addplot coordinates {(0,.4)  (3,.7)  (4,.4)  (7,.7) (8,.4) };
\draw [ultra thin, blue, dashed] (0,0.7)  --  (8,0.7) ;
\draw [ultra thin, blue, dashed] (0,.4) -- (8,0.4) ;
\draw [thick, blue, <->] (8,.4) -- (8,.7);
\node [right] at (8,.55){$\Delta i_L$};
\end{axis}
\end{tikzpicture}
    \end{figure}
\end{document}

edit: in cases when, you have mixed diagrams as shown below, some with negative independent variable, some with only positive and in this mix of diagrams aligning of diagrams' coordinates axis is not important, you can delete xmin=-1 in the last diagram and then obtain the following result:

enter image description here

code for the last diagram is:

...
\begin{tikzpicture}
\begin{axis}[Diagram,
             ylabel = $i_L$, ]
\addplot coordinates {(0,.4)  (3,.7)  (4,.4)  (7,.7) (8,.4) };
\draw [ultra thin, blue, dashed] (0,0.7)  --  (8,0.7) ;
\draw [ultra thin, blue, dashed] (0,.4) -- (8,0.4) ;
\draw [thick, blue, <->] (8,.4) -- (8,.7);
\node [right] at (8,.55){$\Delta i_L$};
\end{axis}
\end{tikzpicture}
...
5
  • My bad, I forgot to tick your answer as the solution. Thanks again, I've corrected it. Back to this problem. I do not quite understand, why you added xmin=-1 to i_L as it does not contain any negative numbers for x and y plots. If put there, the other diagrams suddenly appear to have negative x values, which they don't. How can this be? Changing axis line = left to middle, as suggested by Torbjørn T does the trick although I don't quite understand why. Gee, how long have you been working with pgfplots/tikz? You guys are so experienced. – SF6 Nov 1 '17 at 21:40
  • just for extending x-axis to negative values. if it is not needed (since no drawing at negative time), can be deleted. – Zarko Nov 1 '17 at 21:43
  • But how come, with only that line xmin=-1 locally added to i_L, all of the sudden the other graphs U_GS_1,4 and U_L appear to have negative x values? (That's more of an academic "looking behind the curtain" question) – SF6 Nov 1 '17 at 21:53
  • no, others have first coordinate with negative value. ok, i will change example and remove xmin=-1 in the last diagram. – Zarko Nov 1 '17 at 22:00
  • @SF, i edit my answer and try to answer in your questions in comments – Zarko Nov 1 '17 at 23:48

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.