我创建了以下图片
使用以下代码
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{%
compat=newest,%
/pgf/number format/use comma,%
/pgf/number format/1000 sep={\,},%
/pgf/number format/min exponent for 1000 sep=4}
\begin{document}
\begin{tikzpicture}
\begin{axis}[title={}, xlabel={}, ylabel={}, zlabel={},%
legend cell align=left]
\addplot[red, only marks]
coordinates {(23.0175,1.64554e-15)};
\addplot[brown, only marks]
coordinates {(19.544,12.1362)};
\addplot[orange, only marks]
coordinates {(17.3908, 15.9429)};
\addplot[green, only marks]
coordinates {(16.3344, 18.2596)};
\addplot[lime, only marks]
coordinates {(18.0024, 17.6308)};
\addplot[olive, only marks]
coordinates {(19.9158, 10.8752)};
\addplot[blue, only marks]
coordinates {(19.798, 7.44025)};
\addplot[cyan, only marks]
coordinates {(19.4223, 4.57679)};
\addplot[teal, only marks]
coordinates {( 18.9801, 4.98689e-16)};
\legend{$\gamma = -\frac{\pi}{2}$, $\gamma = -\frac{\pi}{3}$, $\gamma = -\frac{\pi}{4}$, $\gamma = -\frac{\pi}{6}$, $\gamma = 0$, $\gamma = +\frac{\pi}{6}$, $\gamma = +\frac{\pi}{4}$, $\gamma = +\frac{\pi}{3}$, $\gamma = +\frac{\pi}{2}$}
\end{axis}
\end{tikzpicture}
\end{document}
我想用虚线连接所有数据点。如果它们仅代表一个坐标的不同图形,是否可以实现这一点?
答案1
pgfplots
的scatter
选择似乎很有希望(第 4.4.10 节手动的)。
解决方案scatter
注释(我不喜欢的东西)
- 在我看来,每个标记的图例条目只有通过类别才可行。
- 这是非常明确的。
代码
\documentclass[tikz,border=5pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{%
compat=newest,%
/pgf/number format/use comma,%
/pgf/number format/1000 sep={\,},%
/pgf/number format/min exponent for 1000 sep=4}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={},
xlabel={},
ylabel={},
zlabel={},
legend cell align=left,
legend image post style={only marks}
]
\addplot[
smooth,
dotted,
scatter,
every mark/.append style={solid},
scatter src=explicit symbolic,
scatter/classes={
a=red, b=brown, c=orange, d=green, e=lime, f=olive, g=blue, h=cyan, i=teal}
] coordinates {
(23.0175, 1.64554e-15) [a]
(19.544, 12.1362) [b]
(17.3908, 15.9429) [c]
(16.3344, 18.2596) [d]
(18.0024, 17.6308) [e]
(19.9158, 10.8752) [f]
(19.798, 7.44025) [g]
(19.4223, 4.57679) [h]
(18.9801, 4.98689e-16) [i]
};
\legend{$\gamma = -\frac{\pi}{2}$, $\gamma = -\frac{\pi}{3}$, $\gamma = -\frac{\pi}{4}$, $\gamma = -\frac{\pi}{6}$, $\gamma = 0$, $\gamma = +\frac{\pi}{6}$, $\gamma = +\frac{\pi}{4}$, $\gamma = +\frac{\pi}{3}$, $\gamma = +\frac{\pi}{2}$}
\end{axis}
\end{tikzpicture}
\end{document}
输出
来自的(简单)解决方案我的评论
我不喜欢这个解决方案。
代码
\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[title={}, xlabel={}, ylabel={}, zlabel={},legend cell align=left]
\addplot[red, only marks] coordinates {(23.0175,1.64554e-15)};
\addplot[brown, only marks] coordinates {(19.544,12.1362)};
\addplot[orange, only marks] coordinates {(17.3908, 15.9429)};
\addplot[green, only marks] coordinates {(16.3344, 18.2596)};
\addplot[lime, only marks] coordinates {(18.0024, 17.6308)};
\addplot[olive, only marks] coordinates {(19.9158, 10.8752)};
\addplot[blue, only marks] coordinates {(19.798, 7.44025)};
\addplot[cyan, only marks] coordinates {(19.4223, 4.57679)};
\addplot[teal, only marks] coordinates {(18.9801, 4.98689e-16)};
\addplot[smooth,dotted] coordinates {
(23.0175, 1.64554e-15) (19.544, 12.1362) (17.3908, 15.9429)
(16.3344, 18.2596) (18.0024, 17.6308) (19.9158, 10.8752)
(19.798, 7.44025) (19.4223, 4.57679) (18.9801, 4.98689e-16)
};
\legend{$\gamma = -\frac{\pi}{2}$, $\gamma = -\frac{\pi}{3}$, $\gamma = -\frac{\pi}{4}$, $\gamma = -\frac{\pi}{6}$, $\gamma = 0$, $\gamma = +\frac{\pi}{6}$, $\gamma = +\frac{\pi}{4}$, $\gamma = +\frac{\pi}{3}$, $\gamma = +\frac{\pi}{2}$}
\end{axis}
\end{tikzpicture}
\end{document}
输出
输出与上面的输出相同。