我在使用 TikZ 将极坐标数据文件正确绘制成极坐标图时遇到了麻烦,代码如下。提前感谢帮助(我宁愿避免使用 \begin{axis},以便与所有文档图保持一致)。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{tikzpicture}[x=.11cm,y=0.11cm]
% %Circles
\foreach \r in {0, 3,...,42}
\draw[black!20, thick] (0,0) circle (\r);
%Circles
\foreach \r in {0, 6,...,42}
\draw[black!40, thick] (0,0) circle (\r);
%5° Rays
\foreach \a in {0, 5,...,359}
\draw[black!20] (\a:41.5) -- (\a:42);
\foreach \a in {0, 15,...,359}
\draw[black!20] (\a:0) -- (\a:42);
%Main rays
\foreach \a in {0, 90,...,359}
\draw[black!50, thick] (0, 0) -- (\a:42);
%Angle labels
\foreach \a in {0, 15,...,359}
\draw (\a: 45) node {$\a^\circ$};
\draw[color=blue, domain=0:360, line width=1.5pt] plot[smooth] file {data.dat};
\end{tikzpicture}
%\caption
\end{figure}
\end{document}
数据文件包括:
%data.dat
0 7.820634
1 8.381467
2 9.090974
3 9.877479
4 10.68895
5 11.49293
6 12.27133
7 13.0153
8 13.72148
9 14.38954
10 15.0208
11 15.61735
12 16.18157
13 16.71593
14 17.22276
15 17.70429
16 18.16255
17 18.59938
18 19.01647
19 19.4153
20 19.79726
21 20.16356
22 20.5153
23 20.85347
24 21.17899
25 21.49264
26 21.79518
27 22.08727
28 22.36951
29 22.64245
30 22.9066
31 23.16241
32 23.4103
33 23.65067
34 23.88385
35 24.11017
36 24.32993
37 24.5434
38 24.75084
39 24.95247
40 25.14851
41 25.33916
42 25.5246
43 25.70499
44 25.8805
45 26.05127
46 26.21743
47 26.37911
48 26.53643
49 26.68948
50 26.83834
答案1
您可以使用非线性变换从文件生成极坐标图。代码如下:
\documentclass[tikz]{standalone}
\usepgfmodule{nonlineartransformations}
\usepackage{datatool}
\begin{filecontents}{data.dat}
0 7.820634
1 8.381467
2 9.090974
3 9.877479
4 10.68895
5 11.49293
6 12.27133
7 13.0153
8 13.72148
9 14.38954
10 15.0208
11 15.61735
12 16.18157
13 16.71593
14 17.22276
15 17.70429
16 18.16255
17 18.59938
18 19.01647
19 19.4153
20 19.79726
21 20.16356
22 20.5153
23 20.85347
24 21.17899
25 21.49264
26 21.79518
27 22.08727
28 22.36951
29 22.64245
30 22.9066
31 23.16241
32 23.4103
33 23.65067
34 23.88385
35 24.11017
36 24.32993
37 24.5434
38 24.75084
39 24.95247
40 25.14851
41 25.33916
42 25.5246
43 25.70499
44 25.8805
45 26.05127
46 26.21743
47 26.37911
48 26.53643
49 26.68948
50 26.83834
\end{filecontents}
\makeatletter
\def\polartransformation{% from the manual 103.4.2 Installing Nonlinear Transformation
\pgfmathsincos@{\pgf@x}
\pgf@x=\pgfmathresultx\pgf@y%
\pgf@y=\pgfmathresulty\pgf@y%
}
\makeatother
\begin{document}
\begin{tikzpicture}[x=.11cm,y=0.11cm, main1/.style = {black}]
% Circles
\foreach[count=\i, evaluate={\j=20*(1+mod(\i,2));}, ] \r in {0, 3,...,42}
\draw[black!\j, thick] (0,0) circle (\r);
% Rays and labels
\foreach[evaluate={\i=mod(\a,15)>0;\j=\i*41.5;\k=mod(\a,90)==0;\l=\i?"":"$\a^\circ$";}] \a in {0, 5,...,359}
\draw[black!20,main\k/.try] (\a:\j) -- (\a:42) node[black,label={[black]\a:\l}]{};
\pgftransformnonlinear{\polartransformation}
\draw[x=1pt, color=blue, line width=1.5pt] plot[smooth] file {data.dat};
\end{tikzpicture}
\end{document}
笔记:foreach
我已将轴图中的数量减少到 2。
编辑:按照@mark 的评论,我添加了x=1pt
以避免polartransformation
转换错误。\polartransformation
对所有先前的转换都很敏感。例如,如果您添加xscale=.5
所有角度,则将除以 2。此处x=.11 cm
使用的,应重置。