我正在使用 pgfplot 在我的论文中制作几个图形。我想独立更改图中刻度标签、轴标签、图例和其他一些注释/标签的字体大小。例如,轴标签为 8 pt,刻度标签为 6 pt,图例为 6 pt,其他节点为 5 pt。请参阅下面的 MWE,
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{amsmath}
\pgfplotsset{compat=newest}
\pgfplotsset{
tick label style = {font = {\fontsize{6 pt}{12 pt}\selectfont}},
label style = {font = {\fontsize{8 pt}{12 pt}\selectfont}},
legend style = {font = {\fontsize{8 pt}{12 pt}\selectfont}},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width = 6 cm,
height = 5 cm,
xmin = 0,
xmax = 5,
xlabel = {$x$}, ylabel = {$y$},
legend entries = {Analytical, Numerical},
legend pos = north west,
]
\addplot[solid, black, samples = 100, domain = 0:5] {x^2} node[pos = 0.6,below right] (A) {$x^2$};
\addplot[only marks, mark = square, black, samples = 20] {x^2};
\addplot[solid, black, samples = 100, domain = 0:5] {2*x^2} node[pos = 0.75, above left] (B) {$2 x^2$};
\end{axis}
\end{tikzpicture}
\end{document}
默认情况下,节点 (A) (2x^2) 和 (B) (x^2) 中的字体大小对我来说太大了。我知道在定义每个节点时可以更改其字体大小。我正在尝试寻找一些全局方法,因为我在其他图中有很多这样的方法。
我试过
\tikzstyle{every node} = [font = {\fontsize{5 pt}{12 pt}\selectfont}]
这导致
刻度标签和轴标签的字体大小保持不变,但图例的字体大小会发生变化(与节点相同)。我猜这意味着在 pgfplots 中,图例本质上被定义为节点。
所以我的问题是,是否有任何全局方法可以独立更改 pgfplots 中节点的字体大小,而不影响图例?
答案1
如果你想改变\addplot
命令插入的节点的字体大小,你可以使用类似
every axis plot/.append style = {font = \scriptsize}
代码:
\documentclass[margin=5pt]{standalone}
\usepackage{pgfplots}
\usepackage{amsmath}
\pgfplotsset{compat=newest}
\pgfplotsset{
tick label style = {font = \tiny},
label style = {font = \small},
legend style = {font = \footnotesize},
every axis plot/.append style = {font = \scriptsize}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width = 6 cm,
height = 5 cm,
xmin = 0,
xmax = 5,
xlabel = {$x$}, ylabel = {$y$},
legend entries = {Analytical, Numerical},
legend pos = north west,
]
\addplot[solid, black, samples = 100, domain = 0:5] {x^2} node[pos = 0.6,below right] (A) {$x^2$};
\addplot[only marks, mark = square, black, samples = 20] {x^2};
\addplot[solid, black, samples = 100, domain = 0:5] {2*x^2} node[pos = 0.75, above left] (B) {$2 x^2$};
\end{axis}
\end{tikzpicture}
\end{document}