现在我做类似的事情。
有人能帮帮我吗?谢谢!
\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.95]
\begin{axis}[
width=9.5cm,
height=5.5cm,
ymin=0.0,ymax=1.0,
ytick={0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0},
ymajorgrids=true,
grid style=dashed,
%nodes near coords,
legend style={at={(0.15,0.96)},anchor=north,legend columns=1},
]
\addplot [mark=*,mark size=2pt,mark options={fill=blue!80!white},]
coordinates {(0,0.2) (0,0.6)};
\addplot+ [mark=triangle*,mark size=2pt,mark options={fill=blue!80!black},]
coordinates {(0.5,0.4) (0.5,0.8)};
\legend{A,B}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
最简单的选择可能是使用符号散点类。
\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.95]
\begin{axis}[
width=9.5cm,
height=5.5cm,
ymin=0.0,ymax=1.0,
ytick={0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0},
ymajorgrids=true,
grid style=dashed,
legend style={at={(0.35,0.96)},anchor=north,legend columns=1},
scatter/classes={
a={mark=*},
b={mark=o,draw=black}
},
]
\addlegendimage{only marks,mark=*}
\addlegendentry{Before repacking}
\addlegendimage{only marks,mark=o}
\addlegendentry{After repacking}
\addplot[scatter,scatter src=explicit symbolic] coordinates {(0,0.2)[a] (0,0.6)[b]};
\addplot[scatter,scatter src=explicit symbolic] coordinates {(0.5,0.4)[a] (0.5,0.8)[b]};
\end{axis}
\end{tikzpicture}
\end{document}
或者,您可以在方括号中明确设置填充颜色。
\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.95]
\begin{axis}[
width=9.5cm,
height=5.5cm,
ymin=0.0,ymax=1.0,
ytick={0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0},
ymajorgrids=true,
grid style=dashed,
legend style={at={(0.35,0.96)},anchor=north,legend columns=1},
colormap={fake}{
rgb255(0cm)=(255,255,255); rgb255(1cm)=(0,0,0)}
]
\addlegendimage{only marks,mark=*}
\addlegendentry{Before repacking}
\addlegendimage{only marks,mark=o}
\addlegendentry{After repacking}
\addplot[scatter,scatter src=explicit] coordinates {(0,0.2)[1] (0,0.6)[0]};
\addplot[scatter,scatter src=explicit] coordinates {(0.5,0.4)[1] (0.5,0.8)[0]};
\end{axis}
\end{tikzpicture}
\end{document}