Wrong tick on colorbar












2















I am writing a function to generate a legend in beamer based on:




  • the position on the page

  • the max and min value

  • the colormap to use


Here is an example:



documentclass[table]{beamer}

usepackage{tikz,pgfplots}
usetikzlibrary{calc}
usetikzlibrary{backgrounds}

% Colormaps
pgfplotsset{
colormap={Legend1}{
rgb255=(255, 113, 0),
rgb255=(255, 227, 0),
rgb255=(170, 255, 0),
rgb255=( 57, 255, 0),
rgb255=( 40, 255, 185),
rgb255=( 0, 199, 221),
rgb255=( 21, 121, 255),
}
}

% Len of above/below triangle
deflen{0.75cm}

% Horizontal Legend
newcommand{LegendH}[4]{
begin{tikzpicture}[remember picture,overlay]
% Min/Max/Colormap
pgfmathsetmacro{Min}{#2}
pgfmathsetmacro{Max}{#3}
defcolormap{#4}

% Tick distance
pgfmathsetmacro{XTickDistance}{
(Min - Max) / pgfplotscolormapsizeof{colormap}
}

% Above/Below
ifnumpdfstrcmp{colormap}{Legend1}=0
definecolor{Lcolor}{RGB}{192, 192, 192}
definecolor{Rcolor}{RGB}{255, 0, 0}
defprecision{2}
fi

% Axis
begin{axis}[
hide axis, scale only axis, height=0pt, width=0pt, % hide axis
colormap name = colormap,
colorbar sampled,
colorbar horizontal,
point meta min=Min,
point meta max=Max,
colorbar style = {
name = cb,
at={(#1)}, anchor=center,
samples = pgfplotscolormapsizeof{colormap} + 1,
height = 0.5cm,
width = 10cm,
xtick style = {draw=none},
xticklabel style = {
text width = 2.5em,
align = center,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision = precision,
/tikz/.cd
},
xtick distance=XTickDistance,
}
]
addplot [draw=none] coordinates {(0,0)};
end{axis}

% Above/Below triangle
foreach i/j in {south east/a, north east/b, north west/c, south west/d}
{coordinate (j) at (current colorbar axis.i);}
filldraw[fill=Lcolor] (a) -- ($(a)!0.5!(b)+(len,0)$) -- (b);
filldraw[fill=Rcolor] (c) -- ($(c)!0.5!(d)+(-len,0)$)-- (d);

% Background
scoped[on background layer]
fill [white] ([shift={(-0.25cm,-0.5cm)}]cb.outer south west) rectangle ([shift={(+0.0cm,+0.5cm)}]cb.outer north east);
end{tikzpicture}
}

begin{document}
begin{frame}{Legend}
LegendH{$(current page.center)+(0cm, -2cm)$}{1.0}{2.0}{Legend1}
LegendH{$(current page.center)+(0cm, +0cm)$}{1.0}{3.0}{Legend1}
end{frame}
end{document}


This is what I get:
Result



As you can see the lower legend (between 1 and 2) is right.



The upper one is wrong: should start on 1 and end on 3, the ticks should be 1.00, 1.29, 1.57, 1.86, 2.14, 2.43, 2.71, 3.00.



I don't understand why there is this odd behavior.



Thanks










share|improve this question

























  • The manual says that the legend is typeset by a addplot3. (page 284). You probably can draw such a bar with simpler construction. Such as addplot or TikZ's foreach.

    – Symbol 1
    Jan 28 '17 at 16:56











  • Sorry but I don't understand when you say that I should use addplot? The above code use addplot not addplot3.

    – yellowhat
    Feb 4 '17 at 11:35
















2















I am writing a function to generate a legend in beamer based on:




  • the position on the page

  • the max and min value

  • the colormap to use


Here is an example:



documentclass[table]{beamer}

usepackage{tikz,pgfplots}
usetikzlibrary{calc}
usetikzlibrary{backgrounds}

% Colormaps
pgfplotsset{
colormap={Legend1}{
rgb255=(255, 113, 0),
rgb255=(255, 227, 0),
rgb255=(170, 255, 0),
rgb255=( 57, 255, 0),
rgb255=( 40, 255, 185),
rgb255=( 0, 199, 221),
rgb255=( 21, 121, 255),
}
}

% Len of above/below triangle
deflen{0.75cm}

% Horizontal Legend
newcommand{LegendH}[4]{
begin{tikzpicture}[remember picture,overlay]
% Min/Max/Colormap
pgfmathsetmacro{Min}{#2}
pgfmathsetmacro{Max}{#3}
defcolormap{#4}

% Tick distance
pgfmathsetmacro{XTickDistance}{
(Min - Max) / pgfplotscolormapsizeof{colormap}
}

% Above/Below
ifnumpdfstrcmp{colormap}{Legend1}=0
definecolor{Lcolor}{RGB}{192, 192, 192}
definecolor{Rcolor}{RGB}{255, 0, 0}
defprecision{2}
fi

% Axis
begin{axis}[
hide axis, scale only axis, height=0pt, width=0pt, % hide axis
colormap name = colormap,
colorbar sampled,
colorbar horizontal,
point meta min=Min,
point meta max=Max,
colorbar style = {
name = cb,
at={(#1)}, anchor=center,
samples = pgfplotscolormapsizeof{colormap} + 1,
height = 0.5cm,
width = 10cm,
xtick style = {draw=none},
xticklabel style = {
text width = 2.5em,
align = center,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision = precision,
/tikz/.cd
},
xtick distance=XTickDistance,
}
]
addplot [draw=none] coordinates {(0,0)};
end{axis}

% Above/Below triangle
foreach i/j in {south east/a, north east/b, north west/c, south west/d}
{coordinate (j) at (current colorbar axis.i);}
filldraw[fill=Lcolor] (a) -- ($(a)!0.5!(b)+(len,0)$) -- (b);
filldraw[fill=Rcolor] (c) -- ($(c)!0.5!(d)+(-len,0)$)-- (d);

% Background
scoped[on background layer]
fill [white] ([shift={(-0.25cm,-0.5cm)}]cb.outer south west) rectangle ([shift={(+0.0cm,+0.5cm)}]cb.outer north east);
end{tikzpicture}
}

begin{document}
begin{frame}{Legend}
LegendH{$(current page.center)+(0cm, -2cm)$}{1.0}{2.0}{Legend1}
LegendH{$(current page.center)+(0cm, +0cm)$}{1.0}{3.0}{Legend1}
end{frame}
end{document}


This is what I get:
Result



As you can see the lower legend (between 1 and 2) is right.



The upper one is wrong: should start on 1 and end on 3, the ticks should be 1.00, 1.29, 1.57, 1.86, 2.14, 2.43, 2.71, 3.00.



I don't understand why there is this odd behavior.



Thanks










share|improve this question

























  • The manual says that the legend is typeset by a addplot3. (page 284). You probably can draw such a bar with simpler construction. Such as addplot or TikZ's foreach.

    – Symbol 1
    Jan 28 '17 at 16:56











  • Sorry but I don't understand when you say that I should use addplot? The above code use addplot not addplot3.

    – yellowhat
    Feb 4 '17 at 11:35














2












2








2








I am writing a function to generate a legend in beamer based on:




  • the position on the page

  • the max and min value

  • the colormap to use


Here is an example:



documentclass[table]{beamer}

usepackage{tikz,pgfplots}
usetikzlibrary{calc}
usetikzlibrary{backgrounds}

% Colormaps
pgfplotsset{
colormap={Legend1}{
rgb255=(255, 113, 0),
rgb255=(255, 227, 0),
rgb255=(170, 255, 0),
rgb255=( 57, 255, 0),
rgb255=( 40, 255, 185),
rgb255=( 0, 199, 221),
rgb255=( 21, 121, 255),
}
}

% Len of above/below triangle
deflen{0.75cm}

% Horizontal Legend
newcommand{LegendH}[4]{
begin{tikzpicture}[remember picture,overlay]
% Min/Max/Colormap
pgfmathsetmacro{Min}{#2}
pgfmathsetmacro{Max}{#3}
defcolormap{#4}

% Tick distance
pgfmathsetmacro{XTickDistance}{
(Min - Max) / pgfplotscolormapsizeof{colormap}
}

% Above/Below
ifnumpdfstrcmp{colormap}{Legend1}=0
definecolor{Lcolor}{RGB}{192, 192, 192}
definecolor{Rcolor}{RGB}{255, 0, 0}
defprecision{2}
fi

% Axis
begin{axis}[
hide axis, scale only axis, height=0pt, width=0pt, % hide axis
colormap name = colormap,
colorbar sampled,
colorbar horizontal,
point meta min=Min,
point meta max=Max,
colorbar style = {
name = cb,
at={(#1)}, anchor=center,
samples = pgfplotscolormapsizeof{colormap} + 1,
height = 0.5cm,
width = 10cm,
xtick style = {draw=none},
xticklabel style = {
text width = 2.5em,
align = center,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision = precision,
/tikz/.cd
},
xtick distance=XTickDistance,
}
]
addplot [draw=none] coordinates {(0,0)};
end{axis}

% Above/Below triangle
foreach i/j in {south east/a, north east/b, north west/c, south west/d}
{coordinate (j) at (current colorbar axis.i);}
filldraw[fill=Lcolor] (a) -- ($(a)!0.5!(b)+(len,0)$) -- (b);
filldraw[fill=Rcolor] (c) -- ($(c)!0.5!(d)+(-len,0)$)-- (d);

% Background
scoped[on background layer]
fill [white] ([shift={(-0.25cm,-0.5cm)}]cb.outer south west) rectangle ([shift={(+0.0cm,+0.5cm)}]cb.outer north east);
end{tikzpicture}
}

begin{document}
begin{frame}{Legend}
LegendH{$(current page.center)+(0cm, -2cm)$}{1.0}{2.0}{Legend1}
LegendH{$(current page.center)+(0cm, +0cm)$}{1.0}{3.0}{Legend1}
end{frame}
end{document}


This is what I get:
Result



As you can see the lower legend (between 1 and 2) is right.



The upper one is wrong: should start on 1 and end on 3, the ticks should be 1.00, 1.29, 1.57, 1.86, 2.14, 2.43, 2.71, 3.00.



I don't understand why there is this odd behavior.



Thanks










share|improve this question
















I am writing a function to generate a legend in beamer based on:




  • the position on the page

  • the max and min value

  • the colormap to use


Here is an example:



documentclass[table]{beamer}

usepackage{tikz,pgfplots}
usetikzlibrary{calc}
usetikzlibrary{backgrounds}

% Colormaps
pgfplotsset{
colormap={Legend1}{
rgb255=(255, 113, 0),
rgb255=(255, 227, 0),
rgb255=(170, 255, 0),
rgb255=( 57, 255, 0),
rgb255=( 40, 255, 185),
rgb255=( 0, 199, 221),
rgb255=( 21, 121, 255),
}
}

% Len of above/below triangle
deflen{0.75cm}

% Horizontal Legend
newcommand{LegendH}[4]{
begin{tikzpicture}[remember picture,overlay]
% Min/Max/Colormap
pgfmathsetmacro{Min}{#2}
pgfmathsetmacro{Max}{#3}
defcolormap{#4}

% Tick distance
pgfmathsetmacro{XTickDistance}{
(Min - Max) / pgfplotscolormapsizeof{colormap}
}

% Above/Below
ifnumpdfstrcmp{colormap}{Legend1}=0
definecolor{Lcolor}{RGB}{192, 192, 192}
definecolor{Rcolor}{RGB}{255, 0, 0}
defprecision{2}
fi

% Axis
begin{axis}[
hide axis, scale only axis, height=0pt, width=0pt, % hide axis
colormap name = colormap,
colorbar sampled,
colorbar horizontal,
point meta min=Min,
point meta max=Max,
colorbar style = {
name = cb,
at={(#1)}, anchor=center,
samples = pgfplotscolormapsizeof{colormap} + 1,
height = 0.5cm,
width = 10cm,
xtick style = {draw=none},
xticklabel style = {
text width = 2.5em,
align = center,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision = precision,
/tikz/.cd
},
xtick distance=XTickDistance,
}
]
addplot [draw=none] coordinates {(0,0)};
end{axis}

% Above/Below triangle
foreach i/j in {south east/a, north east/b, north west/c, south west/d}
{coordinate (j) at (current colorbar axis.i);}
filldraw[fill=Lcolor] (a) -- ($(a)!0.5!(b)+(len,0)$) -- (b);
filldraw[fill=Rcolor] (c) -- ($(c)!0.5!(d)+(-len,0)$)-- (d);

% Background
scoped[on background layer]
fill [white] ([shift={(-0.25cm,-0.5cm)}]cb.outer south west) rectangle ([shift={(+0.0cm,+0.5cm)}]cb.outer north east);
end{tikzpicture}
}

begin{document}
begin{frame}{Legend}
LegendH{$(current page.center)+(0cm, -2cm)$}{1.0}{2.0}{Legend1}
LegendH{$(current page.center)+(0cm, +0cm)$}{1.0}{3.0}{Legend1}
end{frame}
end{document}


This is what I get:
Result



As you can see the lower legend (between 1 and 2) is right.



The upper one is wrong: should start on 1 and end on 3, the ticks should be 1.00, 1.29, 1.57, 1.86, 2.14, 2.43, 2.71, 3.00.



I don't understand why there is this odd behavior.



Thanks







tikz-pgf legend






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 34 mins ago









JouleV

4,5441938




4,5441938










asked Jan 28 '17 at 12:07









yellowhatyellowhat

1366




1366













  • The manual says that the legend is typeset by a addplot3. (page 284). You probably can draw such a bar with simpler construction. Such as addplot or TikZ's foreach.

    – Symbol 1
    Jan 28 '17 at 16:56











  • Sorry but I don't understand when you say that I should use addplot? The above code use addplot not addplot3.

    – yellowhat
    Feb 4 '17 at 11:35



















  • The manual says that the legend is typeset by a addplot3. (page 284). You probably can draw such a bar with simpler construction. Such as addplot or TikZ's foreach.

    – Symbol 1
    Jan 28 '17 at 16:56











  • Sorry but I don't understand when you say that I should use addplot? The above code use addplot not addplot3.

    – yellowhat
    Feb 4 '17 at 11:35

















The manual says that the legend is typeset by a addplot3. (page 284). You probably can draw such a bar with simpler construction. Such as addplot or TikZ's foreach.

– Symbol 1
Jan 28 '17 at 16:56





The manual says that the legend is typeset by a addplot3. (page 284). You probably can draw such a bar with simpler construction. Such as addplot or TikZ's foreach.

– Symbol 1
Jan 28 '17 at 16:56













Sorry but I don't understand when you say that I should use addplot? The above code use addplot not addplot3.

– yellowhat
Feb 4 '17 at 11:35





Sorry but I don't understand when you say that I should use addplot? The above code use addplot not addplot3.

– yellowhat
Feb 4 '17 at 11:35










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f350865%2fwrong-tick-on-colorbar%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f350865%2fwrong-tick-on-colorbar%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

Insert data from modal to MySQL (multiple modal on website)

count number of partitions of a set with n elements into k subsets