随着X底部轴

随着X底部轴

在此图中,我的两个 x 标签与函数重叠。我想将标签移到顶部,或者给它们一个白框?不知道哪种看起来更好。

我怎样才能做到这一点?

 \documentclass[letter,11pt,twoside]{article}
    \usepackage{tikz}
    \usepackage{pgfplots}
    \usepackage{pgfplotstable}
    \usepackage{stmaryrd}
    \usepackage{array,booktabs}
    \usepackage{placeins}
    \pgfplotsset{
        compat=newest,
        xlabel near ticks,
        ylabel near ticks,
        myplot/.style={smooth,tension=0.5,mark=none,very thick}
    }    
    \begin{document}
\begin{figure}[h]
\begin{tikzpicture}[
labelnode/.style={font=\footnotesize, above},%
  labelline/.style={stealth-stealth,shorten >=0.1pt, shorten <=0.5pt}%
  ]%
\begin{axis}[%
 width=0.95\textwidth,height=0.4\textheight,%
 axis x line=center,%
 xmin=0,%
 xmax=0.8,%
 xtick={0.2,0.22,0.458,0.70},%
 xticklabels={{$c_1$},{$c_2$},{$c_{S_2}$},{$w_{S_2}^*$}},%
 axis y line=left,%
 ymin=-75,%
 ymax=85,%
 ytick={0},%
 yticklabels={{0}},%The ** looks odd there - I know. but otherwise it clashes into c_S_2; I think we can keep it as is. Not an error, but on purpose ;)
 ylabel={$\Delta\left(E\left[\pi\right]\right)$},%
 xlabel={$c_{S_1}$},%
 label style={at={(axis description cs:1,0.46)},anchor=north},
    y label style={at={(axis description cs:-0.06,0.95)},rotate=-90,anchor=south},
]% 
% Retailer
\addplot+[color=black,myplot, thick]%price
 coordinates {%
 (0, 70.)  (0.34, -45.42384424965933)  (0.7000000000000001, 0)
}%
 ;%
  % S1
\addplot+[color=gray,myplot,thick]%
 coordinates {%
  (0, -70.)  (0.31, 25.52000000000001)  (0.45, 0)  
} 
 ;%

\draw[densely dotted] (0.70, -75) -- (0.70,85);%
\draw[densely dotted] (0.22, -75) -- (0.22,85);%
\draw[densely dotted] (0.2, -75) -- (0.2,85);%
\end{axis}%
\end{tikzpicture}%
{Effect of financial distress on expected profits\label{delta}} 
\end{figure}
    \end{document}

答案1

由于您尚未说明如何处理两个重叠的 x 刻度标签C1C2,我会即兴发挥。我添加了图钉以避免重叠问题,用于clip=false确保这些图钉可见,改进了附在轴:

$\operatorname{\Delta}\bigl(\operatorname{E}[\pi]\bigr)$

(使用\operatornamefromamsmath获得适当的间距和直立的字体),删除未使用的东西 - 包括许多不必要的行尾百分号 - 在垂直线左侧十点处放置一个带有方程的图例框X = S 2 *,用于every axis plot/.append style={myplot}避免重复每个图的样式,并从中myplot删除:+\addplot+

  • 我们不想在这里使用任何标记来表示情节,并且

  • 我们自己指定每个图的颜色。

另外,标题的位置不合适,看起来很糟糕。我已将其figure以标准方式添加到:

\caption{Effect of financial distress on expected profits}

您可能想要添加:

\label{whatever-you-want}

紧接着这一行之后(以前没有!)。最后,我在的参数中设置了compat=1.16而不是,以确保可重现的行为。compat=newest\pgfplotsset

随着X底部轴

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}

\pgfplotsset{
  compat=1.16,
  myplot/.style={smooth, tension=0.5, mark=none, thick}
}

\begin{document}

\begin{figure}
  \begin{tikzpicture}
    \begin{axis}[
      width=0.95\textwidth, height=0.4\textheight,
      axis x line=bottom,
      xmin=0,
      xmax=0.8,
      xtick={0.2, 0.22, 0.458, 0.70},
      xticklabels={,, $c_{S_2}$ , $w_{S_2}^*$},
      axis y line=left,
      ymin=-75,
      ymax=85,
      ytick={0},
      yticklabels={0},
      ylabel={$\operatorname{\Delta}\bigl(\operatorname{E}[\pi]\bigr)$},
      label style={at={(axis description cs:1,0.46)},anchor=north},
      y label style={at={(axis description cs:0,0.95)},
                     rotate=-90, anchor=south east},
      legend entries={Price, $S_1$},
      legend style={at={({axis cs:0.70,0} |- 0,0.95)}, anchor=north east,
                    outer xsep=10pt},
      clip=false,
      every axis plot/.append style={myplot},
      ]
      % Retailer
      \addplot[color=blue!40] coordinates { % price
        (0, 70.)  (0.34, -45.42384424965933)  (0.7000000000000001, 0)
      }
      ;
      % S1
      \addplot[color=red!40] coordinates {
        (0, -70.)  (0.31, 25.52000000000001)  (0.45, 0)
      };

      \node [pin=-100:$c_1$] at (0.2,0  |- {axis description cs:0,0}) {};
      \node [pin=-80:$c_2$]  at (0.22,0 |- {axis description cs:0,0}) {};

      \draw[densely dotted] (0.70, -75) -- (0.70,85);
      \draw[densely dotted] (0.22, -75) -- (0.22,85);
      \draw[densely dotted] (0.2, -75) -- (0.2,85);
    \end{axis}
  \end{tikzpicture}%
  \caption{Effect of financial distress on expected profits}
\end{figure}

\end{document}

底部的 x 轴

随着X顶部轴线

代码是相同的,只是你必须用和axis x line=bottom替换axis x line=top

\node [pin=-100:$c_1$] at (0.2,0  |- {axis description cs:0,0}) {};
\node [pin=-80:$c_2$]  at (0.22,0 |- {axis description cs:0,0}) {};

\node [pin=100:$c_1$] at (0.2,0  |- {axis description cs:0,1}) {};
\node [pin=80:$c_2$]  at (0.22,0 |- {axis description cs:0,1}) {};

x 轴在顶部

相关内容