Combining LineLegend and BarLegend in CountourPlot

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite












So I am having a similar problem to the one in this question but the solutions therein are of no use.



Consider a basic ContourPlot with an automatic BarLegend



ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
PlotLegends -> BarLegend[Automatic],
Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


which gives the following, nice ContourPlot:



https://imgur.com/KV5kD1m



However, when I try and add a LineLegend for the Epilog, ContourPlot cannot do so automatically. I have tried all suggestions in the link above and none of them work



ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
PlotLegends ->
Column[BarLegend[Automatic],
LineLegend[Directive[Red], "Test"]],
Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


https://imgur.com/OP9Mzoa



How do I fix this? I want the BarLegend to be automatic, since it provides a nice, simple fit of values. However, even manually I have had no success with BarLegend not evaluating.



(As a sidenote, imgur is not accepting the pictures I have provided. Have put up links, if someone can fix, would be grateful).







share|improve this question
























    up vote
    6
    down vote

    favorite












    So I am having a similar problem to the one in this question but the solutions therein are of no use.



    Consider a basic ContourPlot with an automatic BarLegend



    ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
    PlotLegends -> BarLegend[Automatic],
    Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


    which gives the following, nice ContourPlot:



    https://imgur.com/KV5kD1m



    However, when I try and add a LineLegend for the Epilog, ContourPlot cannot do so automatically. I have tried all suggestions in the link above and none of them work



    ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
    PlotLegends ->
    Column[BarLegend[Automatic],
    LineLegend[Directive[Red], "Test"]],
    Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


    https://imgur.com/OP9Mzoa



    How do I fix this? I want the BarLegend to be automatic, since it provides a nice, simple fit of values. However, even manually I have had no success with BarLegend not evaluating.



    (As a sidenote, imgur is not accepting the pictures I have provided. Have put up links, if someone can fix, would be grateful).







    share|improve this question






















      up vote
      6
      down vote

      favorite









      up vote
      6
      down vote

      favorite











      So I am having a similar problem to the one in this question but the solutions therein are of no use.



      Consider a basic ContourPlot with an automatic BarLegend



      ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
      PlotLegends -> BarLegend[Automatic],
      Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


      which gives the following, nice ContourPlot:



      https://imgur.com/KV5kD1m



      However, when I try and add a LineLegend for the Epilog, ContourPlot cannot do so automatically. I have tried all suggestions in the link above and none of them work



      ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
      PlotLegends ->
      Column[BarLegend[Automatic],
      LineLegend[Directive[Red], "Test"]],
      Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


      https://imgur.com/OP9Mzoa



      How do I fix this? I want the BarLegend to be automatic, since it provides a nice, simple fit of values. However, even manually I have had no success with BarLegend not evaluating.



      (As a sidenote, imgur is not accepting the pictures I have provided. Have put up links, if someone can fix, would be grateful).







      share|improve this question












      So I am having a similar problem to the one in this question but the solutions therein are of no use.



      Consider a basic ContourPlot with an automatic BarLegend



      ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
      PlotLegends -> BarLegend[Automatic],
      Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


      which gives the following, nice ContourPlot:



      https://imgur.com/KV5kD1m



      However, when I try and add a LineLegend for the Epilog, ContourPlot cannot do so automatically. I have tried all suggestions in the link above and none of them work



      ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
      PlotLegends ->
      Column[BarLegend[Automatic],
      LineLegend[Directive[Red], "Test"]],
      Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


      https://imgur.com/OP9Mzoa



      How do I fix this? I want the BarLegend to be automatic, since it provides a nice, simple fit of values. However, even manually I have had no success with BarLegend not evaluating.



      (As a sidenote, imgur is not accepting the pictures I have provided. Have put up links, if someone can fix, would be grateful).









      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 7 at 15:10









      OldTomMorris

      947




      947




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          PlotLegends can take a list of legends:



          ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, 
          PlotRange -> All, PlotLegends ->
          BarLegend[Automatic],
          Placed[LineLegend[Directive[Red], "Test"], After]
          ,
          Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


          By default one legend will go to the right, and one below, so I used Placed to put both on the right.






          share|improve this answer




















          • I swear I tried placing a list in PlotLegends, but I can't see what mistake I made, I believe Column was the problem. Have now amended your comment as the answer.
            – OldTomMorris
            Aug 8 at 10:03

















          up vote
          3
          down vote













          Here is a work-around using separate ContourPlots:



          p1 = ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, 
          PlotRange -> All,
          PlotLegends -> BarLegend[Automatic]];

          p2 = ContourPlot[y == Cos[x], x, 0, 3, y, 0, 3,
          ContourStyle -> Red,
          PlotLegends -> LineLegend["Test"]];

          Show[p1, p2]


          Will this be ok?






          share|improve this answer






















          • Placed is not necessary since Show knows how to combine Legended with legends at the same position, although you can use it to fine tune the positioning. Also, you don't need to specify the color with LineLegend, LineLegend["Test"] does exactly what you want, and you only have to specify the color in one place.
            – rcollyer
            Aug 7 at 16:28






          • 1




            I think both are "correct", but use the one you find most suitable of course :)
            – Marius Ladegård Meyer
            Aug 7 at 16:57






          • 1




            @OldTomMorris I agree with Marius, both are correct, the Legended method, though is a little simpler/less intensive. They both work just finr.
            – rcollyer
            Aug 7 at 16:59






          • 1




            @OldTomMorris actually, Brett's answer is the correct one. Column was causing the confusion.
            – rcollyer
            Aug 7 at 17:41






          • 1




            @rccollyer In that case, I have shifted the answer. Thanks also to you, though.
            – OldTomMorris
            Aug 8 at 10:04

















          up vote
          2
          down vote













          Each plot type allows only specific legends to be used with PlotLegends, for ContourPlot and DensityPlot it is BarLegend. So, it is getting confused when you add LineLegend. (Per Marius, there is a switchover to LineLegend when only specific contours are used, e.g. f == g form of input to ContourPlot.)



          The correct way is to use Legended to add the additional legend:



          Legended[
          ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3,
          PlotRange -> All, PlotLegends -> BarLegend[Automatic],
          Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]
          ,
          LineLegend[Directive[Red], "Test"]
          ]





          share|improve this answer




















          • This the one. I just managed to concoct something from Marius' answer and comments and I used Show and Legended. Was about to post an answer when I see your simplified result. Thank you very much :)
            – OldTomMorris
            Aug 7 at 16:53

















          up vote
          1
          down vote













          Hacked it. The key was to use LegendLabel to label the BarLegend and then hack it into what I wanted.



          ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
          PlotLegends ->
          BarLegend[Automatic,
          LegendLabel ->
          Placed[LineLegend[Directive[Red], "Test"], Bottom]],
          Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


          The result is



          https://imgur.com/a/2OdeovA






          share|improve this answer




















            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "387"
            ;
            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f179628%2fcombining-linelegend-and-barlegend-in-countourplot%23new-answer', 'question_page');

            );

            Post as a guest






























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted










            PlotLegends can take a list of legends:



            ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, 
            PlotRange -> All, PlotLegends ->
            BarLegend[Automatic],
            Placed[LineLegend[Directive[Red], "Test"], After]
            ,
            Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


            By default one legend will go to the right, and one below, so I used Placed to put both on the right.






            share|improve this answer




















            • I swear I tried placing a list in PlotLegends, but I can't see what mistake I made, I believe Column was the problem. Have now amended your comment as the answer.
              – OldTomMorris
              Aug 8 at 10:03














            up vote
            4
            down vote



            accepted










            PlotLegends can take a list of legends:



            ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, 
            PlotRange -> All, PlotLegends ->
            BarLegend[Automatic],
            Placed[LineLegend[Directive[Red], "Test"], After]
            ,
            Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


            By default one legend will go to the right, and one below, so I used Placed to put both on the right.






            share|improve this answer




















            • I swear I tried placing a list in PlotLegends, but I can't see what mistake I made, I believe Column was the problem. Have now amended your comment as the answer.
              – OldTomMorris
              Aug 8 at 10:03












            up vote
            4
            down vote



            accepted







            up vote
            4
            down vote



            accepted






            PlotLegends can take a list of legends:



            ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, 
            PlotRange -> All, PlotLegends ->
            BarLegend[Automatic],
            Placed[LineLegend[Directive[Red], "Test"], After]
            ,
            Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


            By default one legend will go to the right, and one below, so I used Placed to put both on the right.






            share|improve this answer












            PlotLegends can take a list of legends:



            ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, 
            PlotRange -> All, PlotLegends ->
            BarLegend[Automatic],
            Placed[LineLegend[Directive[Red], "Test"], After]
            ,
            Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


            By default one legend will go to the right, and one below, so I used Placed to put both on the right.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 7 at 17:11









            Brett Champion

            16.9k250113




            16.9k250113











            • I swear I tried placing a list in PlotLegends, but I can't see what mistake I made, I believe Column was the problem. Have now amended your comment as the answer.
              – OldTomMorris
              Aug 8 at 10:03
















            • I swear I tried placing a list in PlotLegends, but I can't see what mistake I made, I believe Column was the problem. Have now amended your comment as the answer.
              – OldTomMorris
              Aug 8 at 10:03















            I swear I tried placing a list in PlotLegends, but I can't see what mistake I made, I believe Column was the problem. Have now amended your comment as the answer.
            – OldTomMorris
            Aug 8 at 10:03




            I swear I tried placing a list in PlotLegends, but I can't see what mistake I made, I believe Column was the problem. Have now amended your comment as the answer.
            – OldTomMorris
            Aug 8 at 10:03










            up vote
            3
            down vote













            Here is a work-around using separate ContourPlots:



            p1 = ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, 
            PlotRange -> All,
            PlotLegends -> BarLegend[Automatic]];

            p2 = ContourPlot[y == Cos[x], x, 0, 3, y, 0, 3,
            ContourStyle -> Red,
            PlotLegends -> LineLegend["Test"]];

            Show[p1, p2]


            Will this be ok?






            share|improve this answer






















            • Placed is not necessary since Show knows how to combine Legended with legends at the same position, although you can use it to fine tune the positioning. Also, you don't need to specify the color with LineLegend, LineLegend["Test"] does exactly what you want, and you only have to specify the color in one place.
              – rcollyer
              Aug 7 at 16:28






            • 1




              I think both are "correct", but use the one you find most suitable of course :)
              – Marius Ladegård Meyer
              Aug 7 at 16:57






            • 1




              @OldTomMorris I agree with Marius, both are correct, the Legended method, though is a little simpler/less intensive. They both work just finr.
              – rcollyer
              Aug 7 at 16:59






            • 1




              @OldTomMorris actually, Brett's answer is the correct one. Column was causing the confusion.
              – rcollyer
              Aug 7 at 17:41






            • 1




              @rccollyer In that case, I have shifted the answer. Thanks also to you, though.
              – OldTomMorris
              Aug 8 at 10:04














            up vote
            3
            down vote













            Here is a work-around using separate ContourPlots:



            p1 = ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, 
            PlotRange -> All,
            PlotLegends -> BarLegend[Automatic]];

            p2 = ContourPlot[y == Cos[x], x, 0, 3, y, 0, 3,
            ContourStyle -> Red,
            PlotLegends -> LineLegend["Test"]];

            Show[p1, p2]


            Will this be ok?






            share|improve this answer






















            • Placed is not necessary since Show knows how to combine Legended with legends at the same position, although you can use it to fine tune the positioning. Also, you don't need to specify the color with LineLegend, LineLegend["Test"] does exactly what you want, and you only have to specify the color in one place.
              – rcollyer
              Aug 7 at 16:28






            • 1




              I think both are "correct", but use the one you find most suitable of course :)
              – Marius Ladegård Meyer
              Aug 7 at 16:57






            • 1




              @OldTomMorris I agree with Marius, both are correct, the Legended method, though is a little simpler/less intensive. They both work just finr.
              – rcollyer
              Aug 7 at 16:59






            • 1




              @OldTomMorris actually, Brett's answer is the correct one. Column was causing the confusion.
              – rcollyer
              Aug 7 at 17:41






            • 1




              @rccollyer In that case, I have shifted the answer. Thanks also to you, though.
              – OldTomMorris
              Aug 8 at 10:04












            up vote
            3
            down vote










            up vote
            3
            down vote









            Here is a work-around using separate ContourPlots:



            p1 = ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, 
            PlotRange -> All,
            PlotLegends -> BarLegend[Automatic]];

            p2 = ContourPlot[y == Cos[x], x, 0, 3, y, 0, 3,
            ContourStyle -> Red,
            PlotLegends -> LineLegend["Test"]];

            Show[p1, p2]


            Will this be ok?






            share|improve this answer














            Here is a work-around using separate ContourPlots:



            p1 = ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, 
            PlotRange -> All,
            PlotLegends -> BarLegend[Automatic]];

            p2 = ContourPlot[y == Cos[x], x, 0, 3, y, 0, 3,
            ContourStyle -> Red,
            PlotLegends -> LineLegend["Test"]];

            Show[p1, p2]


            Will this be ok?







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 7 at 16:31

























            answered Aug 7 at 16:22









            Marius Ladegård Meyer

            5,44811022




            5,44811022











            • Placed is not necessary since Show knows how to combine Legended with legends at the same position, although you can use it to fine tune the positioning. Also, you don't need to specify the color with LineLegend, LineLegend["Test"] does exactly what you want, and you only have to specify the color in one place.
              – rcollyer
              Aug 7 at 16:28






            • 1




              I think both are "correct", but use the one you find most suitable of course :)
              – Marius Ladegård Meyer
              Aug 7 at 16:57






            • 1




              @OldTomMorris I agree with Marius, both are correct, the Legended method, though is a little simpler/less intensive. They both work just finr.
              – rcollyer
              Aug 7 at 16:59






            • 1




              @OldTomMorris actually, Brett's answer is the correct one. Column was causing the confusion.
              – rcollyer
              Aug 7 at 17:41






            • 1




              @rccollyer In that case, I have shifted the answer. Thanks also to you, though.
              – OldTomMorris
              Aug 8 at 10:04
















            • Placed is not necessary since Show knows how to combine Legended with legends at the same position, although you can use it to fine tune the positioning. Also, you don't need to specify the color with LineLegend, LineLegend["Test"] does exactly what you want, and you only have to specify the color in one place.
              – rcollyer
              Aug 7 at 16:28






            • 1




              I think both are "correct", but use the one you find most suitable of course :)
              – Marius Ladegård Meyer
              Aug 7 at 16:57






            • 1




              @OldTomMorris I agree with Marius, both are correct, the Legended method, though is a little simpler/less intensive. They both work just finr.
              – rcollyer
              Aug 7 at 16:59






            • 1




              @OldTomMorris actually, Brett's answer is the correct one. Column was causing the confusion.
              – rcollyer
              Aug 7 at 17:41






            • 1




              @rccollyer In that case, I have shifted the answer. Thanks also to you, though.
              – OldTomMorris
              Aug 8 at 10:04















            Placed is not necessary since Show knows how to combine Legended with legends at the same position, although you can use it to fine tune the positioning. Also, you don't need to specify the color with LineLegend, LineLegend["Test"] does exactly what you want, and you only have to specify the color in one place.
            – rcollyer
            Aug 7 at 16:28




            Placed is not necessary since Show knows how to combine Legended with legends at the same position, although you can use it to fine tune the positioning. Also, you don't need to specify the color with LineLegend, LineLegend["Test"] does exactly what you want, and you only have to specify the color in one place.
            – rcollyer
            Aug 7 at 16:28




            1




            1




            I think both are "correct", but use the one you find most suitable of course :)
            – Marius Ladegård Meyer
            Aug 7 at 16:57




            I think both are "correct", but use the one you find most suitable of course :)
            – Marius Ladegård Meyer
            Aug 7 at 16:57




            1




            1




            @OldTomMorris I agree with Marius, both are correct, the Legended method, though is a little simpler/less intensive. They both work just finr.
            – rcollyer
            Aug 7 at 16:59




            @OldTomMorris I agree with Marius, both are correct, the Legended method, though is a little simpler/less intensive. They both work just finr.
            – rcollyer
            Aug 7 at 16:59




            1




            1




            @OldTomMorris actually, Brett's answer is the correct one. Column was causing the confusion.
            – rcollyer
            Aug 7 at 17:41




            @OldTomMorris actually, Brett's answer is the correct one. Column was causing the confusion.
            – rcollyer
            Aug 7 at 17:41




            1




            1




            @rccollyer In that case, I have shifted the answer. Thanks also to you, though.
            – OldTomMorris
            Aug 8 at 10:04




            @rccollyer In that case, I have shifted the answer. Thanks also to you, though.
            – OldTomMorris
            Aug 8 at 10:04










            up vote
            2
            down vote













            Each plot type allows only specific legends to be used with PlotLegends, for ContourPlot and DensityPlot it is BarLegend. So, it is getting confused when you add LineLegend. (Per Marius, there is a switchover to LineLegend when only specific contours are used, e.g. f == g form of input to ContourPlot.)



            The correct way is to use Legended to add the additional legend:



            Legended[
            ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3,
            PlotRange -> All, PlotLegends -> BarLegend[Automatic],
            Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]
            ,
            LineLegend[Directive[Red], "Test"]
            ]





            share|improve this answer




















            • This the one. I just managed to concoct something from Marius' answer and comments and I used Show and Legended. Was about to post an answer when I see your simplified result. Thank you very much :)
              – OldTomMorris
              Aug 7 at 16:53














            up vote
            2
            down vote













            Each plot type allows only specific legends to be used with PlotLegends, for ContourPlot and DensityPlot it is BarLegend. So, it is getting confused when you add LineLegend. (Per Marius, there is a switchover to LineLegend when only specific contours are used, e.g. f == g form of input to ContourPlot.)



            The correct way is to use Legended to add the additional legend:



            Legended[
            ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3,
            PlotRange -> All, PlotLegends -> BarLegend[Automatic],
            Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]
            ,
            LineLegend[Directive[Red], "Test"]
            ]





            share|improve this answer




















            • This the one. I just managed to concoct something from Marius' answer and comments and I used Show and Legended. Was about to post an answer when I see your simplified result. Thank you very much :)
              – OldTomMorris
              Aug 7 at 16:53












            up vote
            2
            down vote










            up vote
            2
            down vote









            Each plot type allows only specific legends to be used with PlotLegends, for ContourPlot and DensityPlot it is BarLegend. So, it is getting confused when you add LineLegend. (Per Marius, there is a switchover to LineLegend when only specific contours are used, e.g. f == g form of input to ContourPlot.)



            The correct way is to use Legended to add the additional legend:



            Legended[
            ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3,
            PlotRange -> All, PlotLegends -> BarLegend[Automatic],
            Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]
            ,
            LineLegend[Directive[Red], "Test"]
            ]





            share|improve this answer












            Each plot type allows only specific legends to be used with PlotLegends, for ContourPlot and DensityPlot it is BarLegend. So, it is getting confused when you add LineLegend. (Per Marius, there is a switchover to LineLegend when only specific contours are used, e.g. f == g form of input to ContourPlot.)



            The correct way is to use Legended to add the additional legend:



            Legended[
            ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3,
            PlotRange -> All, PlotLegends -> BarLegend[Automatic],
            Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]
            ,
            LineLegend[Directive[Red], "Test"]
            ]






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 7 at 16:23









            rcollyer

            28.1k673164




            28.1k673164











            • This the one. I just managed to concoct something from Marius' answer and comments and I used Show and Legended. Was about to post an answer when I see your simplified result. Thank you very much :)
              – OldTomMorris
              Aug 7 at 16:53
















            • This the one. I just managed to concoct something from Marius' answer and comments and I used Show and Legended. Was about to post an answer when I see your simplified result. Thank you very much :)
              – OldTomMorris
              Aug 7 at 16:53















            This the one. I just managed to concoct something from Marius' answer and comments and I used Show and Legended. Was about to post an answer when I see your simplified result. Thank you very much :)
            – OldTomMorris
            Aug 7 at 16:53




            This the one. I just managed to concoct something from Marius' answer and comments and I used Show and Legended. Was about to post an answer when I see your simplified result. Thank you very much :)
            – OldTomMorris
            Aug 7 at 16:53










            up vote
            1
            down vote













            Hacked it. The key was to use LegendLabel to label the BarLegend and then hack it into what I wanted.



            ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
            PlotLegends ->
            BarLegend[Automatic,
            LegendLabel ->
            Placed[LineLegend[Directive[Red], "Test"], Bottom]],
            Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


            The result is



            https://imgur.com/a/2OdeovA






            share|improve this answer
























              up vote
              1
              down vote













              Hacked it. The key was to use LegendLabel to label the BarLegend and then hack it into what I wanted.



              ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
              PlotLegends ->
              BarLegend[Automatic,
              LegendLabel ->
              Placed[LineLegend[Directive[Red], "Test"], Bottom]],
              Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


              The result is



              https://imgur.com/a/2OdeovA






              share|improve this answer






















                up vote
                1
                down vote










                up vote
                1
                down vote









                Hacked it. The key was to use LegendLabel to label the BarLegend and then hack it into what I wanted.



                ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
                PlotLegends ->
                BarLegend[Automatic,
                LegendLabel ->
                Placed[LineLegend[Directive[Red], "Test"], Bottom]],
                Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


                The result is



                https://imgur.com/a/2OdeovA






                share|improve this answer












                Hacked it. The key was to use LegendLabel to label the BarLegend and then hack it into what I wanted.



                ContourPlot[Cos[y + x] x y, x, 0, 3, y, 0, 3, PlotRange -> All, 
                PlotLegends ->
                BarLegend[Automatic,
                LegendLabel ->
                Placed[LineLegend[Directive[Red], "Test"], Bottom]],
                Epilog -> Red, Line[Table[i, Cos[i], i, 0., 3., .1]]]


                The result is



                https://imgur.com/a/2OdeovA







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 7 at 16:35









                OldTomMorris

                947




                947






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f179628%2fcombining-linelegend-and-barlegend-in-countourplot%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery