Message Boards Message Boards

0
|
2248 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Trying to add a legend when using CombinePlots

Posted 1 year ago

My notebook contains two functions makePlot1 and makePlot2. Which one is used depends on the setting of a variable cMethod. makePlot1 has a single Plot command which plots two data series and I use the following to add a legend to the plot:

cPlotLegends -> 
 Placed[LineLegend[{legend1, legend2}, 
   LegendFunction -> (Framed[#, FrameMargins -> -2, 
       Background -> White, FrameStyle -> Directive[Black]] &), 
   LegendLayout -> "Row", LegendMarkerSize -> {{8, 8}}, 
   LabelStyle -> {FontSize -> 10}], {Right, Bottom}]

This works beautifully and produces a legend looking like this enter image description here A screenshot of the full plot from makePlot1 is attached (FullPlot.png)

makePlot2 uses CombinePlots to combine two plots and various "decorations" to fine-tune the results. I have tried adding legends to the two plots before combining them, and have also tried adding a legend after the two plots have been combined. If any kind soul would be prepared to take a look at this, I would be very grateful. My notebook and required data (Dissociation constants.TXT) are attached.

I should add that makePlot1 was only intended to be an interim solution and that makePlot2 is what I want finally..

Attachment

POSTED BY: Paul Newton
2 Replies

Hi Paul,

I have not looked at the code in the attached notebook, however, this works fine.

ResourceFunction["CombinePlots"][
 Plot[Sin[x], {x, 0, 2 \[Pi]}, 
  PlotLegends -> 
   Placed[LineLegend[{Red, Blue}, {"Sin[x]", "Cos[x]"}, 
     LegendFunction -> (Framed[#, FrameMargins -> -2, 
         FrameStyle -> Directive[Black]] &), LegendLayout -> "Row",
     LegendMarkerSize -> {{8, 8}},
     LabelStyle -> {FontSize -> 10}], {Right, Bottom}], 
  PlotStyle -> Blue],
 Plot[Cos[x], {x, 0, 2 \[Pi]}, PlotStyle -> Red],
 Frame -> True]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 1 year ago

Thank you very much, Rohit. Following your example I now have it working just fine and I am attaching the revised, working notebook (the previously uploaded notebook actually contained two typos which would have prevented it from working properly under certain circumstances).

Attachments:
POSTED BY: Paul Newton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract