Warum werden nicht bei jedem meiner Labels/Stile kleine Knoten angezeigt?

Warum werden nicht bei jedem meiner Labels/Stile kleine Knoten angezeigt?

Ich kann nicht herausfinden, welchen Fehler ich mache, aber ich kann die globale Schriftgröße beispielsweise \tinyfür die Beschriftungsknoten nicht einstellen. Ich habe es versucht every label/.style={font=\tiny}. Es scheint für die Achsenbeschriftungen zu funktionieren, aber nicht für den Beschriftungsknoten. Mein MWE:

\documentclass[12pt]{article}
\usepackage[dvips]{graphicx,color}
\usepackage{wasysym}

\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{xcolor}

\usetikzlibrary{arrows,plotmarks}
\usetikzlibrary{intersections,positioning}

\begin{document}
\pgfplotsset{
  standard/.style={%Axis format configuration
    axis x line=middle,
    axis y line=middle,
    enlarge x limits=0.15,
    enlarge y limits=0.15,
    every label/.style={font=\tiny},
    every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
    every axis y label/.style={at={(current axis.above origin)},anchor=north east},
   every axis plot post/.style={mark options={fill=black}}
    }
 }
\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}[baseline=(current bounding box.center)]
    \begin{axis}[axis lines=middle, xtick={-1,0,1},
      xticklabels={-1, 0, 1},
      extra x tick style={
      xticklabel style={yshift=0.5ex, anchor=south}},
      xmin=-4,xmax=4, ytick={\empty}, yticklabels={}, 
      ymin=-2, ymax=2, axis on top,
      enlarge y limits=0.35,
      width=6cm,
      xlabel={$n$}, x label style={anchor=north},
      ylabel={$x[n]$}, y label style={anchor=west}]
      \addplot+[ycomb,black,thick] plot coordinates
      {(-1,1) (0,2) (1,1)};
      \node[anchor=south west] at (axis cs:0,2) {$2$};
      \node[anchor=south east] at (axis cs:-1,1) {$1$};
      \node[anchor=south west] at (axis cs:1,1) {$1$};
      \end{axis}
      \end{tikzpicture}%
      \hspace*{3mm} {\Huge\pointer} \hspace*{3mm}%
      \begin{tikzpicture}[baseline=(current bounding box.center)]
      \pgfplotsset{every tick label/.append style={font=\tiny},
        every label/.append style={font=\tiny}}
      \begin{axis}[axis lines=middle, xtick={-3,-2,...,3},
        xticklabels={{}, {}, {}, 0, 1, 2, 3},
        extra x ticks={-2,-1},
        extra x tick labels={$-3$,$-2$,$-1$},
        extra x tick style={
          xticklabel style={yshift=0.5ex, anchor=south}},
        xmin=-4,xmax=4, ytick={\empty}, yticklabels={}, 
        ymin=-2, ymax=2, axis on top,
        enlarge y limits=0.35,
        width=6cm,
        xlabel={$n$}, x label style={anchor=north},
        ylabel={$y[n]$}, y label style={anchor=west}]
        \addplot+[ycomb,black,thick] plot coordinates
        {(-3,0) (-2,-1) (-1,-2) (0,0) (1,2) (2,1) (3,0)};
        \node[anchor=north] at (axis cs:-2,-1) {$-1$};
        \node[anchor=north] at (axis cs:-1,-2) {$-2$};
        \node[anchor=west] at (axis cs:1,2) {$2$};
        \node[anchor=west] at (axis cs:2,1) {$1$};
      \end{axis}
    \end{tikzpicture}%
  \end{center}
\end{figure}
\end{document}

Bildbeschreibung hier eingeben

Antwort1

Das hat verschiedene Ursachen, aber der Hauptgrund ist, dass Sie nichthabenalle „Label-Knoten“ im Sinne von TikZ. Label-Knoten sind Knoten, die auf Knoten selbst angewendet werden, wie \node [label=above:I am a label node] {I am the main node};. Die Knoten, die Sie verwenden, sind nur „normale“ Knoten.

Sagte, dass Sie auf die Idee kommen können, dann Staat zB every node/.append style={font=\tiny,green}(in der \tikzset), aber weilallesder Text enthält, ist ein Knoten, das wäre viel mehr, als Sie wollen. Probieren Sie es aus und sehen Sie, was passiert.

Ich habe mir erlaubt, Ihr MWE ein wenig zu modifizieren und einige Dinge neu zu ordnen. Dann habe ich alles kommentiert, was „etwas seltsam“/„nicht ganz unkompliziert“ ist, nur für den Fall, dass Sie neben der Frage nach dem „winzigen Knoten“ noch andere Dinge lernen möchten.

Wenn Sie nur an dem „winzigen Knotenkram“ interessiert sind, suchen Sie nach den Blöcken, die von gestrichelten Linien umgeben sind.

