我有以下代码大致近似于我想用 tikz 制作的图表:
\begin{tikzpicture}
\begin{axis}[
% (normal text should not be set in math mode)
xlabel=,
ylabel=,
% if you use `data' ticks will be set on every x coordinate that is
% given by the *first* `\addplot' command
xtick=data,
xticklabels={
Control,
Voucher,
Transfer%
},
ytick=data,
yticklabels={
No increase,
Increase%
},
% use the following key so the baseline of all ticklabel entries is the same
% (compare this image to the one from marmot)
typeset ticklabels with strut,
% there is one default value for the `legend pos' that is outside the axis
legend pos=outer north east,
% (so the legend looks a bit better)
legend cell align=left,
% (moved this common key here),
]
% (renamed `plot coordinates' by `coordinates'
\addplot [mark=*,blue] coordinates {
(1,1)
(2,1)
(3,1)
};
\addplot [color=red,mark=x] coordinates {
(1,1)
(2,1)
(3,2)
};
\addplot [color=green,mark=x] coordinates {
(1,1)
(2,2)
(3,2)
};
% (replaced `\addlegendentry's with `\legend')
\legend{
Pure Altruism,
Warm Glow,
Mental Accounting,
}
\end{axis}
\end{tikzpicture}
如您所见,我尝试添加 y 轴刻度标签,但这并没有出现在实际图表本身中。此外,我试图说明的本质上是离散的,因此我希望 x 轴上的每个刻度有三个相邻的条形图,这将说明在每个理论下水平应该是“高”还是“低”传奇。
如何将其转换为具有三个相邻条形的条形图并添加我需要的两个 y 轴标签?