How to customize contour line labels?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I would like to visualize a function of two variables in a contour plot using Octave, and to put customized line labels on it.



Building on the Octave documentation, I wrote:



clf;
colormap ("default");
[x, y, z] = peaks ();
subplot(2,1,1);
contour (x, y, z,'showtext', 'on');
title ({"contour() plot, showtext on"; "Z = peaks()"});
subplot(2,1,2);
[ctr, h] = contour (x, y, z);
cll = clabel(ctr, h, 'backgroundcolor',[1 1 1]);
title ({"contour() plot, using clabel()"; "Z = peaks()"});


Two more or less identical plots produced by the code snippet above



Which produces two only marginally (if at all) different plots. The labels are there, but don't look nice at all; I need better quality for this project.



What I would like to do is, in order of priority:




  1. Show labels with 2 - 3 decimal digits only.

  2. Change the label background to white.

  3. Plot labels inline with the contour line.


From Octave documentation it appears that the label values are stored in "userdata", but it's not of much help because:



>> get(cll, "userdata")
ans =
{
[1,1] = 6.7459
[2,1] = 5.4167
[3,1] = 5.4167
[4,1] = 4.0874
[5,1] = 4.0874
[6,1] = 2.7581
[7,1] = 2.7581
[8,1] = 2.7581
[9,1] = 2.7581
[10,1] = 1.4289
[11,1] = 1.4289
[12,1] = 1.4289
[13,1] = 1.4289
[14,1] = 0.099636
[15,1] = 0.099636
[16,1] = 0.099636
[17,1] = 0.099636
[18,1] = 0.099636
[19,1] = 0.099636
[20,1] = -1.2296
[21,1] = -1.2296
[22,1] = -1.2296
[23,1] = -1.2296
[24,1] = -2.5589
[25,1] = -2.5589
[26,1] = -2.5589
[27,1] = -3.8881
[28,1] = -5.2174


I am not sure how the number of repetitions for a value is determined.
I'd appreciate help on this matter.










share|improve this question

























  • That matches the number of times each value is shown -- longer lines can fit more labels.

    – Cris Luengo
    Nov 24 '18 at 5:14


















1















I would like to visualize a function of two variables in a contour plot using Octave, and to put customized line labels on it.



Building on the Octave documentation, I wrote:



clf;
colormap ("default");
[x, y, z] = peaks ();
subplot(2,1,1);
contour (x, y, z,'showtext', 'on');
title ({"contour() plot, showtext on"; "Z = peaks()"});
subplot(2,1,2);
[ctr, h] = contour (x, y, z);
cll = clabel(ctr, h, 'backgroundcolor',[1 1 1]);
title ({"contour() plot, using clabel()"; "Z = peaks()"});


Two more or less identical plots produced by the code snippet above



Which produces two only marginally (if at all) different plots. The labels are there, but don't look nice at all; I need better quality for this project.



What I would like to do is, in order of priority:




  1. Show labels with 2 - 3 decimal digits only.

  2. Change the label background to white.

  3. Plot labels inline with the contour line.


From Octave documentation it appears that the label values are stored in "userdata", but it's not of much help because:



>> get(cll, "userdata")
ans =
{
[1,1] = 6.7459
[2,1] = 5.4167
[3,1] = 5.4167
[4,1] = 4.0874
[5,1] = 4.0874
[6,1] = 2.7581
[7,1] = 2.7581
[8,1] = 2.7581
[9,1] = 2.7581
[10,1] = 1.4289
[11,1] = 1.4289
[12,1] = 1.4289
[13,1] = 1.4289
[14,1] = 0.099636
[15,1] = 0.099636
[16,1] = 0.099636
[17,1] = 0.099636
[18,1] = 0.099636
[19,1] = 0.099636
[20,1] = -1.2296
[21,1] = -1.2296
[22,1] = -1.2296
[23,1] = -1.2296
[24,1] = -2.5589
[25,1] = -2.5589
[26,1] = -2.5589
[27,1] = -3.8881
[28,1] = -5.2174


I am not sure how the number of repetitions for a value is determined.
I'd appreciate help on this matter.










share|improve this question

























  • That matches the number of times each value is shown -- longer lines can fit more labels.

    – Cris Luengo
    Nov 24 '18 at 5:14














1












1








1








I would like to visualize a function of two variables in a contour plot using Octave, and to put customized line labels on it.



Building on the Octave documentation, I wrote:



clf;
colormap ("default");
[x, y, z] = peaks ();
subplot(2,1,1);
contour (x, y, z,'showtext', 'on');
title ({"contour() plot, showtext on"; "Z = peaks()"});
subplot(2,1,2);
[ctr, h] = contour (x, y, z);
cll = clabel(ctr, h, 'backgroundcolor',[1 1 1]);
title ({"contour() plot, using clabel()"; "Z = peaks()"});


Two more or less identical plots produced by the code snippet above



Which produces two only marginally (if at all) different plots. The labels are there, but don't look nice at all; I need better quality for this project.



What I would like to do is, in order of priority:




  1. Show labels with 2 - 3 decimal digits only.

  2. Change the label background to white.

  3. Plot labels inline with the contour line.


From Octave documentation it appears that the label values are stored in "userdata", but it's not of much help because:



>> get(cll, "userdata")
ans =
{
[1,1] = 6.7459
[2,1] = 5.4167
[3,1] = 5.4167
[4,1] = 4.0874
[5,1] = 4.0874
[6,1] = 2.7581
[7,1] = 2.7581
[8,1] = 2.7581
[9,1] = 2.7581
[10,1] = 1.4289
[11,1] = 1.4289
[12,1] = 1.4289
[13,1] = 1.4289
[14,1] = 0.099636
[15,1] = 0.099636
[16,1] = 0.099636
[17,1] = 0.099636
[18,1] = 0.099636
[19,1] = 0.099636
[20,1] = -1.2296
[21,1] = -1.2296
[22,1] = -1.2296
[23,1] = -1.2296
[24,1] = -2.5589
[25,1] = -2.5589
[26,1] = -2.5589
[27,1] = -3.8881
[28,1] = -5.2174


I am not sure how the number of repetitions for a value is determined.
I'd appreciate help on this matter.










share|improve this question
















I would like to visualize a function of two variables in a contour plot using Octave, and to put customized line labels on it.



Building on the Octave documentation, I wrote:



clf;
colormap ("default");
[x, y, z] = peaks ();
subplot(2,1,1);
contour (x, y, z,'showtext', 'on');
title ({"contour() plot, showtext on"; "Z = peaks()"});
subplot(2,1,2);
[ctr, h] = contour (x, y, z);
cll = clabel(ctr, h, 'backgroundcolor',[1 1 1]);
title ({"contour() plot, using clabel()"; "Z = peaks()"});


Two more or less identical plots produced by the code snippet above



Which produces two only marginally (if at all) different plots. The labels are there, but don't look nice at all; I need better quality for this project.



What I would like to do is, in order of priority:




  1. Show labels with 2 - 3 decimal digits only.

  2. Change the label background to white.

  3. Plot labels inline with the contour line.


From Octave documentation it appears that the label values are stored in "userdata", but it's not of much help because:



>> get(cll, "userdata")
ans =
{
[1,1] = 6.7459
[2,1] = 5.4167
[3,1] = 5.4167
[4,1] = 4.0874
[5,1] = 4.0874
[6,1] = 2.7581
[7,1] = 2.7581
[8,1] = 2.7581
[9,1] = 2.7581
[10,1] = 1.4289
[11,1] = 1.4289
[12,1] = 1.4289
[13,1] = 1.4289
[14,1] = 0.099636
[15,1] = 0.099636
[16,1] = 0.099636
[17,1] = 0.099636
[18,1] = 0.099636
[19,1] = 0.099636
[20,1] = -1.2296
[21,1] = -1.2296
[22,1] = -1.2296
[23,1] = -1.2296
[24,1] = -2.5589
[25,1] = -2.5589
[26,1] = -2.5589
[27,1] = -3.8881
[28,1] = -5.2174


I am not sure how the number of repetitions for a value is determined.
I'd appreciate help on this matter.







label octave contour






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 5:11









Cris Luengo

23k52254




23k52254










asked Nov 24 '18 at 3:16









Fabio CapezzuoliFabio Capezzuoli

13312




13312













  • That matches the number of times each value is shown -- longer lines can fit more labels.

    – Cris Luengo
    Nov 24 '18 at 5:14



















  • That matches the number of times each value is shown -- longer lines can fit more labels.

    – Cris Luengo
    Nov 24 '18 at 5:14

















That matches the number of times each value is shown -- longer lines can fit more labels.

– Cris Luengo
Nov 24 '18 at 5:14





That matches the number of times each value is shown -- longer lines can fit more labels.

– Cris Luengo
Nov 24 '18 at 5:14












2 Answers
2






active

oldest

votes


















1














To show labels with fewer digits, the best way is to manually specify at which z-values to draw contour lines (see explanation in the documentation to contourc):



colormap('default');
[x, y, z] = peaks();
vn = ceil(min(z(:))):floor(max(z(:))); % list of all integer values within range of data
contour(x, y, z, vn, 'showtext', 'on');
title({"contour() plot, showtext on"; "Z = peaks()"});


You can also specify which contour lines to put labels on:



colormap('default');
[x, y, z] = peaks();
vn = ceil(min(z(:))):floor(max(z(:)));
[ctr, h] = contour(x, y, z, vn);
clabel(ctr, h, vn(1:2:end), 'backgroundcolor',[1 1 1]);
title({"contour() plot, showtext on"; "Z = peaks()"});


I don't have Octave here, but the 'background color' argument should do its thing. It is possible that the lines are drawn over the text, rather than the text over the lines. MATLAB has a command uistack to force drawing order, but this does not seem to exist in Octave. There, one possibility might be to change the order of the children of the axis object:



set(gca,'children',flip(get(gca,'children')))


(Note: MATLAB's contour does a better job of picking nice contour levels, and it also by default interrupts the line where the labels are, so lines and text don't intersect.)






share|improve this answer
























  • Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:

    – Fabio Capezzuoli
    Nov 24 '18 at 14:08



















0














Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:



enter image description here



Which is good for my needs, except for that lonely "0.09" in the left part of the plot. That shouldn't be there but I cannot figure why it appears.



set(gca,'children',flip(get(gca,'children'))) does not work tho.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2fstackoverflow.com%2fquestions%2f53454873%2fhow-to-customize-contour-line-labels%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    To show labels with fewer digits, the best way is to manually specify at which z-values to draw contour lines (see explanation in the documentation to contourc):



    colormap('default');
    [x, y, z] = peaks();
    vn = ceil(min(z(:))):floor(max(z(:))); % list of all integer values within range of data
    contour(x, y, z, vn, 'showtext', 'on');
    title({"contour() plot, showtext on"; "Z = peaks()"});


    You can also specify which contour lines to put labels on:



    colormap('default');
    [x, y, z] = peaks();
    vn = ceil(min(z(:))):floor(max(z(:)));
    [ctr, h] = contour(x, y, z, vn);
    clabel(ctr, h, vn(1:2:end), 'backgroundcolor',[1 1 1]);
    title({"contour() plot, showtext on"; "Z = peaks()"});


    I don't have Octave here, but the 'background color' argument should do its thing. It is possible that the lines are drawn over the text, rather than the text over the lines. MATLAB has a command uistack to force drawing order, but this does not seem to exist in Octave. There, one possibility might be to change the order of the children of the axis object:



    set(gca,'children',flip(get(gca,'children')))


    (Note: MATLAB's contour does a better job of picking nice contour levels, and it also by default interrupts the line where the labels are, so lines and text don't intersect.)






    share|improve this answer
























    • Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:

      – Fabio Capezzuoli
      Nov 24 '18 at 14:08
















    1














    To show labels with fewer digits, the best way is to manually specify at which z-values to draw contour lines (see explanation in the documentation to contourc):



    colormap('default');
    [x, y, z] = peaks();
    vn = ceil(min(z(:))):floor(max(z(:))); % list of all integer values within range of data
    contour(x, y, z, vn, 'showtext', 'on');
    title({"contour() plot, showtext on"; "Z = peaks()"});


    You can also specify which contour lines to put labels on:



    colormap('default');
    [x, y, z] = peaks();
    vn = ceil(min(z(:))):floor(max(z(:)));
    [ctr, h] = contour(x, y, z, vn);
    clabel(ctr, h, vn(1:2:end), 'backgroundcolor',[1 1 1]);
    title({"contour() plot, showtext on"; "Z = peaks()"});


    I don't have Octave here, but the 'background color' argument should do its thing. It is possible that the lines are drawn over the text, rather than the text over the lines. MATLAB has a command uistack to force drawing order, but this does not seem to exist in Octave. There, one possibility might be to change the order of the children of the axis object:



    set(gca,'children',flip(get(gca,'children')))


    (Note: MATLAB's contour does a better job of picking nice contour levels, and it also by default interrupts the line where the labels are, so lines and text don't intersect.)






    share|improve this answer
























    • Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:

      – Fabio Capezzuoli
      Nov 24 '18 at 14:08














    1












    1








    1







    To show labels with fewer digits, the best way is to manually specify at which z-values to draw contour lines (see explanation in the documentation to contourc):



    colormap('default');
    [x, y, z] = peaks();
    vn = ceil(min(z(:))):floor(max(z(:))); % list of all integer values within range of data
    contour(x, y, z, vn, 'showtext', 'on');
    title({"contour() plot, showtext on"; "Z = peaks()"});


    You can also specify which contour lines to put labels on:



    colormap('default');
    [x, y, z] = peaks();
    vn = ceil(min(z(:))):floor(max(z(:)));
    [ctr, h] = contour(x, y, z, vn);
    clabel(ctr, h, vn(1:2:end), 'backgroundcolor',[1 1 1]);
    title({"contour() plot, showtext on"; "Z = peaks()"});


    I don't have Octave here, but the 'background color' argument should do its thing. It is possible that the lines are drawn over the text, rather than the text over the lines. MATLAB has a command uistack to force drawing order, but this does not seem to exist in Octave. There, one possibility might be to change the order of the children of the axis object:



    set(gca,'children',flip(get(gca,'children')))


    (Note: MATLAB's contour does a better job of picking nice contour levels, and it also by default interrupts the line where the labels are, so lines and text don't intersect.)






    share|improve this answer













    To show labels with fewer digits, the best way is to manually specify at which z-values to draw contour lines (see explanation in the documentation to contourc):



    colormap('default');
    [x, y, z] = peaks();
    vn = ceil(min(z(:))):floor(max(z(:))); % list of all integer values within range of data
    contour(x, y, z, vn, 'showtext', 'on');
    title({"contour() plot, showtext on"; "Z = peaks()"});


    You can also specify which contour lines to put labels on:



    colormap('default');
    [x, y, z] = peaks();
    vn = ceil(min(z(:))):floor(max(z(:)));
    [ctr, h] = contour(x, y, z, vn);
    clabel(ctr, h, vn(1:2:end), 'backgroundcolor',[1 1 1]);
    title({"contour() plot, showtext on"; "Z = peaks()"});


    I don't have Octave here, but the 'background color' argument should do its thing. It is possible that the lines are drawn over the text, rather than the text over the lines. MATLAB has a command uistack to force drawing order, but this does not seem to exist in Octave. There, one possibility might be to change the order of the children of the axis object:



    set(gca,'children',flip(get(gca,'children')))


    (Note: MATLAB's contour does a better job of picking nice contour levels, and it also by default interrupts the line where the labels are, so lines and text don't intersect.)







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 24 '18 at 5:43









    Cris LuengoCris Luengo

    23k52254




    23k52254













    • Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:

      – Fabio Capezzuoli
      Nov 24 '18 at 14:08



















    • Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:

      – Fabio Capezzuoli
      Nov 24 '18 at 14:08

















    Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:

    – Fabio Capezzuoli
    Nov 24 '18 at 14:08





    Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:

    – Fabio Capezzuoli
    Nov 24 '18 at 14:08













    0














    Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:



    enter image description here



    Which is good for my needs, except for that lonely "0.09" in the left part of the plot. That shouldn't be there but I cannot figure why it appears.



    set(gca,'children',flip(get(gca,'children'))) does not work tho.






    share|improve this answer




























      0














      Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:



      enter image description here



      Which is good for my needs, except for that lonely "0.09" in the left part of the plot. That shouldn't be there but I cannot figure why it appears.



      set(gca,'children',flip(get(gca,'children'))) does not work tho.






      share|improve this answer


























        0












        0








        0







        Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:



        enter image description here



        Which is good for my needs, except for that lonely "0.09" in the left part of the plot. That shouldn't be there but I cannot figure why it appears.



        set(gca,'children',flip(get(gca,'children'))) does not work tho.






        share|improve this answer













        Well, I used your suggestions and tinkered a bit more with my real data, to obtain this plot:



        enter image description here



        Which is good for my needs, except for that lonely "0.09" in the left part of the plot. That shouldn't be there but I cannot figure why it appears.



        set(gca,'children',flip(get(gca,'children'))) does not work tho.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 14:42









        Fabio CapezzuoliFabio Capezzuoli

        13312




        13312






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • 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%2fstackoverflow.com%2fquestions%2f53454873%2fhow-to-customize-contour-line-labels%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







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini