1

Consider this almost-MWE:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.9}
\begin{document}

\begin{tikzpicture}[]
\begin{axis}[clip=false,
    width=12cm, height=12cm,
    xmin=0, xmax=10,
    ymin=-1, ymax=11,
    grid=both,
    major grid style={black!50, dashed},
    ytick={-1,...,11},
    xlabel = {input voltage $E$ (V)},
    ylabel = {output voltage $v_o$ (V)}, % clip=false,
] 
\draw [thick, ->] (axis cs: 0,0) -- (axis cs: 10,0) node[below left] {$E$};  
\draw [ultra thick, color=blue, draw opacity=0.5] (axis cs: 0, 10) -- (axis cs: 0.7, 10) -- (axis cs: 1.6, 0.9) -- (axis cs: 10,9.3);
\draw[ultra thick, color=blue, ->] (axis cs: 4,3.5) -- node [above]{$v_o$} (axis cs: 3,3.5);
\fill [black!50, fill opacity=0.5] (axis cs: 0, 10.5) rectangle node[black](off){A} (axis cs:0.7, 11);
\fill [green!50, fill opacity=0.5] (axis cs: 0.7, 10.5) rectangle node[black](lin){B} (axis cs:1.6, 11);
\fill [red!50, fill opacity=0.5] (axis cs: 1.6, 10.5) rectangle node[black](sat){C} (axis cs:10, 11);
\end{axis}
\path (2,13) node[rectangle, draw](off text){OFF zone};
\path (4.5,12) node[rectangle, draw](lin text){LINear zone};
\path (7,11) node[rectangle, draw](sat text){SATuration zone};
\path [<-] (off.center) edge[bend left] (off text.west);
\path [<-] (lin.center) edge[bend left] (lin text.west);
\path [<-] (sat.center) edge[bend left] (sat text.west);
\end{tikzpicture}
\end{document}

It gives the correct output --- I know that the position of node (sat) is not ideal, but I will fix that after I understood this puzzle:

graphic ok

The problem is that if I add [scale=0.8] to the main tikzpicture environment, what happens is the following (excerpt of the upper part of the drawing, to save space:

Bad graphic

It's like if, although the nodes are correctly moved (see the A, B, C labels in the colored band), when I try to connect the nodes from inside the axis to outside something break.

I suppose it's, as ever, an operator error... but which one? It is possible to easily fix it?

PS --- I am using Ubuntu 14.04, with TeXLive2013, and the maximum pfgcompat accepted is 1.9.

PPS (later) --- I can express all in axis cs: coordinate, but this will work only if clip=false; if I need to clip the axis environment that approach will not work.

1 Answer 1

2

The problems are caused by the different coordinate systems, I believe. Therefore I moved the \path-commands into the axis environment and adjusted their position slightly.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.9}
\begin{document}

\begin{tikzpicture}[scale=0.8]
\begin{axis}[clip=false,
    width=12cm, height=12cm,
    xmin=0, xmax=10,
    ymin=-1, ymax=11,
    grid=both,
    major grid style={black!50, dashed},
    ytick={-1,...,11},
    xlabel = {input voltage $E$ (V)},
    ylabel = {output voltage $v_o$ (V)}, 
] 
\draw [thick, ->] (axis cs: 0,0) -- (axis cs: 10,0) node[below left] {$E$};  
\draw [ultra thick, color=blue, draw opacity=0.5] (axis cs: 0, 10) -- (axis cs: 0.7, 10) -- (axis cs: 1.6, 0.9) -- (axis cs: 10,9.3);
\draw[ultra thick, color=blue, ->] (axis cs: 4,3.5) -- node [above]{$v_o$} (axis cs: 3,3.5);
\fill [black!50, fill opacity=0.5] (axis cs: 0, 10.5) rectangle node[black](off){A} (axis cs:0.7, 11);
\fill [green!50, fill opacity=0.5] (axis cs: 0.7, 10.5) rectangle node[black](lin){B} (axis cs:1.6, 11);
\fill [red!50, fill opacity=0.5] (axis cs: 1.6, 10.5) rectangle node[black](sat){C} (axis cs:10, 11);
\path (axis cs: 2,13) node[rectangle, draw](off text){OFF zone};
\path (axis cs: 3.5,12) node[rectangle, draw](lin text){LINear zone};
\path (axis cs: 7,12) node[rectangle, draw](sat text){SATuration zone};
\path [<-] (off.center) edge[bend left] (off text.west);
\path [<-] (lin.center) edge[bend left] (lin text.west);
\path [<-] (sat.center) edge[bend left] (sat text.west);
\end{axis}

\end{tikzpicture}
\end{document}

Now the scale key works as intended (0.8 vs 1.5):

enter image description here

2
  • Yes, this works --- but I have another graphic where I need to use clip=true and this will make this solution impossible. The problem is that I can't understand why it happens; coords should be scaled the same way...
    – Rmano
    Commented Apr 17, 2015 at 5:44
  • I don't really know why either. All I know is, that pgfplots does some pretty sophisticated things in its axis environment. For example: All text produced inside it is affected by scale, which is not the standard behaviour of TikZ. Therefore I recommend not to use axis besides regular code in the same tikzpicture. Maybe you could put two tikzpictures separated by some hspace in a single figure?
    – JBantje
    Commented Apr 17, 2015 at 6:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .