问题:我希望 (a) 和 (b) 条形图中 N=12 和 N=6 的较小值(<10%,例如 10%、7% 和 6%)能够正确显示,并且不会相互重叠。我尝试更改限制,增加尺寸,但不幸的是没有任何效果。有人能帮我解决这个问题吗?
乳胶代码:
\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*}[!htpb]
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=3 by 1, horizontal sep=1.5cm},
width=0.30\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=\tiny, xshift=3pt},
y tick label style={font=\tiny,anchor=east,align=left,text width=0.5cm,rotate=360},
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,
yticklabels={{N=3 \newline[1139s]},{N=6 \newline[3938s]},{N=12 \newline[14348s]},{N=24 \newline[63678s]},{N=48 \newline[----]}}]
\addplot [color=black, pattern color=black, pattern=crosshatch dots, %
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{16pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}] coordinates{(59.08,1) (63.96,2) (65,3) (65,4) (0,5)};
\addplot [color=black, pattern color=gray, pattern=checkerboard, %
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{-8pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}] coordinates{(17.69,1) (19.18,2) (21,3) (23,4) (0,5)};
\addplot [color=black,pattern color=gray, pattern=north east lines, %
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{-10pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}] coordinates{(10.69,1) (7.88,2)(7,3) (6,4) (0,5)};
\addplot [color=black, pattern color=black, pattern=north west lines, %
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{8pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}] coordinates{(12.08,1) (7.63,2) (6,3) (6,4) (0,5)};
\nextgroupplot[title=(b) MATD3,
yticklabels={{N=3 \newline[1427s]},{N=6 \newline[4601s]},{N=12 \newline[17067s]},{N=24 \newline[----]},{N=48 \newline[----]}}]
\addplot [color=black,pattern color=black, pattern=crosshatch dots] coordinates{(56,1) (60,2) (62,3) (0,4) (0,5)};
\addplot [color=black, pattern color=gray, pattern=checkerboard
,
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{8pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}]
coordinates{(18,1) (20,2) (22,3) (0,4) (0,5)};
\addplot [color=black, pattern color=gray, pattern=north east lines]
% , %
% nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
% \ifnum\pgfmathresult=1%
% \hspace{4pt}%
% \fi%
% \pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}]
coordinates{(15,1) (12,2)(10,3) (0,4) (0,5)};
\addplot [color=black, pattern color=black, pattern=north west lines]
% , %
% nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
% \ifnum\pgfmathresult=1%
% \hspace{8pt}%
% \fi%
% \pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}]
coordinates{(11,1) (8,2) (6,3) (0,4) (0,5)};
\legend{Mini-batch sampling, Target Q calculation, Q loss, P loss},
\nextgroupplot[title=(c) MASAC,
yticklabels={{N=3 \newline[----]},{N=6 \newline[----]},{N=12 \newline[----]},{N=24 \newline[----]},{N=48 \newline[----]}}]
\addplot [color=black, pattern color=black, pattern=crosshatch dots] coordinates{(0,1) (0,2) (0,3) (0,4) (0,5)};
\addplot [color=black, pattern color=gray, pattern=checkerboard] coordinates{(0,1) (0,2) (0,3) (0,4) (0,5)};
\addplot [color=black, pattern color=gray, pattern=north east lines] coordinates{(0,1) (0,2)(0,3) (0,4) (0,5)};
\addplot [color=black, pattern color=black, pattern=north west lines] coordinates{(0,1) (0,2) (0,3) (0,4) (0,5)};
% \addplot [color=black, pattern color=red, pattern=crosshatch dots] coordinates{(34.73,1) (19.64,2) (9.47,3) (0,4) };
% \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=blue, pattern=north east lines] coordinates{(36.56,1) (37.27,2)(32.63,3) (0,4)};
% \addplot [color=black, pattern color=olive, pattern=north west lines] coordinates{(12.14,1) (3.12,2) (1.53,3) (0,4)};
\end{groupplot}
\end{tikzpicture}
%\vspace{-\baselineskip}
\caption{Caption}
\end{figure*}
\end{document}
答案1
我只是调整了尺寸和间距 - 没有尝试清理或理解代码:
\documentclass[10pt,journal,compsoc,xcolor={dvipsnames}]{IEEEtran}
\usepackage[show frame]{geometry}
\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*}[!htpb]
\begin{tikzpicture}
\begin{groupplot}[
xbar stacked, tiny, nodes near coords style={font=\tiny, yshift=6pt},
group style={group size=3 by 1, horizontal sep=1.2cm},
width=0.30\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=\tiny, xshift=3pt},
y tick label style={font=\tiny,anchor=east,align=left,text width=0.45cm,rotate=360},
legend style={at={(0.5,1.05)}, anchor=south, legend columns=4, font=\footnotesize, cells={anchor=west}},
/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},
]
\nextgroupplot[title=(a) MADDPG,
yticklabels={{N=3 \newline[1139s]},{N=6 \newline[3938s]},{N=12 \newline[14348s]},{N=24 \newline[63678s]},{N=48 \newline[----]}},
coordinate style/.condition={x-0.5*rawx>95}{xshift=-4pt},
]
\addplot [color=black, pattern color=black, pattern=crosshatch dots, %
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{16pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}] coordinates{(59.08,1) (63.96,2) (65,3) (65,4) (0,5)};
\addplot [color=black, pattern color=gray, pattern=checkerboard, %
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{-8pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}] coordinates{(17.69,1) (19.18,2) (21,3) (23,4) (0,5)};
\addplot [color=black,pattern color=gray, pattern=north east lines, %
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{-10pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}] coordinates{(10.69,1) (7.88,2)(7,3) (6,4) (0,5)};
\addplot [color=black, pattern color=black, pattern=north west lines, %
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{8pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}] coordinates{(12.08,1) (7.63,2) (6,3) (6,4) (0,5)};
\nextgroupplot[title=(b) MATD3,
yticklabels={{N=3 \newline[1427s]},{N=6 \newline[4601s]},{N=12 \newline[17067s]},{N=24 \newline[----]},{N=48 \newline[----]}}]
\addplot [color=black,pattern color=black, pattern=crosshatch dots] coordinates{(56,1) (60,2) (62,3) (0,4) (0,5)};
\addplot [color=black, pattern color=gray, pattern=checkerboard
,
nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
\ifnum\pgfmathresult=1%
\hspace{8pt}%
\fi%
\pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}]
coordinates{(18,1) (20,2) (22,3) (0,4) (0,5)};
\addplot [color=black, pattern color=gray, pattern=north east lines]
% , %
% nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
% \ifnum\pgfmathresult=1%
% \hspace{4pt}%
% \fi%
% \pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}]
coordinates{(15,1) (12,2)(10,3) (0,4) (0,5)};
\addplot [color=black, pattern color=black, pattern=north west lines]
% , %
% nodes near coords={\pgfmathparse{less(\pgfplotspointmetatransformed,100)}%
% \ifnum\pgfmathresult=1%
% \hspace{8pt}%
% \fi%
% \pgfkeys{/pgf/number format/precision=0}\pgfmathprintnumber{\pgfplotspointmeta}\%}]
coordinates{(11,1) (8,2) (6,3) (0,4) (0,5)};
\legend{Mini-batch sampling, Target Q calculation, Q loss, P loss},
\nextgroupplot[title=(c) MASAC,
/pgfplots/group/horizontal sep=1cm,
y tick label style={font=\tiny,anchor=east,align=left,text width=0.4cm,rotate=360, xshift=2pt},
yticklabels={{N=3 \newline[----]},{N=6 \newline[----]},{N=12 \newline[----]},{N=24 \newline[----]},{N=48 \newline[----]}}]
\addplot [color=black, pattern color=black, pattern=crosshatch dots] coordinates{(0,1) (0,2) (0,3) (0,4) (0,5)};
\addplot [color=black, pattern color=gray, pattern=checkerboard] coordinates{(0,1) (0,2) (0,3) (0,4) (0,5)};
\addplot [color=black, pattern color=gray, pattern=north east lines] coordinates{(0,1) (0,2)(0,3) (0,4) (0,5)};
\addplot [color=black, pattern color=black, pattern=north west lines] coordinates{(0,1) (0,2) (0,3) (0,4) (0,5)};
% \addplot [color=black, pattern color=red, pattern=crosshatch dots] coordinates{(34.73,1) (19.64,2) (9.47,3) (0,4) };
% \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=blue, pattern=north east lines] coordinates{(36.56,1) (37.27,2)(32.63,3) (0,4)};
% \addplot [color=black, pattern color=olive, pattern=north west lines] coordinates{(12.14,1) (3.12,2) (1.53,3) (0,4)};
\end{groupplot}
\end{tikzpicture}
%\vspace{-\baselineskip}
\caption{Caption}
\end{figure*}
\end{document}