0

This question follows from a previous question I asked. I have some PGFPlots code (kindly provided by Stefan Pinnow) which basically draws a cylinder with its mesh and colours each rectangle delimited by the mesh green or red according to a list of 0s and 1s. The result is something like this:

enter image description here

The two cylinders in the picture above were formed using different lists of 0s and 1s. How I determine which elements of each list are 0s and which elements are 1s is irrelevant to my question (I think). The lists can be created with a regular text editor (I use TextWrangler) or with LaTeX code.

The code compiles perfectly (meaning I get the same result as in the image above). In case it's useful, I'm compiling the code in XeLaTeX (for reasons briefly stated in the previous question) using TeXShop 3.51 on a Mac with OS 10.12.1. The problem is that when I modify anything from the list I get the following result:

enter image description here

If I change draw=black to draw=none in the my addplot style bit (see below for the code), I get the following, indicating the compiler does understand that it must draw red and green bits according to my list of 0s and 1s but can't figure out where exactly to put them:

enter image description here

Here's my code, which, as far as I can tell, is esentially identical to Stefan Pinnow's in the previous question:

\documentclass[border=5pt,varwidth]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
    compat=1.9,
    colormap={CM}{
        color=(green)
        color=(red)
    },
    my axis style/.style={
        xmin=-10,
        xmax=10,
        ymin=-4,
        ymax=4,
        zmin=-4,
        zmax=4,
        hide axis,
        z buffer=sort,
    },
    my addplot style/.style={
        surf,
        line join=round,
        shader=flat corner,
        draw=black,
        point meta=explicit,
    },
    my table style/.style={
        /pgfplots/table/.cd,
            x=x,
            y=y,
            z=z,
    },
}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[my axis style]
        \addplot3 [my addplot style] table [
            my table style,
            meta=prob,
        ] {Tube.txt};
    \end{axis}
\end{tikzpicture}
\end{document}

The differences are that I'm using PGFPlots compatibility 1.9 and Stefan's original code used 1.8 (which doesn't make a difference, I've checked), that I only have one cylinder, that x now ranges from -10 to 10 (both in the "plot" and in Tube.txt) (this doesn't make a difference either, I've tried going back to 1.618), that I've renamed the "gauss_prob" column to "prob" in Tube.txt and that I've removed the code to generate Tube.txt at the top (because I've generated the file another way).

What am I doing wrong?

Thanks in advance.

2

Add mesh/rows=21 to the my addplot style options and it will work.

(Have a look at the corresponding comment in the code for more details.)

\documentclass[border=5pt,varwidth]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
    compat=1.14,
    colormap={CM}{
        color=(green)
        color=(red)
    },
    my axis style/.style={
        xmin=-10,
        xmax=10,
        ymin=-4,
        ymax=4,
        zmin=-4,
        zmax=4,
        hide axis,
        z buffer=sort,
    },
    my addplot style/.style={
        surf,
        line join=round,
        shader=flat corner,
        draw=black,
        point meta=explicit,
        % because you don't have empty lines in your data file, you have to
        % "help" PGFPlots how to interpret it. So either specify the number of
        % rows or the number of columns you have in the data file.
        mesh/rows=21,
    },
    my table style/.style={
        /pgfplots/table/.cd,
            x=x,
            y=y,
            z=z,
    },
}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[my axis style]
            \addplot3 [my addplot style] table [
                my table style,
                meta=prob,
            ] {Tube.txt};
        \end{axis}
    \end{tikzpicture}
\end{document}

image showing the result of above code

  • Ah, thank you! This works. I finally have what I wanted! :) – Rain Nov 28 '16 at 22:38

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.