全局更改刻度标签大小

全局更改刻度标签大小

我正在尝试更改刻度标签的字体大小,但它们不会对

\pgfplotsset{every tick label/.append style={font=\scriptsize}}

这是因为我从 Matlab 自动创建了 tikz 文件。因此,有一些刻度标签的设置,它们会以某种方式覆盖字体大小(尽管只是颜色)。现在,我可以全局更改刻度标签大小,而不必更改自动生成的 tikz 文件吗?

另外,是否有可能在正确对齐图表和标签的同时节省空间?因为现在,“ylabel 4”有点不寻常。当我使用类似

\pgfplotsset{yticklabel style={text width=2.5em,align=center}}

该结构占用了相对较多的空间。我知道这是命令的目的,但也许有人对此有一个优雅的解决方案?

希望您理解我的问题,提前谢谢您!

我的 MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=newest}
\newlength\figureheight
\newlength\figurewidth

\newcommand{\inputTikz}[1]{
            \setlength\figureheight{0.35\textheight} 
            \setlength\figurewidth{\textwidth}
            \centering
            \resizebox{\textwidth}{!}{\input{#1}}}

\pgfplotsset{
  compat=newest,
    every axis/.append style={font=\footnotesize},
    every tick label/.append style={font=\scriptsize, yshift=0.5ex}
    }

\begin{document}

\begin{figure}
    \inputTikz{fig.tikz}
\end{figure}

\end{document}

tikz 文件“fig.tikz”是

\begin{tikzpicture}

\begin{axis}[%
width=0.39\figurewidth,
height=0.458\figureheight,
at={(0\figurewidth,0.542\figureheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.071428579543637,
ymax=2.00000022722184,
ylabel={ylabel 1},
ymajorgrids,
axis background/.style={fill=white},
legend style={at={(0.5,0.97)},anchor=north,legend columns=2,legend cell align=left,align=left,draw=black}
]
\addplot [color=blue,solid]
  table[row sep=crcr]{%
0 0\\
};

\end{axis}

\begin{axis}[%
width=0.39\figurewidth,
height=0.458\figureheight,
at={(0.503\figurewidth,0.542\figureheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.0227138669391646,
ymax=0.0227138674410331,
ylabel={ylabel 2},
ymajorgrids,
axis background/.style={fill=white}
]
\addplot [color=black,solid,forget plot]
  table[row sep=crcr]{%
0 0\\
};
\end{axis}

\begin{axis}[%
width=0.39\figurewidth,
height=0.458\figureheight,
at={(0\figurewidth,0\figureheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xlabel={xlabel 1},
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.0500000006711102,
ymax=1.40000001879109,
ylabel={ylabel 3},
ymajorgrids,
axis background/.style={fill=white},
legend style={at={(0.5,0.97)},anchor=north,legend columns=2,legend cell align=left,align=left,draw=black}
]
\addplot [color=blue,solid]
  table[row sep=crcr]{%
0   0\\
};

\end{axis}

\begin{axis}[%
width=0.39\figurewidth,
height=0.458\figureheight,
at={(0.503\figurewidth,0\figureheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xlabel={xlabel 2},
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.264169253617191,
ymax=0.264169281884055,
ylabel={ylabel 4},
ymajorgrids,
axis background/.style={fill=white}
]
\addplot [color=black,solid,forget plot]
  table[row sep=crcr]{%
0   0\\
};
\end{axis}
\end{tikzpicture}%

输出

答案1

我不完全明白你想要实现什么,但可以回答你的问题:

1)改用\pgfplotsset{every x tick label/.append style={font=\scriptsize}}

2)您可以将第二和第三个图的 y 轴刻度放在右侧,并移除/减少图的水平间距。axis y line*=right在这些轴的选项中使用。

根据轴限制的实际样子,使用组图而不是四轴环境可能是好主意,也可能不是一个好主意。

为什么同时使用resizeboxwidth=\figurewidth?恕我直言,最好只使用:

\newcommand{\inputTikz}[1]{
            \setlength\figureheight{0.35\textheight} 
            \setlength\figurewidth{.9\textwidth} %For example .9
            \centering
            \input{#1}}

避免标签结垢。

fig.tikz以下是使用的示例groupplot在此处输入图片描述

\begin{tikzpicture}
\begin{groupplot}[group style={group size=2 by 2,horizontal sep=15pt}]
\nextgroupplot[width=0.39\figurewidth,
height=0.458\figureheight,
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.071428579543637,
ymax=2.00000022722184,
ylabel={ylabel 1},
ymajorgrids,
axis background/.style={fill=white},
legend style={at={(0.5,0.97)},anchor=north,legend columns=2,legend cell align=left,align=left,draw=black}
]
\addplot [color=blue,solid]
  table[row sep=crcr]{%
0 0\\
};
\nextgroupplot[width=0.39\figurewidth,
height=0.458\figureheight,
scale only axis,
separate axis lines,
axis y line*=right,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.0227138669391646,
ymax=0.0227138674410331,
ylabel={ylabel 2},
ymajorgrids,
axis background/.style={fill=white}
]
\addplot [color=black,solid,forget plot]
  table[row sep=crcr]{%
0 0\\
};
\nextgroupplot[width=0.39\figurewidth,
height=0.458\figureheight,
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xlabel={xlabel 1},
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.0500000006711102,
ymax=1.40000001879109,
ylabel={ylabel 3},
ymajorgrids,
axis background/.style={fill=white},
legend style={at={(0.5,0.97)},anchor=north,legend columns=2,legend cell align=left,align=left,draw=black}
]
\addplot [color=blue,solid]
  table[row sep=crcr]{%
0   0\\
};
\nextgroupplot[width=0.39\figurewidth,
height=0.458\figureheight,
scale only axis,
axis y line*=right,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xlabel={xlabel 2},
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.264169253617191,
ymax=0.264169281884055,
ylabel={ylabel 4},
ymajorgrids,
axis background/.style={fill=white}
]
\addplot [color=black,solid,forget plot]
  table[row sep=crcr]{%
0   0\\
};
\end{groupplot}
\end{tikzpicture}

相关内容