条形图中的 Y 轴标签应该不同

条形图中的 Y 轴标签应该不同

我想为下面显示的三个条形图设置三个不同的 Y 轴标签。重申一下,条形图 (a) MADDPG 的标签应为 N=3、N=6、N=12、N=24、N=48,条形图 (b) MATD3 的标签应为 N=1、N=10、N=20、N=30、N=50,MASAC 的标签应为 N=1、N=25、N=50、N=75、N=100

我的代码:

\documentclass[10pt,journal,compsoc,xcolor={dvipsnames}]{IEEEtran}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.18}
\usepackage{pgfplotstable}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{multirow}
\usepackage{lipsum}
\usepackage{xspace}
\usetikzlibrary{patterns}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\newcommand{\R}{\mathbb{R}}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=0.7pt] (char) {#1};}}

\begin{document}

\begin{figure*}[h]
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=3 by 1, horizontal sep=1.2cm}, 
width=0.3\textwidth, height=0.3cm,
xmajorgrids=true,
tick align=outside, xtick pos=left,
scale only axis,
x post scale=0.85,
enlarge y limits=0.20,
xmin=0, xmax=100,
xtick={0,20,...,100},
ytick=data, yticklabels={N=3,N=6,N=12,N=24,N=48},
xticklabel={\pgfmathprintnumber{\tick}\%},
xticklabel style={font=\scriptsize},
yticklabel style={font=\scriptsize, xshift=3pt},
nodes near coords style={font=\scriptsize,  yshift=8pt},
legend style={at={(0.5,1.05)}, anchor=south, legend columns=4, font=\footnotesize, cells={anchor=west}},
xbar stacked,
/pgf/bar width=2.5mm,
y=5.2mm,
legend image code/.code={%
            \draw[#1] (0cm,-0.1cm) rectangle (0.6cm,0.2cm);
            },
title style={at={(0.5,-0.3)}, anchor=north},
nodes near coords={\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%},
%coordinate style/.condition={x-0.5*rawx<5}{red, xshift=4pt},
coordinate style/.condition={x-0.5*rawx>95}{xshift=-4pt},
]

\nextgroupplot[title=(a) MADDPG]
\addplot [color=black, pattern color=black, pattern=crosshatch dots, %
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{8pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}]
coordinates{(43,1) (30,2) (20,3) (12,4) (4,5)};
%\addplot [color=black,  pattern color=gray, pattern=checkerboard] 
%coordinates{(16.57,1) (39.97,2) (56.37,3) (0,4)};
\addplot [color=black,  pattern color=gray, pattern=checkerboard] coordinates{(55,1) (68,2)(79,3) (88,4) (96,5)};
\addplot [color=black,  pattern color=black, pattern=north west lines] coordinates{(2,1) (2,2) (1,3) (1,4) (0,5)};
%4
\nextgroupplot[title=(b) MATD3]
\addplot [color=black,  pattern color=black, pattern=crosshatch dots, %
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{8pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}]
coordinates{(45,1) (31,2) (18,3) (10,4) (3,5)};
% \addplot [color=black, pattern color=gray, pattern=checkerboard] 
% coordinates{(22,1) (36,2) (50.12,3) (0,4)};
\addplot [color=black,  pattern color=gray, pattern=checkerboard] 
coordinates{(53,1) (67,2) (81,3) (90,4) (97,5)};
\addplot [color=black, pattern color=black, pattern=north west lines] 
coordinates{(2,1) (2,2) (1,3) (0,4) (0,5)};
\legend{Action selection, Update all trainers, Other Parts},
%3,4

\nextgroupplot[title=(c) MASAC]
\addplot [color=black,  pattern color=black, pattern=crosshatch dots]
coordinates{(52,1) (45,2) (38,3) (26,4) (13,5)};
% \addplot [color=black, pattern color=gray, pattern=checkerboard] 
% coordinates{(21,1) (36,2) (51,3) (0,4)};
\addplot [color=black,   pattern color=gray, pattern=checkerboard] coordinates{(46,1) (53,2)(62,3) (74,4) (87,5)};
\addplot [color=black, pattern color=black, pattern=north west lines] 
coordinates{(2,1) (2,2) (0,3) (0,4) (0,5)};
% %3,4

\end{groupplot}
\end{tikzpicture}
%\vspace{-\baselineskip}
\caption{Training time breakdown for three MARL workloads with 3, 6, 12 \& 24 agents. The environment is Competitive task~(Predator-Prey).}
\label{figure1}
\end{figure*}
\end{document}

输出: 在此处输入图片描述

有人知道如何解决这个问题吗?:)

答案1

像这样:

在此处输入图片描述

我擅自(并利用晚上的一些空闲时间)将您的 MWE 重写为更简洁、更清晰(至少对我来说)的形式。您可能喜欢它

相关内容