1

I am trying to create a ybar interval pgf plot with horizontal lines as markers on top of each interval/bar. Intervals widths are specified by my external CSV data file.

I defined my own plotmark (just a \draw (0,0) -- (1,0);), which I am trying to scale in width for each interval I'm plotting.

I have found this answer, where the author makes use of \thisrow, but in my case I get an error:

! Package PGF Math Error: Unknown function `thisrow_unavailable_load_table_directly' (in 'thisrow_unavailable_load_table_directly').

The pgfplots documentation (p.56) mentions this error:

The argument hcolumn namei has to denote either an existing column or one for which a column alias exists (see the manual of PgfplotsTable). If it can't be resolved, the math parser yields an \Unknown function" error message.

How do I fix/accomplish this?

My MWE:

\documentclass{standalone}

\usepackage{filecontents}
\usepackage{pgfplots, pgfplotstable}

\begin{document}
\begin{tikzpicture}
\pgfdeclareplotmark{hr}{
    \draw (0,0) -- (1,0);
}

\begin{axis}[ymode=log,]
\addplot+[
    ybar interval,
    fill=cyan,
    draw=none,
    mark=hr,
    scatter,
    scatter src=explicit,
    visualization depends on=\thisrow{width}\as\intvWidth,
    scatter/@pre marker code/.append style={
        /tikz/mark width=\intvWidth
    },
] table [
    col sep=comma,
    create on use/xaccum/.style={
        create col/expr=\pgfmathaccuma+\prevrow{width}
    },
    x=xaccum, y=height,
] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}

My CSV file looks like this:

height,width
1,884
2,5768
3,835
4,2661
5,492
6,1349
7,486
8,1117
9,498
10,854
10,0

And here's a rendering without widened markers (the blue specs above the cyan area are the markers now):
bad markers

2

Instead of scaling a marker, it might be easier to just use the jump mark left plot style:

\documentclass[border=5mm]{standalone}

\usepackage{filecontents}
\usepackage{pgfplots, pgfplotstable}

\begin{filecontents}{data.csv}
height,width
1,884
2,5768
3,835
4,2661
5,492
6,1349
7,486
8,1117
9,498
10,854
10,0
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\pgfdeclareplotmark{hr}{
    \draw (0,0) -- (1,0);
}

\begin{axis}[ymode=log]
\addplot+[
    jump mark left, mark=none
] table [
    col sep=comma,
    create on use/xaccum/.style={
        create col/expr=\pgfmathaccuma+\prevrow{width}
    },
    x=xaccum, y=height,
] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
| improve this answer | |
  • This kills the fill=cyan. I do want the area under the marker to be filled. Is there a way to combine both? – derabbink Jan 11 '14 at 12:47
  • You can use a second \addplot command for that (though I wouldn't recommend using a filled plot when using a logarithmic axis) – Jake Jan 11 '14 at 13:41
  • fair enough. altough, you can do it with just \addplot[jump mark left] – derabbink Jan 11 '14 at 14:09

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.