1

I wish to plot a 3d surface based on its outline coordinates provided in a file data.txt. The following code works as expected.

\usepackage{pgfplots}
\pgfplotsset{compat = newest}    
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[view={0}{160},
            xlabel={$x$},
            ylabel={$y$},
            zlabel={$z$}]
            \addplot3[green, fill] table[x={X}, y={Y} , z={Z}] {data.txt}; 
        \end{axis}
    \end{tikzpicture}
\end{document}

Which results in:

Output

Now I would like to fill with a non-constant color. Specifically, I would like to fill with a gradient where the color is determined by the y value of the data. How can this be achieved?

This is the data.txt file for completeness:

X Y Z
1.0 0.23750000000000004 0
0.9500000000000001 0.23756250000000004 0
0.9 0.23850000000000005 0
0.8500000000000001 0.24256250000000004 0
0.8 0.25350000000000006 0
0.75 0.27656250000000004 0
0.7000000000000001 0.3185 0
0.65 0.38756250000000003 0
0.6000000000000001 0.4934999999999998 0
0.55 0.6475624999999999 0
0.5 0.8625 0
0.45 0.6600000000000001 0
0.4 0.5025000000000001 0
0.35000000000000003 0.39000000000000007 0
0.30000000000000004 0.3225 0
0.25 0.3 0
0.2 0.32249999999999995 0
0.15000000000000002 0.38999999999999996 0
0.1 0.5025 0
0.05 0.6600000000000001 0
0.0 0.8625 0
0.05 0.6600000000000001 0.1
0.1 0.5025 0.2
0.15000000000000002 0.38999999999999996 0.30000000000000004
0.2 0.32249999999999995 0.4
0.25 0.3 0.5
0.30000000000000004 0.3225 0.6000000000000001
0.35000000000000003 0.39000000000000007 0.7000000000000001
0.4 0.5025000000000001 0.8
0.45 0.6600000000000001 0.9
0.5 0.8625 1.0
0.55 0.6475624999999999 0.9000000000000001
0.6000000000000001 0.4934999999999998 0.8
0.65 0.38756250000000003 0.7000000000000002
0.7000000000000001 0.3185 0.6000000000000001
0.75 0.27656250000000004 0.5
0.8 0.25350000000000006 0.40000000000000013
0.8500000000000001 0.24256250000000004 0.30000000000000004
0.9 0.23850000000000005 0.20000000000000018
0.9500000000000001 0.23756250000000004 0.10000000000000009
1.0 0.23750000000000004 0.0
11
  • 1
    Your data only contains the perimeter of the surface, so there is no information on the z-values of internal points. Hence it is impossible to fill it with well-defined colors. Given a complete data set, one can use e.g. surf,shader=interp to color the surface with a gradient. You can then adjust the point meta key to get precisely the shading you want.
    – user294623
    Apr 12, 2023 at 15:21
  • @Displayname Thanks for the response! I don't entirely follow since I am able to fill with a constant color as I would expect, I would just like the fill color to be non-constant. But if there is a better way of achieving this I would really appreciate if the solution you suggest could be converted into an answer (even if on a smaller sample set of points).
    – Seraf Fej
    Apr 12, 2023 at 15:27
  • You fill the perimeter, or more precisely the projection of he perimeter on the screen. If you want to shade the surface one needs the z-values of the points in the interior. If you have a function that parametrizes the surface this would be very easy, otherwise you need to speficy the data in a "matrix" format.
    – user294623
    Apr 12, 2023 at 15:45
  • @Displayname Ah, I think I follow regarding the projection filling. What can I read to understand more about "matrix" format?
    – Seraf Fej
    Apr 12, 2023 at 15:50
  • 1
    It might make sense but you may then rewrite your question accordingly. However, I personally do not think that it is very convenient to implement these prescriptions in pgfplots, you may want to manipulate your data with tools which are really made for this. (I am not saying that it cannot be done with pgfplots, it is just not very convenient.)
    – user294623
    Apr 12, 2023 at 16:57

1 Answer 1

0

You may just want to do the graphics in a better image program, then take a screenshot of the final result and use \includegraphics to put it into your TeX file.

You must log in to answer this question.

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