
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}
もちろん、リストの任意の色を使用できます。