Wed, 06 Nov 2024 21:12:14 -0500
Improve TikZ
21 | 1 | \documentclass[tikz]{standalone} |
2 | \usepackage{pgfplots} | |
3 | \usepackage{tikz-3dplot} | |
4 | \usepgfplotslibrary{colorbrewer} | |
5 | ||
6 | \def\datapath{../res/} | |
7 | ||
8 | \begin{document} | |
9 | ||
10 | \tdplotsetmaincoords{50}{25} | |
11 | ||
12 | \def\onlyfront#1{ | |
13 | \ifnum#1=2\else\ifnum#1=4\else\ifnum#1=6\else | |
14 | \def\pgfmathresult{} | |
15 | \fi\fi\fi} | |
16 | ||
17 | \def\onlyback#1{ | |
18 | \ifnum#1=1\else\ifnum#1=3\else\ifnum#1=5\else | |
19 | \def\pgfmathresult{} | |
20 | \fi\fi\fi} | |
21 | ||
22 | \pgfplotsset{ | |
23 | % forget plot = no legend | |
24 | cube/.style = {thick, gray!50!black,forget plot}, | |
25 | iter/.style = {mark=x, red}, | |
26 | data/.style = {mark=*, blue, only marks}, | |
27 | backdata/.style = {mark=*, blue!30!white, only marks, onlyback, forget plot}, | |
28 | backiter/.style = {mark=x, red!30!white, onlyback, forget plot}, | |
29 | origin/.style = {mark=o, green, only marks, thick}, | |
30 | surfstyle/.style = {very nearly opaque, forget plot}, | |
31 | onlyfront/.code = \pgfplotsset{x filter/.code={\onlyfront{\thisrow{face}}}}, | |
32 | onlyback/.code = \pgfplotsset{x filter/.code={\onlyback{\thisrow{face}}}}, | |
33 | legend style = { | |
34 | inner sep = 0pt, | |
35 | outer xsep = 5pt, | |
36 | outer ysep = 0pt, | |
37 | legend cell align = left, | |
38 | align = left, | |
39 | draw = none, | |
40 | fill = none, | |
41 | font = \small | |
42 | }, | |
23 | 43 | illustr3d/.style = { |
44 | axis equal, | |
45 | width=5cm, | |
46 | height=5cm, | |
47 | scale only axis, | |
48 | enlargelimits=false, | |
21 | 49 | colormap access=map, |
23 | 50 | colormap/Blues, |
21 | 51 | colorbar, |
52 | point meta rel=axis wide, | |
53 | shader = interp, | |
54 | xlabel = {$x$}, | |
55 | ylabel = {$y$}, | |
56 | zlabel = {$z$}, | |
57 | ticks = none, | |
58 | axis line style = {draw=none}, | |
59 | %axis x line = none, | |
60 | %axis y line = none, | |
61 | %axis z line = none, | |
62 | legend columns = 3, | |
63 | legend style = { | |
64 | at = {(0.5, 1.05)}, | |
65 | anchor = north, | |
66 | column sep = 1ex, | |
67 | }, | |
23 | 68 | } |
69 | } | |
21 | 70 | |
23 | 71 | \begin{tikzpicture} |
72 | \begin{axis}[illustr3d] | |
21 | 73 | \addplot3[cube] coordinates {(0, 0, 0) (0, 1, 0) (0, 1, 1) }; |
74 | \addplot3[cube] coordinates {(0, 1, 0) (1, 1, 0) }; | |
75 | \addplot3[backdata] table[x=x,y=y,z=z] {\datapath/data.csv}; | |
76 | \addplot3[backiter] table[x=x,y=y,z=z] {\datapath/log.txt}; | |
77 | ||
78 | \addplot3[ | |
79 | surf, | |
80 | mesh/ordering=x varies, | |
81 | mesh/cols=32, | |
82 | mesh/rows=32, | |
83 | surfstyle, | |
84 | ] table [ | |
85 | x = u, | |
86 | z = v, | |
87 | y expr = 0.0, | |
88 | point meta = \thisrow{value}, | |
89 | ] {\datapath/F4.csv}; | |
90 | \addplot3[ | |
91 | surf, | |
92 | mesh/ordering=y varies, | |
93 | mesh/cols=32, | |
94 | mesh/rows=32, | |
95 | surfstyle, | |
96 | ] table [ | |
97 | x expr = 1.0, | |
98 | y = u, | |
99 | z = v, | |
100 | point meta = \thisrow{value}, | |
101 | ] {\datapath/F2.csv}; | |
102 | \addplot3[ | |
103 | surf, | |
104 | mesh/ordering=x varies, | |
105 | mesh/cols=32, | |
106 | mesh/rows=32, | |
107 | surfstyle, | |
108 | ] table [ | |
109 | x = u, | |
110 | y = v, | |
111 | z expr = 1.0, | |
112 | point meta = \thisrow{value}, | |
113 | ] {\datapath/F6.csv}; | |
114 | ||
115 | % Edges | |
116 | \addplot3[cube] coordinates {(0, 0, 0) (1, 0, 0) (1, 0, 1) (0, 0, 1) (0, 0, 0)}; | |
117 | \addplot3[cube] coordinates {(0, 0, 1) (0, 1, 1) (1, 1, 1) (1, 0, 1)}; | |
118 | \addplot3[cube] coordinates {(1, 0, 0) (1, 1, 0) (1, 1, 1)}; | |
119 | ||
120 | \addplot3[data,onlyfront] table[x=x,y=y,z=z] {\datapath/data.csv}; | |
121 | \addlegendentry{Data} | |
122 | ||
123 | \addplot3[origin,onlyfront] table[x=x,y=y,z=z] {\datapath/origin.csv}; | |
124 | \addlegendentry{Origin} | |
125 | ||
126 | \addplot3[iter,onlyfront] table[x=x,y=y,z=z] {\datapath/log.txt}; | |
127 | \addlegendentry{Iterates} | |
128 | \end{axis} | |
129 | \end{tikzpicture} | |
130 | ||
131 | \end{document} |