如何更改 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
默认颜色与 overleaf 无关,但它们存储在循环列表中。 的相关循环列表ybar
(与 相同xbar
)可以在手册 v1.16 第 86 页找到,
您可以将其更改为例如
\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}
当然,您可以使用列表中的任意颜色。