1

I'm having a hard time trying to center a simple pgfplots.

This is my code:

    \begin{figure}[h!]
    \centering
    \caption{ Comparação da função tangente hiperbólica em diferentes implementações.}
    \vspace{\baselineskip}
    \fonte{Próprio autor.}
    \label{fig:tanh-plot}
    \begin{tikzpicture}[spy using outlines={circle, magnification=3, connect spies}]
        \begin{axis}[
            xlabel={$ x $},
            ylabel={$ y = \tanh{x} $},
            xmin=-3.5, xmax=3.5,
            ymin=-1.0, ymax=1.0,
            legend pos=north west,
            ymajorgrids=true,
            grid style=dashed,
        ]

            \addplot[color=orange, mark=*,]
                table {plots/tanh-tf.dat};
                \addlegendentry{Keras/TensorFlow (Python)}

            \addplot[color=blue, mark=*,]
                table {plots/tanh-vhdl.dat};
                \addlegendentry{Interpolação (VHDL)}

            \coordinate (spypoint) at (axis cs:-.75, -.63);
            %\coordinate (spypoint) at (axis cs:0, 0);
            \coordinate (magnifyglass) at (axis cs:2, -.2);

        \end{axis}

        \spy[blue, size=8cm] on (spypoint) in node[fill=white] at (magnifyglass);
    \end{tikzpicture}
\end{figure}

Which gives me the following result (I only cropped the bottom part of the page):

Buggy plot :(

How do I center the plot? It seems to have space in the left margin to do so, so why doesn't it?

  • 3
    The text "Próprio autor." and the plot are on the same line in the same paragraph. – Heiko Oberdiek May 8 '18 at 0:00
  • @HeikoOberdiek I guess that was it (?) -- see my answer. Thanks! – gabrieljcs May 8 '18 at 3:18
1

Turns out all I had to do was place this section:

\vspace{\baselineskip}
\fonte{Próprio autor.}
\label{fig:tanh-plot}

after \end{tikzpicture}.

I think I also need some sleep as well.

The result now: fixed, pretty plot

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.