Как рисовать многопроцессорные диаграммы Ганта с помощью pgfgantt?

Как рисовать многопроцессорные диаграммы Ганта с помощью pgfgantt?

У меня есть быстрый вопрос по поводуpgfganttупаковка:

Для статьи мне нужно уметь рисовать такие графики:

введите описание изображения здесь

Однако, с инструкциями, pgfganttкоторые я видел до сих пор, я не могу понять, как это сделать. Пока что мне удалось получить только что-то вроде этого:

введите описание изображения здесь

Вот мой код:

\begin{ganttchart}[
inline, % puts the label inside the bar
hgrid,
vgrid,
bar height=1
]{1}{10}
% P3
\ganttgroup[inline=false,group/.style={draw=none, fill=none}]{P3}{2,0}{25,0}
\ganttbar[bar/.append style={fill=green}]{$T1$}{1}{2} 
\ganttbar{}{3}{4} 
\ganttbar[bar/.append style={fill=orange}]{$T3$}{5}{7}
\ganttbar{}{8}{9} 
\ganttbar[bar/.append style={fill=cyan}]{$T5$}{10}{10} 
\\
% P2
\ganttgroup[inline=false,group/.style={draw=none, fill=none}]{P2}{2,0}{25,0}
\ganttbar[bar/.append style={fill=green}]{$T1$}{1}{2} 
\ganttbar{}{3}{4} 
\ganttbar{}{3}{4} 
\ganttbar{}{5}{7}
\ganttbar[bar/.append style={fill=yellow}]{$T4$}{8}{9}
\ganttbar[bar/.append style={fill=cyan}]{$T5$}{10}{10} 
\\
% P1
\ganttgroup[inline=false,group/.style={draw=none, fill=none}]{P1}{2,0}{25,0}
\ganttbar{}{1}{4} 
\ganttbar[bar/.append style={fill=orange}]{$T3$}{5}{7}
\ganttbar[bar/.append style={fill=yellow}]{$T4$}{8}{9}
\ganttbar{}{10}{10}
%
\end{ganttchart}

Итак, мой вопрос: как мне создать задачи на нескольких процессорах (P_x) и сделать так, чтобы они выглядели как единое целое (убрать черную рамку, использовать только одну нотацию и т. д.)?

решение1

Надеюсь, вы не против, если я предложу альтернативу. Если вы уже знакомы с пакетом pgfplots, использование этого пакета вместо pgfganttможет быть простым вариантом без необходимости слишком много возиться с pgfganttкодом.

Это пример использования, area plotописанный в разделе 4.5.10 руководства pgflots.

Координаты \addplotуказываются в следующем порядке:{(south west) (north west) (north east) (south east)}

Общая настройка среды axisнемного выросла (как, по-моему, обычно бывает с pgfplots). Если у вас есть вопросы по конкретным настройкам, я с удовольствием отвечу на них в комментариях.

Результат:

Новый Гант

Код:

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{intersections}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  font=\footnotesize,
  ytick style={draw=none},
  xtick style={draw=none},
  unit vector ratio*=1 1 1,
  axis lines = middle,
  enlarge x limits = {value=.1,upper},
  enlarge y limits = {value=.05,upper},
  ylabel={processors},
  xlabel={time},
  ylabel near ticks,
  xlabel near ticks,
  const plot,
  stack plots=false,
  area style,
  ytick={1,...,11},
  yticklabels={},  
  xtick={1,...,4},
  extra y ticks={3,5,6,8,10,11},
  extra y tick style={yticklabel={$P_{\pgfmathprintnumber{\tick}}$}}
  ] 
 \addplot[fill=yellow] coordinates {(0,0)  (0,3) (3,3)  (3,0) } node at (current path bounding box.center) {T4};
\addplot[fill=orange] coordinates {(0,3) (0,5) (2,5) (2,3)} node at (current path bounding box.center) {T3}; 
\addplot[fill=red!20] coordinates {(2,3) (2,5) (3,5) (3,3)} node at (current path bounding box.center) {T7}; 
\addplot[fill=gray] coordinates {(3,0) (3,8) (4,8) (4,0)} node at (current path bounding box.center) {T9};  
\addplot[fill=teal] coordinates {(0,5) (0,11) (1,11) (1,5)} node at (current path bounding box.center) {T5}; 
\addplot[fill=yellow!60!black] coordinates {(1,5) (3,5) (3,6) (1,6)} node at (current path bounding box.center) {T8};
\addplot[fill=red!20] coordinates {(2,6) (2,8) (3,8) (3,6)} node at (current path bounding box.center) {T7}; 
\addplot[fill=blue!20] coordinates {(1,6)  (1,10) (2,10) (2,6)} node at (current path bounding box.center) {T6};
\addplot[fill=magenta] coordinates {(2,8) (2,10) (4,10) (4,8)} node at (current path bounding box.center) {T2};
\addplot[fill=green!20] coordinates {(1,10) (1,11) (4,11) (4,10)} node at (current path bounding box.center) {T1};
\end{axis}
\end{tikzpicture}
\end{document}

Связанный контент