我正在尝试根据连接到 Arduino 的摆锤上安装的陀螺仪获得的值制作图表。我无法使颜色图/渐变工作。
原始图表:
这是我正在使用的代码:
\begin{figure}[hbt!]
\begin{tikzpicture}
\begin{axis}[
width=\textwidth,
height=8cm,
axis lines = left,
xlabel={x axis},
ylabel={Time [ms]},
zlabel={y axis},
minor x tick num=4,
minor y tick num=4,
xmajorgrids=true,
ymajorgrids=true,
grid style=dashed,
view={150}{170},
]
\addplot3[color=red, mark=square, mark size=0pt]
file {x_y_z_2.txt};
\end{axis}
\end{tikzpicture}
\caption{Graph of values from gyroscope}
\label{exponential_decay_graph_speed}
\end{figure}
前 100 个值如下x_y_z_2.txt
:
x y z
0.33 0 9.69
0.33 14 9.68
0.35 27 9.67
0.36 41 9.67
0.37 54 9.66
0.37 67 9.62
0.38 81 9.61
0.39 94 9.6
0.39 108 9.56
0.4 121 9.56
0.41 135 9.54
0.41 148 9.55
0.43 162 9.54
0.43 176 9.54
0.43 189 9.54
0.43 202 9.52
0.43 216 9.54
0.43 229 9.52
0.44 243 9.54
0.42 256 9.54
0.42 270 9.56
0.4 283 9.56
0.39 297 9.59
0.38 310 9.6
0.36 323 9.62
0.35 337 9.63
0.32 350 9.64
0.32 364 9.67
0.32 377 9.67
0.31 391 9.71
0.28 404 9.71
0.28 418 9.7
0.27 431 9.7
0.26 444 9.71
0.24 458 9.71
0.22 471 9.72
0.21 485 9.7
0.18 498 9.7
0.17 512 9.7
0.17 525 9.69
0.17 539 9.68
0.13 552 9.67
0.15 566 9.64
0.14 579 9.63
0.14 592 9.61
0.12 606 9.62
0.12 619 9.59
0.11 633 9.58
0.1 646 9.56
0.11 660 9.56
0.11 673 9.56
0.08 687 9.57
0.08 700 9.58
0.08 714 9.55
0.08 727 9.56
0.09 741 9.57
0.07 754 9.57
0.08 768 9.58
0.1 781 9.6
0.11 795 9.61
0.12 808 9.61
0.13 821 9.65
0.15 835 9.64
0.17 848 9.67
0.17 862 9.66
0.2 875 9.7
0.2 889 9.72
0.18 902 9.7
0.19 916 9.71
0.23 929 9.72
0.24 943 9.73
0.26 956 9.72
0.28 969 9.71
0.28 983 9.7
0.3 996 9.68
0.33 1010 9.68
0.35 1023 9.67
0.36 1037 9.67
0.37 1050 9.66
0.37 1064 9.64
0.39 1077 9.63
0.38 1090 9.61
0.38 1104 9.58
0.41 1117 9.57
0.4 1131 9.55
0.41 1144 9.54
0.42 1158 9.53
0.43 1171 9.52
0.42 1185 9.52
0.42 1198 9.52
0.43 1211 9.53
0.43 1225 9.53
0.45 1239 9.53
0.44 1252 9.54
0.4 1266 9.55
0.4 1279 9.59
0.38 1293 9.6
0.35 1306 9.6
0.34 1320 9.6
由于某种原因,我也Package PGF Math Error: Could not parse input 'z' as a floating point number, sorry. The unreadable part was near 'z'..
在线上遇到了错误file {x_y_z_2.txt};
答案1
\begin{filecontents*}{tmp.txt}
x y z
0.33 0 9.69
0.33 14 9.68
0.35 27 9.67
0.36 41 9.67
0.37 54 9.66
0.37 67 9.62
0.38 81 9.61
0.39 94 9.6
0.39 108 9.56
0.4 121 9.56
0.41 135 9.54
0.41 148 9.55
0.43 162 9.54
0.43 176 9.54
0.43 189 9.54
0.43 202 9.52
0.43 216 9.54
0.43 229 9.52
0.44 243 9.54
0.42 256 9.54
0.42 270 9.56
0.4 283 9.56
0.39 297 9.59
0.38 310 9.6
0.36 323 9.62
0.35 337 9.63
0.32 350 9.64
0.32 364 9.67
0.32 377 9.67
0.31 391 9.71
0.28 404 9.71
0.28 418 9.7
0.27 431 9.7
0.26 444 9.71
0.24 458 9.71
0.22 471 9.72
0.21 485 9.7
0.18 498 9.7
0.17 512 9.7
0.17 525 9.69
0.17 539 9.68
0.13 552 9.67
0.15 566 9.64
0.14 579 9.63
0.14 592 9.61
0.12 606 9.62
0.12 619 9.59
0.11 633 9.58
0.1 646 9.56
0.11 660 9.56
0.11 673 9.56
0.08 687 9.57
0.08 700 9.58
0.08 714 9.55
0.08 727 9.56
0.09 741 9.57
0.07 754 9.57
0.08 768 9.58
0.1 781 9.6
0.11 795 9.61
0.12 808 9.61
0.13 821 9.65
0.15 835 9.64
0.17 848 9.67
0.17 862 9.66
0.2 875 9.7
0.2 889 9.72
0.18 902 9.7
0.19 916 9.71
0.23 929 9.72
0.24 943 9.73
0.26 956 9.72
0.28 969 9.71
0.28 983 9.7
0.3 996 9.68
0.33 1010 9.68
0.35 1023 9.67
0.36 1037 9.67
0.37 1050 9.66
0.37 1064 9.64
0.39 1077 9.63
0.38 1090 9.61
0.38 1104 9.58
0.41 1117 9.57
0.4 1131 9.55
0.41 1144 9.54
0.42 1158 9.53
0.43 1171 9.52
0.42 1185 9.52
0.42 1198 9.52
0.43 1211 9.53
0.43 1225 9.53
0.45 1239 9.53
0.44 1252 9.54
0.4 1266 9.55
0.4 1279 9.59
0.38 1293 9.6
0.35 1306 9.6
0.34 1320 9.6
\end{filecontents*}
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={150}{170},
width=\textwidth, height=8cm,
axis lines=left,
xlabel={x axis}, ylabel={Time [ms]}, zlabel={y axis},
minor x tick num=4, minor y tick num=4,
xmajorgrids=true, ymajorgrids=true,
grid style=dashed,
]
\addplot3[mesh] table {tmp.txt};
\end{axis}
\end{tikzpicture}
\end{document}
编辑:
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
colormap name=viridis,
view={150}{170},
width=\textwidth, height=8cm,
axis lines=left,
xlabel={x axis}, ylabel={Time [ms]}, zlabel={y axis},
minor x tick num=4, minor y tick num=4,
xmajorgrids=true, ymajorgrids=true,
grid=major,
grid style=dashed,
]
\addplot3[mesh, point meta=y] table {x_y_z_2.txt};
\end{axis}
\end{tikzpicture}
\end{document}