2

Base on the bellow figure, I want to change color of two face. How it is possible.Both side are the same (just I cant plot correctly one of them). enter image description here

\documentclass[border=10pt,tikz,multi]{standalone}
\tikzset{%
  yzx/.style = {%
    x={(-.385cm, -.385cm)},
    y={(1cm, 0cm)},
    z={(0cm, 1cm)},
  },
}
\begin{document}
\begin{tikzpicture}[yzx, scale=2.5]
  ‎\filldraw[ fill=gray!30,looseness=1](0,0,0.2)--(2,0,0.2)--(2,2,0.2)-- (0,2,0.2)--cycle;
  ‎‎\filldraw[ fill=gray!30,looseness=1] (0,2,0.2)--(2,2,0.2)--(2,2,-0.2)-- (0,2,-0.2)--cycle;
  ‎‎\filldraw[ fill=gray!30,looseness=1] (2,0,0.2)--(2,2,0.2)--(2,2,-0.2)-- (2,0,-0.2)--cycle;
‎‎\end{tikzpicture}
\end{document}
2
  • I don't really understand your question or why you are loading tikz-3dplot but not using it. If you can shade the one side, as shown, why isn't that in your code? And if that's not what you mean, what do you mean that you can plot? \tikzstyle is deprecated, by the way.
    – cfr
    Apr 20 '16 at 23:25
  • You have many weird invisible characters in the code you've posted. Please check your code compiles before posting and be sure that you paste it cleanly.
    – cfr
    Apr 20 '16 at 23:30
1

This isn't probably quite what you want but an approximation. To get what you want, you probably need to read the TikZ manual discussion of shadings in the PGF layer in order to define a custom shading which will come out correctly when rotated. This will need to take account of the fact that non-rectangular shapes end up with a smaller part of the shading than rectangular ones, and that even rectangular ones only use the centre of the defined shading.

\documentclass[border=10pt,tikz,multi]{standalone}
\tikzset{%
  yzx/.style = {%
    x={(-.385cm, -.385cm)},
    y={(1cm, 0cm)},
    z={(0cm, 1cm)},
  },
}
\begin{document}
\begin{tikzpicture}[yzx, scale=2.5]
  ‎\filldraw[fill=gray](0,0,0.2)--(2,0,0.2)--(2,2,0.2)-- (0,2,0.2)--cycle;
  ‎‎\filldraw[top color=blue, bottom color=red] (2,0,0.2)--(2,2,0.2)--(2,2,-0.2)-- (2,0,-0.2)--cycle;
  \pgfsetadditionalshadetransform{\pgftransformscale{.7}}
‎‎  ‎‎\filldraw[top color=blue, bottom color=red, shading angle=30] (0,2,0.2)--(2,2,0.2)--(2,2,-0.2)-- (0,2,-0.2)--cycle;
\end{tikzpicture}
\end{document}

approximate shading

That is, TikZ/PGF does not make shading things (or fading them) at all easy. There is no straightforward way of defining or manipulating shadings for shapes which are neither rectangles nor circles. It is true that the set-up ensures that rotated radial shadings are not distorted, but the results in other cases are far from intuitive. (And it is not at all clear to me why the manual claims that they will generally produce the results you'd want or expect. In my case, at least, nothing could be further from the truth. But perhaps I simply have a contrary mind.)

TikZ/PGF is an incredibly impressive achievement given the raw materials available. But shadings are no more among its strengths than is speed.

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.