我这里有一个宏:在 pgfplots 中强制将绘图标记设置为“轴在顶部”
这样我就可以在标记上方绘制轴线。但是,如果我将它与颜色条结合使用,它就无法正常工作,因为颜色条的刻度和刻度标签是透明的
\makeatletter \newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis} \makeatother
\pgfplotsset{axis line on top/.style={
axis line style=transparent,
ticklabel style=transparent,
tick style=transparent,
axis on top=false,
after end axis/.append code={
\pgfplotsset{axis line style=opaque,
ticklabel style=opaque,
tick style=opaque,
grid=none,
every extra x tick/.style={grid=none},
every extra y tick/.style={grid=none}}
\pgfplotsdrawaxis}
}
}
这里是 MWE:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12}
\pgfplotsset{axis line on top/.style={
axis line style=transparent,
ticklabel style=transparent,
tick style=transparent,
axis on top=false,
after end axis/.append code={
\pgfplotsset{axis line style=opaque,
ticklabel style=opaque,
tick style=opaque,
grid=none,
every extra x tick/.style={grid=none},
every extra y tick/.style={grid=none}}
\pgfplotsdrawaxis}
}
}
\begin{document}
\pgfplotstableread{
A B C
0 5 -1
0.5 2 0
1 7 1
1.5 11 1.5
}\mytable %
\begin{tikzpicture}
\pgfplotsset
{
colormap
={test}{color=(green); color=( green!75!black);color=(black)}
}
\makeatletter \newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis} \makeatother
\begin{axis}[
axis line on top,
xmin=0,
colorbar,
]
\addplot[%
scatter,%
only marks,
mark=*,
scatter src=explicit,
colormap name=test,
] table [x={A}, y ={B},meta ={C}] %
{\mytable};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以使用以下方式再次打开颜色条的刻度
every colorbar/.append style={ticklabel style=opaque,
tick style=opaque}
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12}
\pgfplotsset{axis line on top/.style={
axis line style=transparent,
ticklabel style=transparent,
tick style=transparent,
axis on top=false,
after end axis/.append code={
\pgfplotsset{axis line style=opaque,
ticklabel style=opaque,
tick style=opaque,
grid=none,
every extra x tick/.style={grid=none},
every extra y tick/.style={grid=none}}
\pgfplotsdrawaxis}
}
}
\begin{document}
\pgfplotstableread{
A B C
0 5 -1
0.5 2 0
1 7 1
1.5 11 1.5
}\mytable %
\begin{tikzpicture}
\pgfplotsset
{
colormap
={test}{color=(green); color=( green!75!black);color=(black)}
}
\makeatletter \newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis} \makeatother
\begin{axis}[
axis line on top,
every colorbar/.append style={
ticklabel style=opaque,
tick style=opaque},
xmin=0,
colorbar,
]
\addplot[%
scatter,%
only marks,
mark=*,
scatter src=explicit,
colormap name=test,
] table [x={A}, y ={B},meta ={C}] %
{\mytable};
\end{axis}
\end{tikzpicture}
\end{document}