我在添加与 x 轴和 y 轴对齐的标签时遇到了问题。当我在代码中实现xlabel
/时,它们不显示。此外,我希望图例字体更小,但命令不起作用。我可能没有遵循正确的语法。我能得到一些帮助吗?ylable
\footnotesize
我简化了问题的代码,但最初它是为了显示三个直方图的重叠。
\documentclass[border=1mm]{standalone}
\usepackage{helvet}
\usepackage[eulergreek]{sansmath}
\usepackage{pgfplots}
\pgfplotsset{ compat=1.9}
\usetikzlibrary{patterns}
\makeatletter
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar]
width=7.5mm,
xtick label style = {font=\sansmath\sffamily},
every axis label = {font=\sansmath\sffamily},
xlabel={aaa},
ylabel={bbb},
legend style = {font=\sansmath\sffamily\footnotesize},
label style = {font=\sansmath\sffamily},
legend style={anchor=north west, draw=none},
\addlegendimage{empty legend},
\addplot+[hist={data=x,bins=16,data max=2,data min=-2.6},black!85, fill=black!90 ,opacity=0.7]
table [y expr=1] {
0.944
1.093
-0.678
-1.409
-0.209
-0.672
-1.921
0.220
0.696
0.718
-0.633
-0.575
-0.860
-0.205
1.310
0.220
0.696
0.718
};
\addlegendentry{\hspace{-0.85cm}\textbf\footnotesize{Metals}},
\addlegendentry{Cr(VI)},
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您的代码需要进行如下修改。
\documentclass[border=1mm]{standalone}
\usepackage{helvet}
\usepackage[eulergreek]{sansmath}
\usepackage{pgfplots}
\pgfplotsset{ compat=1.9}
\usetikzlibrary{patterns}
\makeatletter
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,
% width=7.5mm,
xticklabel style = {font=\sansmath\sffamily},
yticklabel style = {font=\sansmath\sffamily},
every axis label = {font=\sansmath\sffamily},
xlabel={aaa},
ylabel={bbb},
legend style = {anchor=north east,
nodes={scale=0.55,transform shape},
font=\sansmath\sffamily},
label style = {font=\sansmath\sffamily},
%legend style={anchor=north east },
%legend style={nodes={scale=0.65, transform shape}},
]
\addplot+[hist={data=x,bins=16,data max=2,data min=-2.6},black!85, fill=black!90 ,opacity=0.7]
table [y expr=1] {
0.944
1.093
-0.678
-1.409
-0.209
-0.672
-1.921
0.220
0.696
0.718
-0.633
-0.575
-0.860
-0.205
1.310
0.220
0.696
0.718
};
\addlegendimage{empty legend},
\addlegendentry{Metals },
\addlegendentry{Cr(VI)},
\end{axis}
\end{tikzpicture}
\end{document}