3

I want to recreate the following figure with the colorbar.

fig

Source: https://dl.acm.org/citation.cfm?id=1531403

I've tried using pgfplots axis environment with colorbars, and managed to get the colorbar right. But I don't know how I can get the colored plots.

So far, what I have managed to do is this: enter image description here

I have the following questions:

  1. How to move the colorbar to the right side of the grid of squares?
  2. How to plot the colored line plot inside each square?

Code:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{plotmarks}

\begin{document}

\begin{tikzpicture}[>={Stealth[inset=0pt,length=10pt,angle'=35,round]}]

% \begin{axis}[colorbar,at={(1.1,1.1)},hide axis,
%     scale only axis]
% \addplot[mesh,ultra thick,domain=1.5:3] {x};
% \end{axis}



\draw[->,ultra thick] (-5.4,-5.4)--(5.4,-5.4) node[right]{$\omega_x$};
\draw[->,ultra thick] (-5.4,-5.4)--(-5.4,5.4) node[above]{$\omega_y$};

% \draw[step=1cm,gray,very thin] (0,0) grid (5,5);

% First row
\draw (-5.2,5.2) -- (-5.2,3.2) -- (-3.2,3.2) -- (-3.2,5.2) -- cycle;
\draw (-3.1,5.2) -- (-3.1,3.2) -- (-1.1,3.2) -- (-1.1,5.2) -- cycle;
\draw (1,5.2) -- (1,3.2) -- (-1,3.2) -- (-1,5.2) -- cycle;
\draw (3.1,5.2) -- (3.1,3.2) -- (1.1,3.2) -- (1.1,5.2) -- cycle;
\draw (5.2,5.2) -- (5.2,3.2) -- (3.2,3.2) -- (3.2,5.2) -- cycle;

% Second row
\draw (-5.2,3.1) -- (-5.2,1.1) -- (-3.2,1.1) -- (-3.2,3.1) -- cycle;
\draw (-3.1,3.1) -- (-3.1,1.1) -- (-1.1,1.1) -- (-1.1,3.1) -- cycle;
\draw (1,3.1) -- (1,1.1) -- (-1,1.1) -- (-1,3.1) -- cycle;
\draw (3.1,3.1) -- (3.1,1.1) -- (1.1,1.1) -- (1.1,3.1) -- cycle;
\draw (5.2,3.1) -- (5.2,1.1) -- (3.2,1.1) -- (3.2,3.1) -- cycle;

% Middle row
\draw (-5.2,1) -- (-5.2,-1) -- (-3.2,-1) -- (-3.2,1) -- cycle;
\draw (-3.1,1) -- (-3.1,-1) -- (-1.1,-1) -- (-1.1,1) -- cycle;
\draw (1,1) -- (1,-1) -- (-1,-1) -- (-1,1) -- cycle;
\draw (3.1,1) -- (3.1,-1) -- (1.1,-1) -- (1.1,1) -- cycle;
\draw (5.2,1) -- (5.2,-1) -- (3.2,-1) -- (3.2,1) -- cycle;

% Fourth row
\draw (-5.2,-1.1) -- (-5.2,-3.1) -- (-3.2,-3.1) -- (-3.2,-1.1) -- cycle;
\draw (-3.1,-1.1) -- (-3.1,-3.1) -- (-1.1,-3.1) -- (-1.1,-1.1) -- cycle;
\draw (1,-1.1) -- (1,-3.1) -- (-1,-3.1) -- (-1,-1.1) -- cycle;
\draw (3.1,-1.1) -- (3.1,-3.1) -- (1.1,-3.1) -- (1.1,-1.1) -- cycle;
\draw (5.2,-1.1) -- (5.2,-3.1) -- (3.2,-3.1) -- (3.2,-1.1) -- cycle;

%Fifth row
\draw (-5.2,-3.2) -- (-5.2,-5.2) -- (-3.2,-5.2) -- (-3.2,-3.2) -- cycle;
\draw (-3.1,-3.2) -- (-3.1,-5.2) -- (-1.1,-5.2) -- (-1.1,-3.2) -- cycle;
\draw (1,-3.2) -- (1,-5.2) -- (-1,-5.2) -- (-1,-3.2) -- cycle;
\draw (3.1,-3.2) -- (3.1,-5.2) -- (1.1,-5.2) -- (1.1,-3.2) -- cycle;
\draw (5.2,-3.2) -- (5.2,-5.2) -- (3.2,-5.2) -- (3.2,-3.2) -- cycle;

\begin{axis}[
    hide axis,
    scale only axis,
    height=0pt,
    width=0pt,
    colormap/jet,
    colorbar,
    point meta min=-1,
    point meta max=1,
    colorbar style={
        height=5cm,
        ytick={-1,-0.5,0,0.5,1}
    }]
    \addplot [draw=none] coordinates {(0,0)};
\end{axis}

\end{tikzpicture}

\end{document}
6

Generally you will receive more attention if you split up your question in smaller pieces because the chance that many others will precisely want to produce this graph may not be too big.

  1. To produce this layout of subgraphs I use the groupplots library.
  2. The color bar is produced standalone and inserted via a savebox in order to avoid nesting tikzpictures.
  3. To simplify matters, the various plots are produced in a loop.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{groupplots} 
\usetikzlibrary{arrows.meta,positioning}
\newsavebox\ColorBar
\sbox\ColorBar{\pgfplotscolorbardrawstandalone[colormap/jet,
    colorbar style={
        ticklabel style={
            font=\small,
            /pgf/number format/precision=3,
            /pgf/number format/relative*=4,
        },ytick={0,250,500,750,1000},yticklabels={$s=1$,$s=0.5$,$s=0$,$s=0.5$,$s=1$}
    },
    %colorbar horizontal,
    %colormap access=const,
     point meta min=0,point meta max=1000]}
\begin{document}
\begin{tikzpicture}[>={Stealth[inset=0pt,length=10pt,angle'=35,round]}]
 \begin{groupplot}[group style={group size=5 by 5, y descriptions at=edge
   left, horizontal sep=5pt,vertical sep=5pt,
   group name=my plots},height=2.5cm,width=2.5cm,
   ymin=-0.5,ymax=0.5,xmin=-0.5,xmax=0.5,
    axis background/.style={fill=black},hide axis,colormap/jet]
  \pgfplotsinvokeforeach{0,...,24}{\nextgroupplot[]
   \pgfmathtruncatemacro{\X}{mod(#1,5)-2}
   \pgfmathtruncatemacro{\Y}{int(#1/5)-2}
   \pgfmathsetmacro{\Z}{ifthenelse(abs(\X)<2,ifthenelse(abs(\Y)<2,0.5,1),1)}
   \pgfmathsetmacro{\myangle}{-atan2(\Y,\X)}
   \ifnum#1=12
    \addplot[opacity=0] ({cos(\myangle)*x},{sin(\myangle)*x});
    \fill[red] (0,0) circle(1pt);
   \else
    \addplot[mesh,domain=-0.5*\Z:0.5*\Z,point meta={veclen(-0.5*cos(\myangle)+x,-0.5*sin(\myangle)+y)},line width=1pt]
    ({cos(\myangle)*x},{sin(\myangle)*x});
   \fi}
 \end{groupplot}
 \node[right=1cm of my plots c5r3.east]{\usebox\ColorBar};
 \draw[thick,<->] ([xshift=3mm,yshift=-2mm]my plots c5r5.south east) 
 node[right]{$\omega_x$} -- 
  ([xshift=-2mm,yshift=-2mm]my plots c1r5.south west) 
 -- ([xshift=-2mm,yshift=3mm]my plots c1r1.north west) node[above]{$\omega_y$};
 \foreach \X [count=\Y,evaluate=\Y as \Z using {int(6-\Y)}] in {\Omega,0.5\,\Omega,0,-0.5\,\Omega,-\Omega}
 {\node [left=4mm of my plots c1r\Y.west]{$\X$};
 \node [below=4mm of my plots c\Z r5.south]{$\X$}; }
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    If you increase the samples, the color transitions will become smoother (at the expense of an increased compilation time). – user121799 Jan 27 at 23:48
  • I'm trying to add two axes without ticks but with arrowheads to just one of the groupplots. How can I do this? – Sndn Feb 20 at 18:56
  • @Sndn Just add \draw[stealth-stealth] ([xshift=-1mm,yshift=1mm]my plots c3r3.north west) |- ([xshift=1mm,yshift=-1mm]my plots c3r3.south east);, say. Here c and r stand for to column and row. – user121799 Feb 20 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.