Pgfplot 轴和轴标签自定义

Pgfplot 轴和轴标签自定义

好吧,简单来说,我的代码给出了下面的图表。 What I have.

但我想要的是类似图 30 的东西(第 56 页,高级工程数学,第 9 版,Irvine Kreszig 著)。

What I want

\ssfamily刻度标签的字体、axis label位置以及更多一点的空间。

前言:

\usepackage{xcolor}
\usepackage{pgfplots}
    \pgfplotsset{compat=newest}
    \pgfplotsset{small, every non boxed x axis/.append style={x axis line style=-},
every non boxed y axis/.append style={y axis line style=-}}

我的代码:

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
        axis lines= middle,
        ylabel=$y$,
        xlabel=$t$,
        height=100pt,
        ymax=3, ymin=-1,
        minor y tick num=1,
        minor x tick num=1,     
        restrict y to domain=-20:20,
]

\addplot[
    thick,
    orange,
    domain=0:15,
    samples=100,
%   fill=orange!60!white,
]
{(3-2*x)*exp(-0.5*x)};
\end{axis}
\end{tikzpicture}
\caption{The sample function, $y=(3-2x)e^{-0.5x}$.}
\end{figure}

抱歉,如果有点长的话。

答案1

这是一次尝试,其中第二组 pgfplotsset{....} 用于设置字体系列,以下两个命令用于重命名\figurename和编号。

\renewcommand\figurename{Fig.}
\setcounter{figure}{29}

并将 x 和 y 标签位置分配到 (x,y) 处,方法是

ylabel=$y$, y label style={at={(0.05,1)}},
xlabel=$t$, x label style={at={(1,0.3)}},

enter image description here

代码

\documentclass[]{article}

\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage[eulergreek]{sansmath}        %%% newly added for font family
\pgfplotsset{
compat=newest, 
small, every non boxed x axis/.append style={x axis line style=-},
every non boxed y axis/.append style={y axis line style=-}
}

\pgfplotsset{                            %%% newly added for font family setting
  tick label style = {font=\sansmath\sffamily},
  every axis label = {font=\sansmath\sffamily},
%  legend style = {font=\sansmath\sfamily},
  label style = {font=\sansmath\sffamily}
}

\renewcommand\figurename{Fig.}
\setcounter{figure}{29}

\begin{document}
\begin{figure}
\begin{tikzpicture}%[inner sep=0.2cm]

\begin{axis}[
        axis lines= middle,
        ylabel=$y$, y label style={at={(0.05,1)}},  %%% newly added
        xlabel=$t$, x label style={at={(1,0.3)}},   %%% newly added
%        height=100pt,
        ymax=3, ymin=-1,
        minor y tick num=1,
        minor x tick num=1,     
        restrict y to domain=-20:20,
        width=8cm, height=5cm,                      %%% newly added 
]

\addplot[
    thick,
    orange,
    domain=0:15,
    samples=100,
%   fill=orange!60!white,
]
{(3-2*x)*exp(-0.5*x)};
\end{axis}
\end{tikzpicture}
\caption{Solution in Example 4}
\end{figure}

\end{document}

相关内容