4

I ask this question more to have suggestions than to solve a real problem.

When I have to plot data I use pgfplots. On the other hand, in order to keep the code smaller, I use tikz in other situations, e.g. when I have to make grids like the one coded in following non-MWE

\begin{tikzpicture}
    \foreach \x in {0,1,...,5}
    \foreach \y in {0,1,...,5}
    \draw plot[only marks,mark=o] coordinates{(\x,\y)};
\end{tikzpicture}

Such a basic tikzpicture (which would get "fat" adding \begin{axis} and other stuff like that) could be even slimmer substituting the fourth line by \node at (\x,\y) {$\circ$}; (I know the result is a little bit different), that is

\begin{tikzpicture}
    \foreach \x in {0,1,...,5}
    \foreach \y in {0,1,...,5}
    \node at (\x,\y) {$\circ$};
\end{tikzpicture}

Whichever the code chosen, it has to be put in a figure, whose caption could be required to refer to a specific marker of the tikzpicture (if more than one are present). Obviously it's easy to refer to $\circ$ in the text. Furthermore I would prefer to use symbols like $\circ$, $\bullet$ and similia, since they're constant in size when the tikzpicture is made bigger or smaller. On the other hand, markers can be easily changed in color, shape and can be filled, rotated and so on. So the question arises: is it easy to refer to a mark of a plot operation in \draw? And how to do it the best way?

Thank you in advice for suggestions

EDIT: I don't need an actual reference since I know that I will reference this symbols only once, just in the caption below the figure. For this reason, to "reference" a $\circ$, I simply write $\circ$ in the caption. The point is: if I use \draw plot[only marks,mark=o] coordinates{(\x,\y)};, how can I easily (if it is possible) reproduce manually the marker in the text outside the tikzpicture? (Maybe it's worth to mention that I don't want to use ref/label to plots in order to avoid externalization problems)

EDIT 2: The picture I typeset at the moment is the following. enter image description here

and it is coded as follows

\begin{tikzpicture}
    \draw (-.25,-.25) grid (5.25,5.25);
    \foreach \x in {0,1,...,5}
    \foreach \y in {.5,1.5,...,5}
    \node at (\x,\y) {\tiny$\blacktriangleright$};

    \foreach \x in {.5,1.5,...,5}
    \foreach \y in {0,1,...,5}
    \node[rotate=90] at (\x,\y) {\tiny$\blacktriangleright$};

    \foreach \x in {.5,1.5,...,5}
    \foreach \y in {.5,1.5,...,5}
    \node at (\x,\y) {$\circ$};

    \node[rotate=0] at (2.5,5.5) {\raisebox{1pt}{\tiny$\blacktriangleright$} $u$ \hspace{.5cm} \rotatebox{90}{\raisebox{1pt}{\tiny$\blacktriangleright$}} $v$ \hspace{.5cm} $\circ$ $p$};

\end{tikzpicture}

where I used a handmade legend.

  • Doing so I both handle the picture without pgfplots (I don't need so much power) and avoid using actual \ref/\labels that I'm not able to handle in conjunction with externalization.
  • The drawback in using symbols is that I can not customize them: they're many, but markers are virtually in infinite number (e.g. $\bullet$ is not properly the filled version of $\circ$, as it happens for mark=* and mark=o; symbols are one-color, whereas markers can be two-colors; and so on).

This is why I was thinking about \draw plot[only marks,mark=o] coordinates{(\x,\y)};...

Hope to have set the question.

  • 1
    You want to refer to it like, The node \ref{name} is...? Because in that case, I'd suggest using pgfplots. – Alenanno Jan 4 '16 at 13:32
  • No, no. Figurures like that have not to be explained more than once (in the caption), so there's no need to create references. Just to use the same symbol in both the figure and the caption. – Enrico Maria De Angelis Jan 4 '16 at 13:36
  • How do you mean referring? – percusse Jan 4 '16 at 13:37
  • If I used $\circ$, then I would use \caption{The symbol $\circ$ indicates the points where bla bla bla.} in the figure environment. – Enrico Maria De Angelis Jan 4 '16 at 13:42
  • @EnricoMariaDeAngelis \caption{The symbol $\circ$ ... can't work because Latex wouldn't know what you're referencing. Unless you want it to be manual, like this example. – Alenanno Jan 4 '16 at 13:50
2

Markers are small fragments of low level TikZ drawings. So you can refer to them via PGF notation.

\documentclass[]{article}
\usepackage{tikz,amssymb}
\usetikzlibrary{plotmarks}
\def\myplotmark#1{%
  \begin{pgfpicture}\pgfuseplotmark{#1}\end{pgfpicture}%
}

\begin{document}

\begin{figure}%
\centering
\begin{tikzpicture}
    \draw (-.25,-.25) grid (5.25,5.25);
    \foreach \x in {0,1,...,5}
    \foreach \y in {.5,1.5,...,5}
%    \node at (\x,\y) {\tiny$\blacktriangleright$};
    \draw plot[only marks,mark=triangle*,mark options={rotate=-90}] coordinates{(\x,\y)};


    \foreach \x in {.5,1.5,...,5}
    \foreach \y in {0,1,...,5}
%    \node[rotate=90] at (\x,\y) {\tiny$\blacktriangleright$};
    \draw plot[only marks,mark=triangle*] coordinates{(\x,\y)};

    \foreach \x in {.5,1.5,...,5}
    \foreach \y in {.5,1.5,...,5}
%    \node at (\x,\y) {$\circ$};
    \draw plot[only marks,mark=o] coordinates{(\x,\y)};

%    \node[rotate=0] at (2.5,5.5) {\raisebox{1pt}{\tiny$\blacktriangleright$} 
%        $u$ \hspace{.5cm} \rotatebox{90}{\raisebox{1pt}{\tiny$\blacktriangleright$}} 
%        $v$ \hspace{.5cm} $\circ$ $p$};
\end{tikzpicture}
\caption{Here are some markers: 
\protect\myplotmark{triangle*} and 
\protect\myplotmark{triangle*} and 
\protect\myplotmark{o}}
\end{figure}

\end{document}

I don't have access to TeX now so I couldn't test the \protectless version. Please feel free to edit or fix.

  • I edited it just a bit. I think you got the point. Furthermore I see that \myplotmark are not externalized, just as I want. The last point to fix is how to rotate them. As you can see form my editing, the second and third markers in the caption match those in the second and third \draw plots, whereas the first don't, for being not rotated. Where should I add mark options={rotate=-90}? – Enrico Maria De Angelis Jan 5 '16 at 9:14
  • I don't know what you mean by externalised but you can enhance the macro with an additional argument that goes into \tikzset{} before the \pgfuseplotmark. But you are reinventing the wheel. pgfplots does this right off the bat including line types, width and many more. – percusse Jan 5 '16 at 9:19
  • (About the externalization I simply mean this: if markers are low level TikZ drawings I would expect them to be externalized if externalization is enabled, but they don't. Nothing more.) Maybe you're right about the wheel.. Maybe I should simply use pgfplots. It simply sounds so strange to me to use it to make sketches. Pgfplots is meant to be used to plot functions, not to draw sketches, isn't it? – Enrico Maria De Angelis Jan 5 '16 at 9:59
  • Use tikzpicture environment and they will be externalised as tiny PDF files. It requires slightly more work for pgfpicture to externalise – percusse Jan 5 '16 at 10:02
  • No, no. As I wrote it's "just as I want". – Enrico Maria De Angelis Jan 5 '16 at 10:13

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.