取代之前已設定樣式的軸線

取代之前已設定樣式的軸線

我不知道如何將軸線樣式從“帶箭頭”(在樣式中設定)覆蓋為“無箭頭”。

這是一個 MWE:

\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=newest}

\pgfplotsset{
axisStyle/.style={axis y line =left, 
          axis x line =bottom,
          axis line style ={very thick}}
}

\begin{document}

\begin{figure}[htbc]
    \centering
    \begin{tikzpicture}
        \begin{axis}
        [   axisStyle, 
            axis y line=none,
            axis y line*=left, 
            axis x line*=bottom,
            ymax=5
        ]
            \addplot[domain=-2:2] {x^2};
        \end{axis}
    \end{tikzpicture}
\end{figure}

\end{document}

正如您所看到的,簡單地將線條樣式設為“無箭頭”既不起作用,也沒有幫助首先將其設為無。

注意:實際上,我的樣式當然包含更多選項,因此使用該樣式並在可能的情況下更改這兩個設定仍然是合理的。

答案1

若要修改軸線的樣式,請使用<axis> axis line style={<styles>},其中<axis>是要修改的軸(xyz或省略以設定所有軸的樣式),<styles>就是要套用的樣式。

因此,我們可以axis line style={-}axis選項中使用來覆蓋axisStyle軸線,並在本地設定沒有箭頭提示。這裡我省略了,<axis>因為只畫了一條軸線,但效果和 是一樣的x axis line style

這些鑰匙將是附加的到目前安裝的軸線樣式,這就是axis line style ={very thick}fromaxisStyle仍然有效的原因。

\documentclass[tikz]{standalone}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=1.12}

\pgfplotsset{
  axisStyle/.style={
    axis y line =left,
    axis x line =bottom,
    axis line style ={very thick},
  }
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
  axisStyle, 
  axis line style={-},
  axis y line=none,
  ymax=5,
]
  \addplot[domain=-2:2] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容