0

I'm trying to create a figure in which I plot a mesh. Each 'rectangle' of the mesh should be labelled with a number that has a circle around it. My goal is to rotate this number and circle (or just the circle) so that it lies on the rectangle.

As I have very few mesh rectangles, I am happy to specify the rotation/position of each label individually.

Below is my first attempt, inspired by another stackoverflow post. It's based on the fact that it's possible to specify coordinates that are used to determine the radius of the circle: to draw a circle in the xz plane, for instance, I'd write circle[x={(1,0,0)}, y={(0,0,1)}, x radius=1,y radius=1];. But in my case, this doesn't seem to work and I have to guess/fudge the vectors and/or radius and am left with something that's not quite right.

What am I missing? Here's the output of the current code.

Current figure.

\tikzset{label/.style={draw=gray, fill=white, circle, minimum size=0pt, inner sep=2pt, outer sep=0pt, font=\large}}

\begin{tikzpicture}
    \begin{axis}[
    view = {-18}{30},
    axis lines = center,
    axis on top,
    axis line style = {thick, black},
    xmin=0, xmax=20,
    ymin=0, ymax=20,
    zmin=0, zmax=20,
    ticks=none,
    ]
        \addplot3[surf, red, opacity=0.7] coordinates {
        (6.0, 6.0, 0.0) (6.0, 20.0, 0.0)
        
        (6.0, 6.0, 20.0) (6.0, 20.0, 20.0)
        };
        \addplot3[mesh, surf, green, opacity=0.7] coordinates {
        (6.0, 6.0, 0.0) (20.0, 6.0, 0.0)
        
        (6.0, 6.0, 20.0) (20.0, 6.0, 20.0)
        };
        \addplot3[surf, yellow, opacity=0.7] coordinates {
        (6.0, 6.0, 0.0) (6.0, 6.0, 20.0)
        
        (0.0, 0.0, 0.0) (0.0, 0.0, 20.0)
        };

        % labels
        \node[label] at (5,12,18) {$1$};
        % \node[label] at (13,6,10) {$2$};
        % \node[label] at (3,3,10) {$3$};

        % attempt at rotated labels
        \draw[thick, fill=white] (13,6,10) circle[x={(1,0,0)}, y={(0,0,16)}, x radius=.1,y radius=.1]; (1);
        \node[] at (13,6,10) {$2$};
        
        \draw[thick, fill=white] (3,3,10) circle[x={(1,1,0)}, y={(0,0,18)}, x radius=.1,y radius=.1]; (1);
        \node[] at (3,3,10) {$3$};
    \end{axis}
\end{tikzpicture}
grapher
  • 43
  • 4
  • To make things even more confusing, whenever I change xmin, ymin and zmin to something negative, the circles get distorted further. – grapher Feb 18 '23 at 10:33

1 Answers1

0

I've found a solution. (The key was reading the pgfplots manual carefully.) The problem was that pgfplots uses its own 3d coordinate system that is translated under the hood to a 'basic' 2d tikz coordinate system. And the draw circle command interprets the x and y direction coordinates in the basic coordinate system.

For me, the solution was to use pgfplot's ellipse drawing command, and to use its functions for converting between the two coordinate systems as follows. The code is a bit verbose, but it works.

\draw [red, fill=white] \pgfextra{
    \pgfpathellipse{\pgfplotspointaxisxyz{5}{12}{18}}
    {\pgfplotspointaxisdirectionxyz{0}{3}{0}}
    {\pgfplotspointaxisdirectionxyz{0}{0}{3}}
    };
\node[] at (5,12,18) {$1$};

Here's what the final plot looks like with circles embedded in the planes.

Final outcome

grapher
  • 43
  • 4