Overleaf Latex 中長條圖的填滿顏色清單是什麼?如何更改長條圖的預設顏色?

Overleaf Latex 中長條圖的填滿顏色清單是什麼?如何更改長條圖的預設顏色?

如何更改 Overleaf 圖表範本的預設顏色?

在此輸入影像描述

我找到了顏色列表

在此輸入影像描述

我的MWE:

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.16}

\begin{document}

\begin{tikzpicture}
\pgfplotsforeachungrouped \X in {1,...,9}
{\ifnum\X=1
\edef\mylst{Testing1}
\else
\edef\mylst{\mylst,Testing\X}
\fi}
\begin{axis}[symbolic x coords/.expanded=\mylst,
    ylabel=Number,
    enlargelimits=0.05,
    x tick label style={anchor=north west,rotate=-30},
    legend style={at={(0.5,-0.2)},
    anchor=north,legend columns=-1},
    ybar,
]
\addplot 
    coordinates {(Testing1,9) (Testing2,4)
         (Testing3,4) (Testing4,1) (Testing5,1) (Testing6,8) (Testing7,1) (Testing8,1) (Testing9,1)};
\addplot 
    coordinates {(Testing1,3) (Testing2,5)
         (Testing3,5) (Testing4,4) (Testing5,5) (Testing6,7) (Testing7,0) (Testing8,0) (Testing9,0)};
\legend{Series 1, Series2}
\end{axis}
\end{tikzpicture}
\end{document}

答案1

預設顏色與背面無關,但它們儲存在循環列表中。相關的循環清單ybar(與 相同xbar)可以在第 4 頁找到。 86本手冊v1.16,

在此輸入影像描述

你可以改變它以獲得例如

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.16}
\pgfplotsset{
/pgfplots/bar cycle list/.style={/pgfplots/cycle list={
{OliveGreen,fill=OliveGreen!30!white,mark=none},
{Plum,fill=Plum!30!white,mark=none},
{cyan!60!black,fill=cyan!30!white,mark=none},
{black,fill=gray,mark=none},
},
},
}
\begin{document}

\begin{tikzpicture}
\pgfplotsforeachungrouped \X in {1,...,9}
{\ifnum\X=1
\edef\mylst{Testing1}
\else
\edef\mylst{\mylst,Testing\X}
\fi}
\begin{axis}[symbolic x coords/.expanded=\mylst,
    ylabel=Number,
    enlargelimits=0.05,
    x tick label style={anchor=north west,rotate=-30},
    legend style={at={(0.5,-0.2)},
    anchor=north,legend columns=-1},
    ybar,
]
\addplot 
    coordinates {(Testing1,9) (Testing2,4)
         (Testing3,4) (Testing4,1) (Testing5,1) (Testing6,8) (Testing7,1) (Testing8,1) (Testing9,1)};
\addplot 
    coordinates {(Testing1,3) (Testing2,5)
         (Testing3,5) (Testing4,4) (Testing5,5) (Testing6,7) (Testing7,0) (Testing8,0) (Testing9,0)};
\legend{Series 1, Series2}
\end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

在這裡,我加載了獲取您喜歡的顏色的選項,您也可以在之前使用,xcolor因為它無論如何都會加載。dvipsnames\PassOptionsToPackage{dvipsnames}{xcolor}\usepackage{pgfplots}xcolor

或者,您可以將選項直接傳遞給\addplot

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.16}
\begin{document}

\begin{tikzpicture}
\pgfplotsforeachungrouped \X in {1,...,9}
{\ifnum\X=1
\edef\mylst{Testing1}
\else
\edef\mylst{\mylst,Testing\X}
\fi}
\begin{axis}[symbolic x coords/.expanded=\mylst,
    ylabel=Number,
    enlargelimits=0.05,
    x tick label style={anchor=north west,rotate=-30},
    legend style={at={(0.5,-0.2)},
    anchor=north,legend columns=-1},
    ybar,
]
\addplot[fill=ForestGreen!30,draw=ForestGreen] 
    coordinates {(Testing1,9) (Testing2,4)
         (Testing3,4) (Testing4,1) (Testing5,1) (Testing6,8) (Testing7,1) (Testing8,1) (Testing9,1)};
\addplot[fill=RoyalPurple!30,draw=RoyalPurple]  
    coordinates {(Testing1,3) (Testing2,5)
         (Testing3,5) (Testing4,4) (Testing5,5) (Testing6,7) (Testing7,0) (Testing8,0) (Testing9,0)};
\legend{Series 1, Series2}
\end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

當然,您可以使用清單中的任何顏色。

相關內容