如何在 pgfplots 中设置 y 轴范围?

如何在 pgfplots 中设置 y 轴范围?

下面是我的代码:

\documentclass[11pt,oneside,openany]{book}
\usepackage[a4paper, left=1.5cm, right=1.5cm, top=3cm, bottom=3cm]{geometry}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\tikzset{bullet/.style={circle,fill,inner sep=2pt}}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            ymin=0, ymax=10,
            minor y tick num = 3,
            area style,
            ]
            \addplot+[ybar interval,mark=no] plot coordinates { (0, 9.52) (18 868.3692, 9.72) (45 000, 0) };
        \end{axis}
    \end{tikzpicture}
\end{document}

我希望我的图表像下面这样(手写)在此处输入图片描述

当前结果

当前结果

答案1

像这样?

在此处输入图片描述

\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
    axis lines=left,
    xmax=45 000,
    ymin=7, ymax=10,    
    restrict y to domain=7:10,
    ytick=\empty,
    extra y ticks={8, 9, 9.52, 9.72, 10},
    extra y tick style={tick label style={font=\scriptsize}},
    ylabel={Weighted Cost of Capital \%},
    axis y discontinuity=crunch,
    xtick=\empty,
    extra x ticks={0, 18 868.3692, 45 000},
    xlabel={Total financing},
    enlargelimits=0.1,
    area style,
    ]

\addplot +[ybar interval] coordinates { (0, 9.52) (18 868.3692, 9.72) (45 000, 9.72) };

\end{axis}
    \end{tikzpicture}
\end{document}

相关内容