
Problema 1: Estou tentando gerar um gráfico de barras com 3 barras para cada gráfico. Mas, como você pode ver na saída abaixo, meus rótulos do eixo x estão sendo repetidos duas vezes. Rótulos do eixo X = {3-6, 6-12, 12-24}
Problema 2: Quando compilo o código no verso, obtenho a imagem completa no centro e quando colo o código em outro documento, ele ocupa muito espaço (já que toda a página do pdf está sendo copiada para outro documento). Existe alguma maneira de, ao compilar o projeto, receber apenas um download em PDF que se limita apenas a essa imagem?
Saída do problema 2
Saída do problema 1:
Código de látex:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{pgf}
\usepackage{tikz} % Required for drawing custom shapes
\usetikzlibrary{shapes,arrows,automata}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.17}
\usetikzlibrary{patterns}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}[
legend columns=-1,
%bar width=1pt, % Width of the bar
%, % Distance between the centers of the bars
symbolic x coords={3-6, 6-12, 12-24},
enlarge x limits={abs=0.6cm},
width=1.2\textwidth,
%xtick={3,6,12,24},
height=0.8\textheight,
ymin=0,
ymax=15,
nodes near coords,
every node near coord/.append style={font=\scriptsize},
nodes near coords align={vertical},
xlabel={x},
ylabel={y},
% The distance between the center of the first bar and the left edge
%enlarge y limits=false,
legend entries={{\color{olive}{\tiny Random}},{\color{orange}{\tiny ++Cost}},{\color{teal}{\tiny ++FTE}}},
legend to name=CombinedLegendBar,
footnotesize,
ybar legend,
legend image code/.code={%
\draw[#1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
},
% area legend, % This is the alternate option
group style={
group size=3 by 1,
xlabels at=edge bottom,
ylabels at=edge left}]
\nextgroupplot[title={\scriptsize MADDPG}]
\addplot[ybar, fill=olive] coordinates { (3-6, 6.886)};
\addplot[ybar, fill=orange] coordinates { (6-12, 8.501)};
\addplot[ybar, fill=teal] coordinates { (12-24, 10.179)};
%\addplot[ybar, fill=gray] coordinates { (4, 11.14)};
% \addplot[ybar, pattern=north east lines] coordinates { (5, 15.001)};
\nextgroupplot[title={\scriptsize MATD3}]
\addplot[ybar, fill=olive] coordinates { (3-6, 6.886)};
\addplot[ybar, fill=orange] coordinates { (6-12, 8.501)};
\addplot[ybar, fill=teal] coordinates { (12-24, 10.179)};
% \addplot[ybar, fill=gray] coordinates { (4, 11.14)};
% \addplot[ybar, pattern=north east lines] coordinates {(5, 15.001)};
\nextgroupplot[title={\scriptsize MASAC}]
` \addplot[ybar, fill=olive] coordinates { (3-6, 6.886)};
\addplot[ybar, fill=orange] coordinates { (6-12, 8.501)};
\addplot[ybar, fill=teal] coordinates { (12-24, 10.179)};
% \addplot[ybar, fill=gray] coordinates { (4, 11.14)};
% \addplot[ybar, pattern=north east lines] coordinates { (5, 15.001)};
\end{groupplot}
\end{tikzpicture}
\ref{CombinedLegendBar}
\caption{Triage++ Performance}
\label{PlusPlusCombinedBar}
\end{figure}
\end{document}
Alguém pode me ajudar com esse problema?
Obrigado!
Responder1
- Sua dúvida não está totalmente clara, por exemplo, como você insere essa imagem no seu documento real (final)?
- Para posicionamento de figuras na página, tente usar opções de posição de posicionamento, ou seja,
\begin{figure}
escreva\begin{figure}[ht]
ou\begin{figure}[!ht]
. - Depois de limpar suas
groupplot
configurações como é feito no MWE abaixo, e depois de reorganizar um pouco o código da figura, a compilação na instalação local do MiKTeX, bem como no Overleaf, dá o mesmo resultado. - A limpeza é feita de acordo com a minha resposta anteriorpergunta(não há necessidade de adicionar
xtick
opção):
(as linhas vermelhas indicam o layout da página)
\documentclass{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{figure}[ht]
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=3 by 1,
ylabels at=edge left,
horizontal sep=6mm,
},
%
width=0.27\linewidth, %height=4cm,
scale only axis,
title style = {font=\small},
%
enlarge x limits=0.3,
xlabel={x}, ylabel={y},
symbolic x coords={3-6, 6-12, 12-24},
ytick={0,2,...,12},
ticklabel style={font=\footnotesize},
ymin=0, ymax=12,
%
nodes near coords,
every node near coord/.append style={yshift=-3pt, font=\scriptsize},
%
legend entries = {\color{olive}{Random},
\color{orange}{++Cost},
\color{teal}{++FTE}},
legend to name=CombinedLegendBar,
legend image code/.code={\draw[#1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);},
legend style={at={(0.5,-0.33)},
below,
legend columns=-1,
font=\footnotesize,
/tikz/every even column/.append style={column sep=1em}
}
]
\nextgroupplot[title=MADDPG]
\addplot[ybar, fill=olive] coordinates { (3-6, 6.886) };
\addplot[ybar, fill=orange] coordinates { (6-12, 8.501) };
\addplot[ybar, fill=teal] coordinates { (12-24,10.179) };
\nextgroupplot[title=MATD3]
\addplot[ybar, fill=olive] coordinates { (3-6, 6.886) };
\addplot[ybar, fill=orange] coordinates { (6-12, 8.501) };
\addplot[ybar, fill=teal] coordinates { (12-24,10.179) };
\nextgroupplot[title=MASAC]
\addplot[ybar, fill=olive] coordinates { (3-6, 6.886) };
\addplot[ybar, fill=orange] coordinates { (6-12, 8.501) };
\addplot[ybar, fill=teal] coordinates { (12-24,10.179) };
\end{groupplot}
\end{tikzpicture}
\ref{CombinedLegendBar}
\caption{Triage++ Performance}
\label{PlusPlusCombinedBar}
\end{figure}
\end{document}
Responder2
Em relação ao Problema 1: Adicionar o comando xtick com os rótulos simbólicos (veja abaixo) funcionou para mim.
Em relação ao Problema 2: Se bem entendi, substituir a classe do artigo de documento para autônomo resolveu para mim (tive que remover a figura ambiente + a legenda)
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{pgf}
\usepackage{tikz} % Required for drawing custom shapes
\usetikzlibrary{shapes,arrows,automata}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.17}
\usetikzlibrary{patterns}
\begin{document}
\centering
\begin{tikzpicture}
\begin{groupplot}[
legend columns=-1,
%bar width=1pt, % Width of the bar
%, % Distance between the centers of the bars
symbolic x coords={3-6, 6-12, 12-24},
enlarge x limits={abs=0.6cm},
width=1.2\textwidth,
xtick={3-6, 6-12, 12-24},
height=0.8\textheight,
ymin=0,
ymax=15,
nodes near coords,
every node near coord/.append style={font=\scriptsize},
nodes near coords align={vertical},
xlabel={x},
ylabel={y},
% The distance between the center of the first bar and the left edge
%enlarge y limits=false,
legend entries={{\color{olive}{\tiny Random}},{\color{orange}{\tiny ++Cost}},{\color{teal}{\tiny ++FTE}}},
legend to name=CombinedLegendBar,
footnotesize,
ybar legend,
legend image code/.code={%
\draw[#1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
},
% area legend, % This is the alternate option
group style={
group size=3 by 1,
xlabels at=edge bottom,
ylabels at=edge left}]
\nextgroupplot[title={\scriptsize MADDPG}]
\addplot[ybar, fill=olive] coordinates { (3-6, 6.886)};
\addplot[ybar, fill=orange] coordinates { (6-12, 8.501)};
\addplot[ybar, fill=teal] coordinates { (12-24, 10.179)};
%\addplot[ybar, fill=gray] coordinates { (4, 11.14)};
% \addplot[ybar, pattern=north east lines] coordinates { (5, 15.001)};
\nextgroupplot[title={\scriptsize MATD3}]
\addplot[ybar, fill=olive] coordinates { (3-6, 6.886)};
\addplot[ybar, fill=orange] coordinates { (6-12, 8.501)};
\addplot[ybar, fill=teal] coordinates { (12-24, 10.179)};
% \addplot[ybar, fill=gray] coordinates { (4, 11.14)};
% \addplot[ybar, pattern=north east lines] coordinates {(5, 15.001)};
\nextgroupplot[title={\scriptsize MASAC}]
` \addplot[ybar, fill=olive] coordinates { (3-6, 6.886)};
\addplot[ybar, fill=orange] coordinates { (6-12, 8.501)};
\addplot[ybar, fill=teal] coordinates { (12-24, 10.179)};
% \addplot[ybar, fill=gray] coordinates { (4, 11.14)};
% \addplot[ybar, pattern=north east lines] coordinates { (5, 15.001)};
\end{groupplot}
\end{tikzpicture}
\end{document}