我正在使用带标记的散点图cube*
。图本身一切正常,但是图例中显示cube*
为黑色。有没有办法配置图例使用的颜色?
以下是 PGFPlots 手册第 133 页的一个小例子(修改为使用更简单的独立数据代替plotdata/pgfplots_scatterdata4.dat
,并添加了图例)。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={120}{40},
width=220pt,
height=220pt,
grid=major,
z buffer=sort,
xmin=-1,xmax=9,
ymin=-1,ymax=9,
zmin=-1,zmax=9,
enlargelimits=upper,
xtick={-1,1,...,19},
ytick={-1,1,...,19},
ztick={-1,1,...,19},
xlabel={$l_1$},
ylabel={$l_2$},
zlabel={$l_3$},
point meta={x+y+z+3},
colormap={summap}{
color=(black) color=(blue)
color=(black) color=(white)
color=(orange) color=(violet)
color=(red)
},
scatter/use mapped color={
draw=mapped color,fill=mapped color!70},
]
\addplot3 [only marks,scatter,mark=cube*,mark size=7]
coordinates {
(1, 6, -1)
(-1, -1, -1)
};
\addlegendentry{Test};
\end{axis}
\end{tikzpicture}
\end{document}
\end{standalone}
图例显示为黑色:
答案1
您可以添加legend image post style={mark options={...}}
到轴选项:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm, compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={120}{40},
width=220pt,
height=220pt,
grid=major,
z buffer=sort,
xmin=-1,xmax=9,
ymin=-1,ymax=9,
zmin=-1,zmax=9,
enlargelimits=upper,
xtick={-1,1,...,19},
ytick={-1,1,...,19},
ztick={-1,1,...,19},
xlabel={$l_1$},
ylabel={$l_2$},
zlabel={$l_3$},
point meta={x+y+z+3},
colormap={summap}{
color=(black) color=(blue)
color=(black) color=(white)
color=(orange) color=(violet)
color=(red)
},
scatter/use mapped color={
draw=mapped color,fill=mapped color!70
},
legend image post style={mark options={fill=lightgray}},
]
\addplot3 [only marks,scatter,mark=cube*,mark size=7]
coordinates {
(1, 6, -1)
(-1, -1, -1)
};
\addlegendentry{Test};
\end{axis}
\end{tikzpicture}
\end{document}
如果您想要更改图例中立方体的大小,并以不同方式设置立方体边缘的大小,您可以执行以下操作:
legend image post style={
/pgfplots/cube/size x=10pt,
mark options={
fill=lightgray,
mark size=5pt,
}
}
这将导致: