1
$\begingroup$

Can anyone help me make the legends(markers) match with the figure curves? I have 2 figures that have three curves each, and then I have to combine them. I used the following code for the first figure:

 p1 = ListLinePlot[Transpose[{k, #}] & /@ {K11s, K12s, K22s}, 
 PlotLegends -> 
 Placed[LineLegend[{"K11", "K12", "K22"}, 
 LegendFunction -> (Framed[#1, FrameMargins -> 0] & )], {0.8, 
  0.2}], FrameLabel -> {"k", "K"}, Axes -> True, Frame -> True, 
  AxesStyle -> Directive[{Bold, 25}, {Black, 25}], 
  BaseStyle -> {FontWeight -> Bold, FontSize -> 14}, 
   PlotRange -> All]

for the other figure I used this:

p2 = Legended[Show[
 ListLinePlot[Transpose[{k, #}] & /@ {K11b}, PlotStyle -> Red], 
   ListLinePlot[Transpose[{k, #}] & /@ {K12b}, 
  PlotStyle -> {Dashing[Large], Thickness[Large], Blue}], 
 ListLinePlot[Transpose[{k, #}] & /@ {K22b}, PlotStyle -> {Dashed}],
  AxesStyle -> Directive[{Bold, 25}, {Black, 25}], 
 FrameLabel -> {"k", "K"}, Frame -> True, FrameTicks -> Automatic, 
 ImageSize -> 700, Background -> Transparent, PlotRange -> All, 
 BaseStyle -> {FontWeight -> Bold, FontSize -> 14}], 
 Placed[LineLegend[{Red, {Dashing[Large], Thickness[Large], 
  Blue}, {Dashed, Blue}}, {Style["fitted K11", 12], 
  Style["fitted K12", 12], Style["fitted K22", 12]}, 
  LegendMargins -> {{0, 0}, {0, 0}}, 
  LegendFunction -> (Framed[#1, FrameMargins -> 0] & ) , 
  LabelStyle -> {(FontFamily -> "Helvetica"), 
   FontWeight -> Bold}], {0.4, 0.8}]]

Then I combined them using "Show". My problem with the second one is the markers do not match the one in the plot.Also is there another way to make these plots in one graph rather than using "Show" with keeping the legends bar inside the graph?

$\endgroup$
  • 1
    $\begingroup$ try using Directive[Dashing[Large], Thickness[Large], Blue] instead of {Dashing[Large], Thickness[Large], Blue]} and Directive[Dashed, Blue] instead of {Dashed, Blue} in lListPlots and in LineLegend in p2. $\endgroup$ – kglr Oct 15 at 22:55
1
$\begingroup$
SeedRandom[1]
k = Range[10];
{K11s, K12s, K22s} = RandomInteger[10, {3, 10}];
{K11b, K12b, K22b} = {K11s, K12s, K22s} + RandomReal[{-1, 1}, {3, 10}]; 

ListLinePlot[Transpose[{k, #}] & /@ {K11s, K12s, K22s, K11b, K12b, K22b},
 PlotStyle -> {Automatic, Automatic, Automatic, 
   Red, Directive[Dashing[Large], Thickness[Large], Blue], Directive[Dashed, Blue]}, 
 PlotLegends -> Placed[
   LineLegend[
     Flatten[{#, "fitted " <> # & /@ #}] &@{"K11", "K12", "K22"}, 
     LegendLayout -> {"Column", 2}, 
     LegendMarkerSize -> {40, 20}, 
     LegendFunction -> (Framed[#1, FrameMargins -> 0] &)], 
   {0.35, 0.85}], 
 FrameLabel -> {"k", "K"}, Axes -> True, Frame -> True, 
 AxesStyle -> Directive[{Bold, 25}, {Black, 25}], 
 BaseStyle -> {FontWeight -> Bold, FontSize -> 14}, PlotRange -> All]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you very much!! $\endgroup$ – Ghady Oct 16 at 13:38
  • $\begingroup$ @Ghady, my pleasure. Thank you for the accept. $\endgroup$ – kglr Oct 16 at 13:45

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.