5
  1. I would like the ticks of the colormap from the first picture below to show the maximum and minimum of the data like in the second picture, in this case 1.35 and -0.26. I know I can do it through uncommenting the line which has extra y ticks=..., but I want to do it automatically.

    What I have:

    what I have

    What I want (automatically):

    what I (automatically) want

  2. I would like to only show one integer after the decimal point only for the minimum and maximum (in this case 1.3 and -0.2). But this isn't crucial, since I can round my data in Matlab, but I'd like to avoid that.

    \documentclass{article}
    \usepackage{tikz,pgfplots}
    \pgfplotsset{compat=1.13}
    \usepgfplotslibrary{patchplots}
    \begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    small,
    view={0}{90},
    colorbar,
    colorbar style={
            %extra y ticks={-0.26,1.35}
    }
    ]
    \addplot3[surf,shader=interp,patch type=bilinear]
    coordinates {
    (0,0,-0.26) (1,0,0)
    
    (0,1,0) (1,1,1.35)
    };
    \end{axis}
    \end{tikzpicture}
    \end{document}
    

edit:

In the real application i am importing data from matlab, so simply defining a variable, which could be a half-automatic solution in this example, isnt possible.

1 Answer 1

3

You can get the minimum and maximum values with \pgfkeysvalueof{/pgfplots/ymin} and \pgfkeysvalueof{/pgfplots/ymax}}

I only have TL 2015 so I need 1.12, but I don't see why this wouldn't work in 1.13

\documentclass{article}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.12}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
small,
view={0}{90},
colorbar,
colorbar style={
        extra y ticks={\pgfkeysvalueof{/pgfplots/ymin},\pgfkeysvalueof{/pgfplots/ymax}}
}
]
\addplot3[surf,shader=interp,patch type=bilinear]
coordinates {
(0,0,-0.26) (1,0,0)

(0,1,0) (1,1,1.35)
};
\end{axis}
\end{tikzpicture}
\end{document}
3
  • unbelievably fast and correct. this site is a blessing. 2. Part is, like i said, not crucial, i will round in matlab. thanks a lot man!
    – loosa2
    Commented Jul 5, 2016 at 18:40
  • 1
    @loosa2 I missed part 2. You could do something like y tick label style = {/pgf/number format/.cd, fixed, precision=1} to get -.03 and 1.4 (i.e., it rounds instead of flooring and ceiling). There are a fair number of questions on the number formatting in PGF (e.g., tex.stackexchange.com/questions/96347/…). If you do not find something, it seems like a reasonable follow on question.
    – StrongBad
    Commented Jul 5, 2016 at 18:57
  • i solved the rounding problem via http://tex.stackexchange.com/questions/315571/rounding-off-before-plotting/315659#315659. With that macro i can round certain numbers.
    – loosa2
    Commented Jul 5, 2016 at 19:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .