如何改进这个`pgfplot`盈亏平衡图?

如何改进这个`pgfplot`盈亏平衡图?

我刚刚完成了绘制盈亏平衡图的代码,该代码仅根据 4 个初始数据自动确定(几乎)所有内容。假定的最小代码如下:

\documentclass{standalone}

\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}

\usepackage{xfp}

\usepackage[np,autolanguage]{numprint}


\usepackage{pgfplots}
  \pgfplotsset{/pgf/number format/use comma,compat=newest}
  \usetikzlibrary{patterns}
  \usepgfplotslibrary{fillbetween}


\begin{document}

% ---------------------- PROBLEM DATA ----------------------------

        \newcommand{\Qmax}{5000}
        \newcommand{\FixedCosts}{9000}
        \newcommand{\Cvu}{2.5}
        \newcommand{\Pu}{7}

% ---------------------- INITIAL SETUPS -------------------------------------

        \newcommand{\Profits}{\fpeval{\Pu-\Cvu}}
        \newcommand{\QBEP}{\fpeval{\FixedCosts/(\Profits)}}
        \newcommand{\yBEP}{\fpeval{\QBEP*\Pu}}
        \newcommand{\Rmax}{\fpeval{\Qmax*\Pu}}
        \newcommand{\Cneg}{\fpeval{-\FixedCosts/\Cvu}}

% -------------------------------------------------------------------------

                 \begin{tikzpicture}
                    \def \minleft {-4500}
                    \def \maxright {5750}
                    \def \mindown {-1500}
                    \def \maxtop {37500}
                    \newcommand{\ylabelpos}{\fpeval{-\minleft/(-\minleft+\maxright)}}
                    \begin{axis}[%
                        scale=2,
                        max space between ticks=30,
                        ticklabel style={font=\scriptsize},
                        axis lines = middle,
                        xmin=\minleft, xmax=\maxright,
                        ymin=\mindown, ymax=\maxtop,
                        domain=\minleft:\maxright,
                        grid=both,
                        xlabel=$ Q $,
                        y label style={at={(axis description cs:\ylabelpos,0.97)},anchor=south},
                        ylabel=$ R_T \quad C_T $,
                        scaled y ticks=false,
                        xticklabel style={/pgf/number format/fixed,/pgf/number format/set thousands separator={\,},rotate=0,anchor=north},
                        scaled x ticks=false,
                        yticklabel style={/pgf/number format/fixed,/pgf/number format/set thousands separator={\,}}]
                        \draw [very thick, red, dashed] (axis cs:\Qmax,\maxtop) -- (axis cs:\Qmax,\mindown);
                        \path [pattern color=yellow, pattern=north west lines,opacity=0.3] (axis cs:\minleft,\maxtop) -- (axis cs:0,\maxtop) -- (axis cs:0,\mindown) -- (axis cs:\minleft,\mindown) -- cycle;
                        \path [pattern color=yellow, pattern=north east lines,opacity=0.3] (axis cs:\Qmax,\maxtop) -- (axis cs:
                        \maxright,\maxtop) -- (axis cs:\maxright,\mindown) -- (axis cs:\Qmax,\mindown) -- cycle;
                        \addplot [very thick, blue, dashed] {\Pu*x};
                        \addplot [name path = R, very thick, blue,domain=0:\Qmax] {\Pu*x};
                        \addplot [very thick, gray, dashed] {\Cvu*x+\FixedCosts};
                        \addplot [name path = C, very thick, gray,domain=0:\Qmax] {\Cvu*x+\FixedCosts};
                        \addplot[opacity=0.3] fill between [of=R and C, split, every even segment/.style = {pattern=north west lines,pattern color=red}, every odd segment/.style ={pattern=north east lines, pattern color=green}];
                        \draw [fill=red](axis cs:0,0) circle (2.5pt);
                        \draw [fill=red](axis cs:\Qmax,\Rmax) circle (2.5pt);
                        \draw [fill=yellow](axis cs:\QBEP,\yBEP) circle (2.5pt) node [below right] {$ B.E.P. ( \np{\QBEP} ; \np{\yBEP} ) $};
                        \draw [fill=red](axis cs:0,\FixedCosts) circle (2.5pt);
                        \draw [fill=red](axis cs:\Cneg,0) circle (2.5pt);
                    \end{axis}
                    \end{tikzpicture}


\end{document}

结果是:

在此处输入图片描述

我代码中的许多语句都来自这个论坛。我有一个愚蠢的问题是:您能给我提供一些改进建议吗?

相关内容