我正在写一篇包含许多图的论文。我希望能够全局更改所有图的一个属性。在我的示例中,我尝试更改所有图的 ylabel 的字体大小,但我想保留所有其他本地设置的属性,例如 ylabel 的颜色。我尝试了以下操作,但没有成功:
\documentclass[12pt, rgb, german,table]{scrreprt}
\usepackage{setspace}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta,shapes.geometric,plotmarks}
\usepgfplotslibrary{patchplots,external}
\begin{document}
\tikzset{every axis/.append style={ylabel style={font={\small \sffamily}},tick label style={font=\scriptsize \sffamily}}}
\begin{figure}
\centering
\includestandalone{Fit}% without .tex extension
\end{figure}
\end{document}
tikz 文件示例为:
\documentclass{standalone}
\usepackage{setspace}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usepackage{grffile}
\usepackage{amsmath}
\begin{document}
\pgfkeys{/pgf/number format/use comma}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=5 cm,
height= 5 cm ,
at={(6.5 cm, 0cm)},
scale only axis,
xmin=0,
xmax=7,
xlabel={},
xmajorticks=false,
separate axis lines,
axis y line*=right,
every outer y axis line/.append style={mycolor2},
every y tick label/.append style={font=\color{mycolor2}},
every y tick/.append style={mycolor2},
ymin=0,
ymax=10,
ylabel/.append style={font=\color{mycolor2}},
ylabel={$A$ (pixel)},
axis background/.style={fill=none},
yticklabel pos=right,
clip marker paths=true,
axis on top=true,
]
\addplot [color=mycolor2, only marks, mark=*, mark options={solid, mycolor2}, forget plot] table[row sep=crcr]{%
1 1.15960009643026\\
2 2.41853566710355\\
3 3.6107259394201\\
4 4.82171231418267\\
5 6.04375717648504\\
6 7.23340089514461\\
};
\end{axis}
\end{tikzpicture}
\end{document}
这会将 ylabel 的字体大小改为小,但也会将 ylabel 的颜色改为黑色,但我希望它们保留我在文件中设置的颜色TikZ
。
答案1
您可以在 中定义所有图片的所有通用样式\pgfplotsset
。例如,在 MWE 中,可以局部设置不同的颜色,以便更容易看到全局和局部设置的效果。其中也有简化的设置方式:
\pgfplotsset{compat = 1.18,
ylabel style={font=\small\sffamily},
tick label style={font=\scriptsize \sffamily}
}
所有这些设置您都可以在本地覆盖。因此,您可以向这些设置添加其他设置,这些设置用于大多数图片(例如图片大小、轴样式等),并在例外情况下在本地覆盖它们。
图表的全局和局部设置示例pgfplots
:
\documentclass[margin=1cm]{standalone}
\usepackage{setspace}
%\usepackage{tikz} % is loaded by `pgfplots`
\usepackage{pgfplots}
\pgfplotsset{compat = 1.18,
ylabel style={font=\small\sffamily},
tick label style = {font=\scriptsize\sffamily,
/pgf/number format/use comma},
}
\usepgfplotslibrary{patchplots}
\usetikzlibrary{arrows.meta,
plotmarks}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\usepackage{grffile}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=5 cm, height= 5cm ,
at={(6.5 cm, 0cm)}, % ?, at standalone this has no sense
scale only axis,
xmin=0, xmax=7, xlabel={},
xmajorticks=false,
separate axis lines,
axis y line*=right,
y axis line style={mycolor2},
y tick label style={mycolor2},
y tick style=blue,
ymin=0, ymax=10,
ylabel style={mycolor2},
ylabel={$A$ (pixel)},
%axis background style={fill=none},
yticklabel pos=right,
clip marker paths=true,
axis on top=true,
]
\addplot [color=mycolor2, only marks, mark=*, mark options={solid, mycolor2}, forget plot] table[row sep=crcr]{%
1 1.15960009643026\\
2 2.41853566710355\\
3 3.6107259394201\\
4 4.82171231418267\\
5 6.04375717648504\\
6 7.23340089514461\\
};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[%
width=5 cm, height= 5cm ,
at={(6.5 cm, 0cm)}, % ?, at standalone this has no sense
scale only axis,
xmin=0, xmax=7, xlabel={},
xmajorticks=false,
separate axis lines,
axis y line*=right,
y axis line style={green},
y tick label style={blue},
y tick style={mycolor2},
ymin=0, ymax=10,
ylabel style={mycolor2},
ylabel={$A$ (pixel)},
axis background style={fill=none},
yticklabel pos=right,
clip marker paths=true,
axis on top=true,
]
\addplot [color=mycolor2, only marks, mark=*, mark options={solid, mycolor2}, forget plot] table[row sep=crcr]{%
1 1.15960009643026\\
2 2.41853566710355\\
3 3.6107259394201\\
4 4.82171231418267\\
5 6.04375717648504\\
6 7.23340089514461\\
};
\end{axis}
\end{tikzpicture}
\end{document}