使用 pgfplots 繪製部分極座標圖

使用 pgfplots 繪製部分極座標圖

我想僅創建圓的第一象限(角度 0 到 90 度)的極坐標圖,但我無法正確獲取刻度和標籤。採取這個樣本:

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.polar}
\pgfplotsset{width=10cm,compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{polaraxis}[
  domain=0:90,
  ymin=0, ymax=1.5,
  xmin=0, xmax=90,
  xlabel={angle},
  ylabel={radius},
  ytick pos=left,
]
\addplot {1};
\end{polaraxis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
  domain=0:90,
  ymin=0, ymax=1.5,
  xmin=0, xmax=90,
  xlabel={angle},
  ylabel={radius},
]
\addplot {1};
\end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

我想要但找不到一致的方式來獲得的東西:

  1. 繪圖下方的半徑刻度標籤(水平軸)

  2. 在水平軸下方也標記“半徑”。

  3. 刪除外圓線,但仍會得到刻度線和標籤。

另外,尺寸與所請求的“寬度”不匹配,就像附帶的笛卡爾圖一樣,我想這是因為尺寸是針對整個圓計算的。這是故意的嗎?

更新的 pgfplots 版本可以解決這些問題嗎?

答案1

我認為該polar庫是一個“快速而骯髒”的實現,並且似乎不經常使用,因為其中似乎存在一些錯誤,正如您已經發現的那樣。因此,似乎人們必須在沒有 PGFPlots「智能」的情況下放置和繪製所有需要的東西。

如果需要,您可以將錯誤新增至錯誤追蹤者。最好的是,每個 bug 都有一個 MWE。

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
    \usetikzlibrary{pgfplots.polar}
    \pgfplotsset{width=10cm,compat=1.10}
\begin{document}
    \begin{tikzpicture}
        \begin{polaraxis}[
            domain=0:90,
            ymin=0, ymax=1.5,
            xmin=0, xmax=90,
            xlabel={angle},
            ylabel={radius},
            ytick pos=left,
            % move `yticklabels' below the axis line
%            yticklabel pos=lower,   % <-- doesn't seem to work in `polaraxis'
            % move them down by hand
            yticklabel style={
                anchor=north,
                yshift=-2pt,
            },
            % move ``radius'' label below the axis
            ylabel style={
                at={(axis cs:0,0.75)},
                anchor=near ticklabel opposite,
                yshift=-2ex,
            },
            % move ``angle'' label to 45° again
            xlabel style={
                at={(axis cs:45,1.7)},
                sloped={at position=45},
                anchor=near ticklabel,
                near ticklabel at=45,
            },
            % don't draw the axis lines
            axis line style={draw=none},
            % in case you want to draw the yaxis lines only
            % (but the line will then be drawn above marks ...)
            after end axis/.code={
                \draw (axis cs:0,1.5) -- (axis cs:0,0) -- (axis cs:90,1.5);
                % test the width of the plot
                \draw [red] (axis cs:-1,1.5) -- +(-5cm,0);
            },
%            % to scale only the axis (and not also the labels, etc.)
%            scale only axis=true,
        ]
            \addplot {1};
        \end{polaraxis}
    \end{tikzpicture}
\end{document}

顯示上述程式碼結果的程式碼

相關內容