更改 tikz 極座標中的點顏色

更改 tikz 極座標中的點顏色

我目前正在努力改變極座標中單一點的顏色。我想使用圓柱體創建 HSV 色彩空間的視覺化。

謝謝pgfplots 中圓錐體的 HSV 陰影我了解到您可以point meta={symbolic={Hsb=v,u,u}}直接從當前座標獲得正確的顏色。

但是當我把它換成圓柱體時,我得到了很多

Missing number, treated as zero.
<to be read again> 
LaTeX
Illegal unit of measure (pt inserted).
<to be read again> 
LaTeX

錯誤。

我目前的程式碼是:

\documentclass[tikz,border=3mm]{standalone} 
\usepackage{pgfplots}

\begin{document} 
\begin{axis}[axis equal, data cs=polar]
    
    \addplot3 [surf,
                domain=0:1,
                y domain=0:180,
               samples=20, %number of samples taken
               z buffer=sort,
               shader=interp,
               variable=\u,
               variable y=\v,
               point meta={symbolic={Hsb=u,v,v}}] % the origin of my errors
        (
            {v/2},
            {sin(v/2)},
            {u}
        );
    
    \end{axis}
\end{document}

我認為這可能是我生成圓柱體的怪異方式導致了問題,但我無法理解它。

先致謝

答案1

我看到你修復了你的 MWE 以包含在內mesh/color input = explicit mathparse,!對於後代來說,HSB「S」的飽和度也存在問題,它需要一個 [0,1] 中的值,而您要傳遞\v給 [0,180]。

只是為了好玩,如果你想要一個完整的圓柱體,你可以改變網域:

\documentclass[tikz,border=3mm]{standalone} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document} 
\begin{tikzpicture}
    \begin{axis}[axis equal, data cs=polar]
    \addplot3 [
        surf,
        domain = 0:1,
        y domain = 0:360,
        samples = 20, %number of samples taken
        z buffer = sort,
        shader = interp,
        variable = \u, variable y = \v,
        mesh/color input = explicit mathparse,
        point meta={symbolic={Hsb=v,1,u}},
        ] 
        ({v/2},{sin(v/2)},{u});
    \end{axis}    
\end{tikzpicture}
\end{document}

帶有 HSB 著色的開頂圓柱體 如果你想要一個具有全色譜的半圓柱體,只需將色調加倍即可:

\documentclass[tikz,border=3mm]{standalone} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document} 
\begin{tikzpicture}
    \begin{axis}[axis equal, data cs=polar]
    \addplot3 [
        surf,
        domain = 0:1,
        y domain = 0:180,
        samples = 20, %number of samples taken
        z buffer = sort,
        shader = interp,
        variable = \u, variable y = \v,
        mesh/color input = explicit mathparse,
        point meta={symbolic={Hsb=2*v,1,u}},
        ] 
        ({v/2},{sin(v/2)},{u});
    \end{axis}    
\end{tikzpicture}
\end{document}

帶有 HSB 著色的頂部開口的半圓柱體

答案2

我再次查看了代碼pgfplots 中圓錐體的 HSV 陰影並發現我錯過了添加mesh/color input=explicit mathparse到我的軸選項。

工作代碼是:

\documentclass[tikz,border=3mm]{standalone} 
\usepackage{pgfplots}

\begin{document} 
\begin{tikzpicture}

    \begin{axis}[axis equal, data cs=polar, mesh/color input=explicit mathparse] % the solution to my problem
    
    \addplot3 [surf,
                domain=0:1,
                y domain=0:180,
               samples=20, %number of samples taken
               z buffer=sort,
               shader=interp,
               variable=\u,
               variable y=\v,
               point meta={symbolic={Hsb=v,1,u}}]
        (
            {v/2},
            {sin(v/2)},
            {u}
        );
    
    \end{axis}
    
\end{tikzpicture}
\end{document}

編譯後的圖像

相關內容