3

There is alas some (understatement) dissonance between my idea of a figure and the figure I am currently able to make using tikz and pgfplots. I want to make a figure that looks like this

enter image description here

however my poor knowledge of tikz and pgfplots only allowed me to come up with this (I apologize in advance) terrible MWE:

\documentclass{standalone}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xbar=0pt,
        enlargelimits=0.15,
        width=.9\textwidth,
        label style={font=\footnotesize},
        ytick={0,...,3},
        yticklabels = {AA, BB, CC},
        ytick=data,
        every axis plot/.append style={fill},
        y = 0.4cm,
        xmode=log,log basis x=10,
        xbar stacked,
        axis on top
    ]
        \addplot coordinates {(3000, 0) (832, 1) (1E7, 2)};
    \end{axis}
\end{tikzpicture}
\end{document}

I went through the documentation for the pgfplots package but could not find something similar to use as a starting point and quickly became intimidated.

Is there anyone who could guide a poor soul?

1 Answers1

2

This diagram is probably easier to draw with TikZ, but in case you want to use pgfplots, this can maybe serve as a starting point (with inspiration from this answer):

\documentclass[border=2mm]{standalone}

\usepackage{pgfplotstable} \pgfplotsset{compat=1.18}

\begin{document}% \begin{tikzpicture}

\pgfplotstableread{
    Label Start  Stop
    1     600    60000 
    2     1      3000 
    3     1e5    1e7 
}\datatable

\pgfplotsset{
  every axis/.style={
    width=.9\textwidth,
    y=0.4cm,
    bar width=0.4cm,
    enlarge y limits=0.25,
    label style={font=\footnotesize},
    axis on top,
    xbar stacked,
    xmin=1, xmax=1e7,
    xmode=log, 
    ytick={1,...,3},
    yticklabels={CC, BB, AA},
    ytick style={draw=none},
    extra y ticks={1.5,2.5},
    extra y tick labels={},
    extra y tick style={grid=minor},
    minor tick style={draw=none},
    xlabel={FREQUENCY (Hz)},
    clip=false,
  },
  minimum/.style={forget plot, draw=none, fill=none},
}

\begin{axis} \draw [<->, thick] (axis cs:1,3.5) -- (axis cs:1e2,3.5) node [midway,above, font=\footnotesize] {XXX}; \draw [<->, thick] (axis cs:1e3,3.5) -- (axis cs:1.5e4,3.5) node [midway,above, font=\footnotesize] {YYY}; \draw [<->, thick] (axis cs:1e5,3.5) -- (axis cs:1e7,3.5) node [midway,above, font=\footnotesize] {ZZZ}; \addplot [minimum] table [x=Start, y=Label] {\datatable}; \addplot table [y=Label, x expr=\thisrowno{2}-\thisrowno{1}] {\datatable}; \end{axis}

\end{tikzpicture} \end{document}

enter image description here

  • Wow, thank you, @Jasper Habicht. This pretty much solved everything and then some! I particularly liked how you implemented the data table. – naughty_waves Nov 04 '21 at 16:01
  • I apologize for annoying you again but is there a way to change the color of the bars from blue to something else? Also, is it possible to change the color of the edges? I already changed the color of the grids (grid style={black}) and ticks (every tick/.style={black}). – naughty_waves Nov 04 '21 at 18:26
  • Maybe have a look over here: https://tex.stackexchange.com/a/99320/47927 – Jasper Habicht Nov 04 '21 at 18:40
  • How foolish am I! Saw that one earlier but apparently misread something. Thank you again, @Jasper Habicht, and yet again I apologize for my ignorance. – naughty_waves Nov 04 '21 at 19:11
  • This site is exactly for asking questions. So, there is absolutely no reason to apologise! – Jasper Habicht Nov 04 '21 at 19:13