在 pgfplots 中定義顏色

在 pgfplots 中定義顏色

我想使用自己的顏色繪製函數和數據\definecolor{<name>}{<model>}{<value(s)>}。如果我使用這個指令就\tikzpicture可以了。但如果我使用這個指令pgfplots所有定義的顏色都是黑色的。為什麼?

我的範例(不知道一些計算 - 我需要它來實現更複雜的函數和資料繪圖):

\documentclass[rgb]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepackage{pgffor}
\usepackage{calc}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{sistyle}

\newcommand{\thetamin}{-90}
\newcommand{\thetamax}{90}
\newcommand{\thetaminplusstep}{-80}

%======================================================================================

\begin{document}

\begin{tikzpicture}
\begin{axis}[title={Title},title style={text width=8cm,font=\tiny},ylabel={y}, xlabel={x}, legend style={cells={anchor=west}, legend pos=north west, font=\tiny}, xmin=-1, xmax=1, ymin=-1, ymax=1]
        \foreach \i in {\thetamin,\thetaminplusstep,...,\thetamax}{
        \newcount\k
        \pgfmathsetmacro{\k}{\i/\thetamax}
        \newcount\j
        \j=400
        \ifnum\i<0
        \pgfmathsetmacro{\j}{-400*\i/\thetamin+800} 
        \else
        \pgfmathsetmacro{\j}{(-400/\thetamax*\i)+800}
        \fi     
        \definecolor{tmpcolor}{wave}{\j}
    \colorlet{mycolor}[rgb]{tmpcolor}
        \addplot[color=mycolor, mark=none, domain=-1:1,samples=100]{\k*x};
        %\addlegendentry{$\ang{\i}$};
        }   
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\foreach \i in {\thetamin,\thetaminplusstep,...,\thetamax}{
        \newcount\k
        \pgfmathsetmacro{\k}{\i/\thetamax*2}
        \newcount\j
        \j=400
        \ifnum\i<0
        \pgfmathsetmacro{\j}{-400*\i/\thetamin+800} 
        \else
        \pgfmathsetmacro{\j}{(-400/\thetamax*\i)+800} 
        \fi     
        \definecolor{tmpcolor}{wave}{\j}
    \colorlet{mycolor}[rgb]{tmpcolor}
        \draw[fill=mycolor] (0,\k) rectangle (1,\k+0.25);
        \draw[black] (2.5,\k+0.15) node {\tiny $\ang{\i}$, wave: \j};
        }
\end{tikzpicture}

\end{document}

結果我得到: 在 pgfplots 中定義顏色

我期待一個有用的答案。

安妮

答案1

引起的問題\foreach,也看看\foreach 在軸環境中不表現

解決我使用的問題(在使用顏色圖期間)

\edef\temp{\noexpand\addplot[color of colormap={\l}, solid, mark=none,domain=-1:1,samples=100]{\k*x};}
        \temp   

代替

\addplot[color of colormap={\l}, solid, mark=none,domain=-1:1,samples=100]{\k*x};

結果,問題解決

解決了顏色問題

它也應該在沒有顏色圖的情況下工作,但可以使用\definecolor

相關內容