1

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?

John
  • 1,611
  • 4
  • 14
  • I get lots of errors when I run your code, – Nasser Jun 03 '20 at 01:24
  • 1
    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. – MarcoB Jun 03 '20 at 01:32
  • @MarcoB I have EDITED the question to make it workable and so that it works as a minimal working example. Thanks – John Jun 03 '20 at 01:58
  • @Nasser I edited the question to make it work and to make it easier. Thanks for trying to help me – John Jun 03 '20 at 01:59
  • 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 – John Jun 03 '20 at 02:04

2 Answers2

0

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

Nasser
  • 143,286
  • 11
  • 154
  • 359
  • 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

    – John Jun 03 '20 at 02:29
  • @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. – Nasser Jun 03 '20 at 02:31
  • Nasser, I have made an EDIT to include the second set of data and make more especific the question, Thanks ! – John Jun 03 '20 at 02:41
  • @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. – Nasser Jun 03 '20 at 02:51
  • 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.? – John Jun 03 '20 at 03:01
  • @John you can do it with Show but need to do lots of Manual construction and it gets messy. See how-to-add-plotlegends-in-a-show-function I would recommend changing your Show to one Plot. It should not be hard to do this change, just replace Show[ plot[data1..],plot[data2,...]] with plot[{data1,data2},...] and now you can make the Legends much easier. But again, if you want to use Show, then the above linked answer shows how. – Nasser Jun 03 '20 at 03:11
  • Nasser, thanks! I saw this post before. The problem with my particular code is that inside the Show I have not only ListPlot but also Plot and in this way if I use your code it wouldn't work because I cannot use ListPlot[{data, data2}...etc as I also have Plot inside my Show. That is the main reason that for my particular case it would be better to do this with Show if possible. Inside the Show I have a Plot function that contains a fitted model and that's the reason I need to use Plot. – John Jun 03 '20 at 03:17
  • I have not only ListPlot but also Plot it then would have been better to show your MWE doing the above, your MWE only shows both using ListPlot. But if you have seen the above linked to answer before, why not use that answer for your needs? It already shows how do it with Show? Did it not work for you for some reason? my answer to add legends to Show is not going to be really much different that what the above link shows. – Nasser Jun 03 '20 at 03:22
  • Nasser, I was already able to do it taking a better look at the link you provided. I appreciate your help a lot ! – John Jun 03 '20 at 04:06
0

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

Rohit Namjoshi
  • 10,212
  • 6
  • 16
  • 67
  • 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? – John Jun 03 '20 at 02:42