1
$\begingroup$

If I have the following code:

data={{-1., 53.260026873285206}, {-0.5228787452803376, 
   54.87380209619239}, {0., 56.1639882116586}, {Log[3]/Log[10], 
   58.84342746705887}, {1, 61.23327329308531}, {Log[30]/Log[10], 
   63.24477900953466}, {2, 66.81745692936386}, {Log[300]/Log[10], 
   69.93149162170488}, {Log[600]/Log[10], 71.4829226089971}, {3, 
   72.18449065001315}, {-2.3010299956639813, 
   54.00231502199229}, {-(Log[60]/Log[10]), 
   55.1941444178587}, {-(Log[20]/Log[10]), 56.003834022541035}, {-1,56.949679030549746}, {-(Log[6]/Log[10]), 
   57.3050045190135}, {-(Log[10/3]/Log[10]), 
   57.72132372329668}, {-(Log[2]/Log[10]), 
   58.24888194249831}, {-2.3010299956639813, 
   54.03670125564749}, {-(Log[60]/Log[10]), 
   55.11571197888246}, {-(Log[20]/Log[10]), 56.17041542461532}, {-1,
    56.71167863055032}, {-(Log[6]/Log[10]), 
   57.25059302294601}, {-(Log[10/3]/Log[10]), 
   57.70966183063876}, {-(Log[2]/Log[10]), 58.106793148660984}};

   ListPlot[data, PlotStyle -> {Red, AbsolutePointSize[6]}, 
 PlotLegends -> Placed[{"All Data"}, {0.2, 0.8}], Frame -> True, 
 Axes -> False, FrameStyle -> 16, GridLines -> Automatic, 
 GridLinesStyle -> Lighter[Gray, .8], 
 FrameLabel -> (Style[#, 20, Bold] & /@ {HoldForm@Log10["q (K/s)"], 
     Row[{Subscript[T, f'], " (", Degree, " C)"}]})]

Which gives the following plot:

enter image description here

I have two questions:

1) How can I put a frame to the legend (e.g "All Data") keeping the same position? 2) How can I make the legend bigger?

EDIT:

If I have a second data and Legend and I include it to plot it with Show such as:

data2 = {{2, 66.9795853828354}, {Log[300]/Log[10], 70.1}, {Log[600]/
    Log[10], 71.7}, {3, 72.3}, {-2.3010299956639813, 
    54.}, {-(Log[60]/Log[10]), 55.1}, {-(Log[20]/Log[10]), 56.}, {-1, 
    56.9}, {-(Log[6]/Log[10]), 57.3}, {-(Log[10/3]/Log[10]), 
    57.7}, {-(Log[2]/Log[10]), 58.2}, {-2.3, 
    54.}, {-(Log[60]/Log[10]), 55.1}, {-(Log[20]/Log[10]), 56.1}, {-1,
     56.7}, {-(Log[6]/Log[10]), 57.2}, {-(Log[10/3]/Log[10]), 
    57.7}, {-(Log[2]/Log[10]), 58.1}};

Show[ListPlot[data, PlotStyle -> {Red, AbsolutePointSize[6]}, 
  PlotLegends -> Placed[{"All Data"}, {0.2, 0.8}], Frame -> True, 
  Axes -> False, FrameStyle -> 16, GridLines -> Automatic, 
  GridLinesStyle -> Lighter[Gray, .8], 
  FrameLabel -> (Style[#, 20, Bold] & /@ {HoldForm@Log10["q (K/s)"], 
      Row[{Subscript[T, f'], " (", Degree, " C)"}]})], 
 ListPlot[data2, PlotLegends -> Placed[{"All Data"}, {0.2, 0.7}]]]

Which gives:

enter image description here

3) How can I do the same but both Legends in the same frame, together with their data points?

$\endgroup$
5
  • $\begingroup$ I get lots of errors when I run your code, $\endgroup$
    – Nasser
    Jun 3 '20 at 1:24
  • 1
    $\begingroup$ John, you've posted quite a few questions, so you should know by now that we need COMPLETE code, including the data needed to run it. It is also best to produce a minimal working example that reproduces the problem. In your case, none of the formatting is relevant to the problem, so you could take it out. That helps because it brings your problem to the fore and allows people to focus on it. But remember, first and foremost, if I can't run your code, I can't fix your code! If your code is too big, just make up some numbers just for the question. $\endgroup$
    – MarcoB
    Jun 3 '20 at 1:32
  • $\begingroup$ @MarcoB I have EDITED the question to make it workable and so that it works as a minimal working example. Thanks $\endgroup$
    – John
    Jun 3 '20 at 1:58
  • $\begingroup$ @Nasser I edited the question to make it work and to make it easier. Thanks for trying to help me $\endgroup$
    – John
    Jun 3 '20 at 1:59
  • $\begingroup$ Please take into account that in my actual code I have two legends and I am plotting two figures together with Show so that it is workable also with Show and more Legends. Thanks $\endgroup$
    – John
    Jun 3 '20 at 2:04
0
$\begingroup$

How can I put a frame to the legend (e.g "All Data") keeping the same position?

ListPlot[data,
 PlotStyle -> {Red, AbsolutePointSize[6]},
 PlotLegends -> Placed[LineLegend[{"All Data"}, 
            LegendFunction -> (Framed[Style[#]] &)], {0.2, 0.8}],
 Frame -> True,
 Axes -> False,
 FrameStyle -> 16,
 GridLines -> Automatic, GridLinesStyle -> Lighter[Gray, .8],
 FrameLabel -> (Style[#, 20, Bold] & /@ {HoldForm@Log10["q (K/s)"], 
     Row[{Subscript[T, f'], " (", Degree, " C)"}]})
 ]

enter image description here

2) How can I make the legend bigger?

ListPlot[data,
 PlotStyle -> {Red, AbsolutePointSize[6]},
 PlotLegends -> Placed[LineLegend[{"All Data"}, 
        LegendFunction -> (Framed[Style[#, 20]] &)], {0.2, 0.8}],
 Frame -> True,
 Axes -> False,
 FrameStyle -> 16,
 GridLines -> Automatic, GridLinesStyle -> Lighter[Gray, .8],
 FrameLabel -> (Style[#, 20, Bold] & /@ {HoldForm@Log10["q (K/s)"], 
     Row[{Subscript[T, f'], " (", Degree, " C)"}]})
 ]

enter image description here


Update for two data

ListPlot[{data, data2},
 PlotStyle -> {Red, AbsolutePointSize[6]},
 PlotLegends -> 
  Placed[LineLegend[{"data1", "data2"}, 
    LegendFunction -> (Framed[#] &)], {0.2, 0.8}],
 Frame -> True,
 Axes -> False,
 FrameStyle -> 16,
 GridLines -> Automatic, GridLinesStyle -> Lighter[Gray, .8], 
 FrameLabel -> (Style[#, 20, Bold] & /@ {HoldForm@Log10["q (K/s)"], 
     Row[{Subscript[T, f'], " (", Degree, " C)"}]})
 ]

enter image description here

ListPlot[{data, data2},
 PlotStyle -> {Red, AbsolutePointSize[6]},
 PlotLegends -> Placed[LineLegend[{"data1", "data2"}, 
       LegendFunction -> (Framed[Style[#, 18]] &)], {0.2, 0.8}],
 Frame -> True,
 Axes -> False,
 FrameStyle -> 16,
 GridLines -> Automatic, GridLinesStyle -> Lighter[Gray, .8], 
 FrameLabel -> (Style[#, 20, Bold] & /@ {HoldForm@Log10["q (K/s)"], 
     Row[{Subscript[T, f'], " (", Degree, " C)"}]})
 ]

enter image description here

$\endgroup$
9
  • $\begingroup$ Nasser thank you very much!. One question: Is it possible to put the Legend point (e,g the red point) inside the frame as well?. Also, if I have another legend for another plot using Show how can I also put that Legend in the same Frame?. If I use the code it will do it manually for each but both will not be included in the same frame. Is this possible as well?. I appreciate your help again in advanced $\endgroup$
    – John
    Jun 3 '20 at 2:29
  • $\begingroup$ @John please provide a second MWE of what you want, which includes 2 legends to add in this case. I used the MWE you provided which has only one legend. I'll see if it possible to include the point as well inside. $\endgroup$
    – Nasser
    Jun 3 '20 at 2:31
  • $\begingroup$ Nasser, I have made an EDIT to include the second set of data and make more especific the question, Thanks ! $\endgroup$
    – John
    Jun 3 '20 at 2:41
  • $\begingroup$ @John updated for 2 data. You can play with Frame setting there to change it more, spacing, etc... see help on Frame as needed. I think it is better to use one plot command and not use Show to combine them. $\endgroup$
    – Nasser
    Jun 3 '20 at 2:51
  • $\begingroup$ Thank you Nasser!!!! This works great!. Just one more thing if you don't mind and if it is not to difficult. Is it possible too do it with the command Show as I had it? I have all my long code with plots using Show.? $\endgroup$
    – John
    Jun 3 '20 at 3:01
0
$\begingroup$

If you want a frame around the whole legend

ListPlot[data, PlotStyle -> {Red, AbsolutePointSize[6]}, 
 PlotLegends -> 
  Placed[PointLegend[{Style["All Data", 14]}, 
    LegendFunction -> (Framed[#, FrameStyle -> Thick, 
        FrameMargins -> Tiny] &)], {0.2, 0.8}], Frame -> True, 
 Axes -> False, FrameStyle -> 16, GridLines -> Automatic, 
 GridLinesStyle -> Lighter[Gray, .8], 
 FrameLabel -> (Style[#, 20, Bold] & /@ {HoldForm@Log10["q (K/s)"], 
     Row[{Subscript[T, f'], " (", Degree, " C)"}]})]

enter image description here

$\endgroup$
1
  • $\begingroup$ Rohit! Thank you very much. This is exactly what I wanted. Could you also take a look at the last edit I made to include two different legends in the same frame and make them bigger? $\endgroup$
    – John
    Jun 3 '20 at 2:42

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.