0

A figure of a cube (or a 3D plot), along with an external image, is shown below (and its code is here). I'm trying to use dashed lines instead of solid lines in this figure. I have checked these links, link2, link3, and link4, but I need help to solve this problem.

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{3d,calc}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
enlargelimits=false,
axis on top,
axis equal image,
xmin=0,xmax=4,
ymin=-1,ymax=1,
zmin=-1,zmax=1,
ylabel=$X$,zlabel=$Y$, %xlabel=$Z$,
view={-20}{30},
xtick={0, 4},
ticks = none,
clip = false,
]

\draw [black,dashed] 
(axis cs:?) -- (axis cs:?)  % ???
(axis cs:?) -- (axis cs:?);

\path (axis cs:0,0,0) coordinate (O) (axis cs:1,0,0) coordinate (X)  
(axis cs:0,1,0) coordinate (Y) (axis cs:0,0,1) coordinate (Z)
 (axis cs:4,0,0) coordinate (P)  
 [x={($(O)-(X)$)},y={($(O)-(Y)$)},z={($(Z)-(O)$)},
    canvas is yz plane at x=0,transform shape]
   (P) node{\includegraphics[width=2cm,height=2cm]{example-image-duck}};


\path (axis cs:0,0,0) coordinate (O) (axis cs:1,0,0) coordinate (X)  
(axis cs:0,1,0) coordinate (Y) (axis cs:0,0,1) coordinate (Z)
 (axis cs:0,0,0) coordinate (P)  
 [x={($(O)-(X)$)},y={($(O)-(Y)$)},z={($(Z)-(O)$)},
    canvas is yz plane at x=0,transform shape]
   (P) node{\includegraphics[width=2cm,height=2cm]{example-image-duck}};


%\draw[black, <->] ([xshift =-0.09cm] axis description cs:0, 0.2) -- node[left] {} ([xshift =-0.1cm] axis description cs:0, 0.66) node[font=\scriptsize, midway, left=-1mm] {\fontsize{6.5}{6.5}\selectfont$y$};
%\draw[black, <->] ([xshift =-.14cm] axis description cs:0.01, 0.19) -- node[left] {} ([xshift =-.39cm] axis description cs:0.35,- 0.01)node[font=\scriptsize, midway,below] {\fontsize{6.5}{6.5}\selectfont$x$};

\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

1
  • Please include code for your minimal example here. Aside from anything else, you haven't said which code you're using from the link you gave. Could you explain about the cube? The linked question and answers concern plots, so there are axes etc. and that's what you seem to show as well. Is this a plot? Which cube are you talking about? (Or cuboid??) In general, you can just add dashed to the \draw commands to get dashed lines.
    – cfr
    Commented Dec 25, 2023 at 3:40

1 Answer 1

1

I'm not really clear what you're trying to do or how whatever you've tried hasn't worked, but maybe something like this ...

dashed lines before and behind duck

There are zero cubes in this answer, though.

\documentclass{standalone}
% ateb: https://tex.stackexchange.com/a/705675/ addaswyd o ateb user194703: https://tex.stackexchange.com/a/516994/
\usepackage{pgfplots}
\usetikzlibrary{3d,calc}
\begin{document}
\pgfplotsset{%
  every axis/.append style={%
    draw=lightgray
  },
}%
\begin{tikzpicture}
  \begin{axis}[
      enlargelimits=false,
      axis equal image,
      xmin=0,xmax=4,
      ymin=-1,ymax=1,
      zmin=-1,zmax=1,
      xlabel=$x$,ylabel=$y$,zlabel=$z$,
      view={-20}{30},
      xtick={0, 3},
    ]
    \draw [red,dashed] 
      (axis cs:0,1,1) -- (axis cs:4,1,1) 
      (axis cs:0,1,-1) -- (axis cs:4,1,-1);
    \path (axis cs:0,0,0) coordinate (O) (axis cs:1,0,0) coordinate (X)  
    (axis cs:0,1,0) coordinate (Y) (axis cs:0,0,1) coordinate (Z)
    (axis cs:3,0,0) coordinate (P)  
    [x={($(X)-(O)$)},y={($(Y)-(O)$)},z={($(Z)-(O)$)},
    canvas is yz plane at x=0,transform shape]
    (P) node{\includegraphics[width=2cm,height=2cm]{example-image-duck}};
    \draw [red,densely dashed] 
      (axis cs:0,-1,1) -- (axis cs:4,-1,1) 
      (axis cs:0,-1,-1) -- (axis cs:4,-1,-1);
  \end{axis}
\end{tikzpicture}
\end{document}
2
  • Thanks. I have edited my question and inserted its related code. I used draw without \pgfplotsset{% every axis/.append style={% draw=lightgray } . Also, I had a problem with the setting of cs().
    – Ellie
    Commented Dec 25, 2023 at 6:08
  • @Ellie You should be able to adapt the above either way. The main thing is to split the lines so you get the back ones behind the picture and the others in front.
    – cfr
    Commented Dec 25, 2023 at 12:54

You must log in to answer this question.

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