![在 pgfplots 中轴上也更改字体](https://linux22.com/image/257297/%E5%9C%A8%20pgfplots%20%E4%B8%AD%E8%BD%B4%E4%B8%8A%E4%B9%9F%E6%9B%B4%E6%94%B9%E5%AD%97%E4%BD%93.png)
我需要将字体从标准 cnr 更改为 Times。我试过了
\usepackage{times}
,但并没有改变轴上刻度标记数字的字体。我在下面粘贴了代码和输出图像。如图所示,轴上的数字仍然格式化为cnr
,尽管图表的其余部分格式化为Times
。我怎样才能将轴刻度标记上的数字格式化为Times
?
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3, width=70mm, height=60mm} %use to get tight spacing of labels to tickmarks. Not enabled by default because it affects the spacing.
\usepackage[tightpage,active]{preview}
\usepackage{times}
\begin{document}
\begin{preview}
\begin{tikzpicture}
\pgfplotsset{every axis legend/.append style={
font={\tiny}}}
\begin{semilogyaxis}[
legend pos = north east,
unbounded coords=jump,
xmin=-50,
xmax=1000,
ymin=1e-5,
ymax=1e-1,
minor x tick num = {2},
tick style={color=black},
xtick={0, 300, 600, 900},
ytick={1e-2, 1e-3, 1e-4},
every tick/.append style={thin,black},
xlabel=xlabel (times),
ylabel=ylabel (times),
after end axis/.append code={
\draw[black,dotted] (axis cs:200,1e-5) -- (axis cs:200,1e-1);
\node [rotate=90,anchor=north west] at (axis cs:200, 1e-5) {\tiny{side one (times)}};
\node [rotate=90,anchor=south west] at (axis cs:200, 1e-5) {\tiny{side two (times)}};
}]
\addplot+[mark=nothing,
thin,
solid,
black
]
coordinates {(0, 5e-3) (500, 6e-2) (900, 9e-4)};
\addplot+[mark=nothing,
thin,
dashed,
black
]
coordinates {(0, 1e-3) (300, 1e-2) (1000, 3e-4)};
\end{semilogyaxis}
\end{tikzpicture}
\end{preview}
\end{document}
答案1
times
已过时。请使用mathptmx
或txfonts
或txfontsb
代替,这会将数学字体(如轴中的数字)也更改为时间。请参阅此回答以便快速参考过时的软件包。
输入\usepackage{mathptmx}
你的代码
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3, width=70mm, height=60mm} %use to get tight spacing of labels to tickmarks. Not enabled by default because it affects the spacing.
\usepackage[tightpage,active]{preview}
%\usepackage{mathptmx}
%\usepackage{txfonts}
\usepackage{txfontsb}
\begin{document}
\begin{preview}
\begin{tikzpicture}
\pgfplotsset{every axis legend/.append style={
font={\tiny}}}
\begin{semilogyaxis}[
legend pos = north east,
unbounded coords=jump,
xmin=-50,
xmax=1000,
ymin=1e-5,
ymax=1e-1,
minor x tick num = {2},
tick style={color=black},
xtick={0, 300, 600, 900},
ytick={1e-2, 1e-3, 1e-4},
every tick/.append style={thin,black},
xlabel=xlabel (times),
ylabel=ylabel (times),
after end axis/.append code={
\draw[black,dotted] (axis cs:200,1e-5) -- (axis cs:200,1e-1);
\node [rotate=90,anchor=north west] at (axis cs:200, 1e-5) {\tiny{side one (times)}};
\node [rotate=90,anchor=south west] at (axis cs:200, 1e-5) {\tiny{side two (times)}};
}]
\addplot+[mark=nothing,
thin,
solid,
black
]
coordinates {(0, 5e-3) (500, 6e-2) (900, 9e-4)};
\addplot+[mark=nothing,
thin,
dashed,
black
]
coordinates {(0, 1e-3) (300, 1e-2) (1000, 3e-4)};
\end{semilogyaxis}
\end{tikzpicture}
\end{preview}
\end{document}