Weitere Einzelheiten entnehmen Sie bitte den Kommentaren im Code.

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
% -----------------------------------------------------------------------------
% one possibility to show tiny labels is to define a new style which you
% apply later to the corresponding nodes
\tikzset{
    Label/.style={
        font=\tiny,
        red,
    },
}
% -----------------------------------------------------------------------------
%\pgfplotsset{
%    % this (whole) style isn't *used* in the following tikzpictures/axis
%    % environments so it isn't needed here
%    standard/.style={%Axis format configuration
%        axis x line=middle,
%        axis y line=middle,
%        enlarge x limits=0.15,
%        enlarge y limits=0.15,
%        every label/.style={font=\tiny},
%        every axis x label/.style={
%            at={(current axis.right of origin)},
%            anchor=north west,
%        },
%        every axis y label/.style={
%            at={(current axis.above origin)},
%            anchor=north east,
%        },
%        every axis plot post/.style={
%            mark options={fill=black},
%        },
%    },
%}
\begin{document}
\begin{tikzpicture}[
%    % in this case this statement is not needed
%    baseline=(current bounding box.center),
]
    \begin{axis}[
        axis lines=middle,
        xtick={-1,0,1},
%        % you don't need this, because the tick labels are identical to the ticks
%        xticklabels={-1, 0, 1},
%        % there are no `extra x ticks` so you don't need this as well
%        extra x tick style={
%            xticklabel style={yshift=0.5ex, anchor=south},
%        },
        xmin=-4,
        xmax=4,
        ytick={\empty},
%        % since you don't state `ytick's you don't to provide corresponding labels ...
%        yticklabels={},
        ymin=-2, ymax=2,
        axis on top,
        enlarge y limits=0.35,
        width=6cm,
        xlabel={$n$},
        ylabel={$x[n]$},
        x label style={anchor=north},
        y label style={anchor=west},
    ]
        \addplot+ [ycomb,black,thick] coordinates {
            (-1,1) (0,2) (1,1)
        };
        \node [anchor=south west] at (axis cs:0,2)  {$2$};
        % ---------------------------------------------------------------------
        % as stated earlier there are plenty of ways to achieve what you want
        % to do, here are some possibilities
        %
        % 1. provide what you need directly to the node
        \node [
            anchor=south east,
            font=\tiny,
            red,
        ] at (axis cs:-1,1) {$1$};
        % 2. apply the created style directly to the node
        \node [
            anchor=south west,
            Label,
        ] at (axis cs:1,1)  {$1$};
    \end{axis}
\end{tikzpicture}

\begin{tikzpicture}[
%    baseline=(current bounding box.center),
]
        \pgfplotsset{
            every tick label/.append style={font=\tiny},
%            % this style is a TikZ style for "labels of nodes" and not nodes that are labels,
%            % that is why you don't see any changing font sizes
%            % said that, it is also not needed here
%            every label/.append style={font=\tiny},
        }
    \begin{axis}[
        axis lines=middle,
        xtick={-3,-2,...,3},
        % as you can see the zero isn't shown, although you stated it here
        % this is because of the key `hide obscured x ticks' which is true by default when
        % `axis lines' are set to `middle' or the alias `center'
        xticklabels={{}, {}, {}, 0, 1, 2, 3},
        % also this is strange. You state the ticks at positions -2 and -1, ...
        extra x ticks={-2,-1},
        % ... but apply the numbers -3 and -2 to them. Is that intended?
        extra x tick labels={$-3$,$-2$,$-1$},
        extra x tick style={
            xticklabel style={yshift=0.5ex,anchor=south}, },
        xmin=-4, xmax=4,
        ytick={\empty},
        yticklabels={},
        ymin=-2, ymax=2,
        axis on top,
        enlarge y limits=0.35,
        width=6cm,
        xlabel={$n$},
        ylabel={$y[n]$},
        x label style={anchor=north},
        y label style={anchor=west},
    ]
        \addplot+ [ycomb,black,thick] plot coordinates
            {(-3,0) (-2,-1) (-1,-2) (0,0) (1,2) (2,1) (3,0)
        };
        % ---------------------------------------------------------------------
        % 3. but you could also scope the nodes and apply the style of the
        %    nodes
        \begin{scope}[
            font=\tiny,
            red,
        ]
            \node [anchor=north] at (axis cs:-2,-1) {$-1$};
            \node [anchor=north] at (axis cs:-1,-2) {$-2$};
        \end{scope}
        % 3. or of course apply the style in the scope
        \begin{scope}[
            Label,
        ]
            \node [anchor=west]  at (axis cs:1,2)   {$2$};
            \node [anchor=west]  at (axis cs:2,1)   {$1$};
        \end{scope}
        % ---------------------------------------------------------------------
    \end{axis}
\end{tikzpicture}
\end{document}

Bild, das das Ergebnis des obigen Codes zeigt

verwandte Informationen