2
$\begingroup$

I have a plot for which I would like to create an legend that is black and white printer friendly. I have seen Jen's legendmaker but I don't know how to adapt it. I need help in making the legend for the exit region to appear meshed. The graph is incomplete right now and I will add more stuff to it.. like J and V etc etc but for now I want the exit regions and their legends to be black and white printer friendly. What can I do to get a mesh to appear in the legend for the exit region. Thanks

EDIT: Gaps in code fixed.

enter image description here

I1 = 15;
I2 = 8;
f1[x_] := I1;
f2[x_] := I2;
hddd = 20;
h00d = 60;
h00s = 150;
hsss = 180;
    pl1 = Plot[{f1[x]}, {x, 0, 200}, AxesOrigin -> {0, 0}, 
       PlotRange -> {-1, 20}, Epilog -> {
         Inset[
          Grid[{{Text[Style["J", "Garamond", 16]], 
             Text[Style["First Function", "Garamond", 16]]}, {Text[
              Style["V", "Garamond", 16]], 
             Text[Style["Second Function", "Garamond", 16]]}}], {h00s, 
           I1 + 3}],
         Inset[
          Grid[{{Item["", 
              Background -> RGBColor[0.35082, 0.595178, .853742], 
              Frame -> True, FrameStyle -> AbsoluteThickness[1]], 
             Style["Continuation Region", "Garamond", 16]}, {Item["", 
              Background -> RGBColor[1, 1, .4], Frame -> True, 
              FrameStyle -> AbsoluteThickness[1]], 
             Style["Exit Region", "Garamond", 16]}}]], Dashed, 
         Arrowheads[Small], Arrow[{{h00s, I1}, {h00s, 0}}], 
         Arrowheads[Small], Arrow[{{h00d, I1}, {h00d, 0}}], 
         Arrowheads[Small], Arrow[{{hddd, I1}, {hddd, 0}}], 
         Arrowheads[Small], Arrow[{{hsss, I2}, {hsss, 0}}], 
         Inset[Style["Down Boundaries", "Garamond", 
           16], {(hddd + h00d)/2, (I1 + I2)/2}],
         Inset[
          Style["Top Boundaries", "Garamond", 
           16], {(hsss + h00s)/2, (I1 + I2)/2}],
         }, Ticks -> {{{hddd, Text[Style["HDD", "Garamond", 20]]}, {h00d, 
           Text[Style["H0D", "Garamond", 20]]}, {h00s, 
           Text[Style["H0S", "Garamond", 20]]}, {hsss, 
           Text[Style["HSS", "Garamond", 20]]}}, {{I1, 
           Text[Style["High", "Garamond", 20]]}, {I2, 
           Text[Style["Low", "Garamond", 20]]}}}, 
       AxesLabel -> {Text[Style["Variable X", "Garamond", 20]], 
         Text[Style["Variable Y", "Garamond", 20]]}];
    pl2 = Plot[{f2[x]}, {x, 0, 200}, AxesOrigin -> {0, 0}, 
       PlotRange -> {-1, 20}];
    ptd = ListPlot[{{h00d, I2}, {hddd, I1}}, 
       PlotStyle -> {Directive[Red, PointSize[Large]]}, 
       AxesOrigin -> {0, 0}, PlotRange -> {-1, 20}];
    pts = ListPlot[{{h00s, I1}, {hsss, I2}}, 
       PlotStyle -> {Directive[Green, PointSize[Large]]}, 
       AxesOrigin -> {0, 0}, PlotRange -> {-1, 20}];
    r1 = RegionPlot[
       f1[x] > 0, {x, 0, hddd - 1}, {y, I1 - 0.15, I1 + 0.15}, 
       PlotStyle -> RGBColor[1, 1, .4], Mesh -> 2];
    r2 = RegionPlot[
       f1[x] > 0, {x, h00s + 1, 200}, {y, I1 - 0.15, I1 + 0.15}, 
       PlotStyle -> RGBColor[1, 1, .4], Mesh -> 2];
    r3 = RegionPlot[
       f1[x] > 0, {x, 0, h00d - 1}, {y, I2 - 0.15, I2 + 0.15}, 
       PlotStyle -> RGBColor[1, 1, .4], Mesh -> 2];
    r4 = RegionPlot[
       f1[x] > 0, {x, hsss + 1, 200}, {y, I2 - 0.15, I2 + 0.15}, 
       PlotStyle -> RGBColor[1, 1, .4], Mesh -> 2];
    r5 = RegionPlot[
       f1[x] > 0, {x, h00d + 1, hsss - 1}, {y, I2 - 0.1, I2 + 0.1}, 
       PlotStyle -> RGBColor[0.35082, 0.595178, .853742]];
    r6 = RegionPlot[
       f1[x] > 0, {x, hddd + 1, h00s - 1}, {y, I1 - 0.1, I1 + 0.1}, 
       PlotStyle -> RGBColor[0.35082, 0.595178, .853742]];
    Show[pl1, pl2, ptd, pts, r1, r2, r3, r4, r5, r6]
$\endgroup$

1 Answer 1

8
$\begingroup$

After Amatya's edit

MeshMarker[a_, b_, col_: Lighter@Blue] :=RegionPlot[True, {x, -2, 2}, {y, -2, 2},
 Frame -> False, PlotStyle -> col, Mesh -> {a, b}, ImageSize -> 20]

SwatchLegend[{1, 2}, {"Continuation Region", "ExitRegion"},
LegendMarkerSize -> {{30,30}}, LegendMarkers -> MeshMarker @@@ {{2, 2, Yellow}, {0,0}}]

enter image description here

Before Amatya's edit

There are gaps in Your code so it does not work for me but look at following solutions.

With Mesh

MeshMarker[a_, b_] :=RegionPlot[True, {x, -2, 2}, {y, -2, 2}, Frame -> False, 
Mesh -> {a, b}, ImageSize -> 20];

Show[{
 RegionPlot[x^2 + y^2 < 4, {x, -3, 3}, {y, -3, 3}, Mesh -> {0, 6}, 
 PlotLegends ->      SwatchLegend[{1}, {plot1}, LegendMarkers -> MeshMarker[0, 6], 
  LegendMarkerSize -> 30]],

 RegionPlot[(x - 5)^2 + y^2 < 4, {x, -3, 7}, {y, -3, 3}, Mesh -> {6, 0}, 
 PlotLegends ->     SwatchLegend[{1}, {plot2}, LegendMarkers -> MeshMarker[6, 0], 
  LegendMarkerSize -> 30]]

 }, PlotRange -> All, AspectRatio -> Automatic, ImageSize -> 500
 ]

enter image description here

without mesh

 texture = {
  Rasterize@Graphics[{Thick, Line[{{{0, 0}, {1, 1}}, {{0, 1}, {1, 0}}}]}, 
                     ImageSize -> 30, ImageMargins -> 0],
  Rasterize@Graphics[{Thick, Line[{{{0, 0}, {1, 1}}, {{.5, 0}, {1, .5}}, {{0, .5}, {.5, 1}}}]},
                     ImageSize -> 30, ImageMargins -> 0, PlotRange -> {{0, 1}, {0, 1}}]
 };

Show[{
  RegionPlot[x^2 + y^2 < 4, {x, -3, 3}, {y, -3, 3},
    PlotStyle -> Texture[texture[[1]]],TextureCoordinateScaling -> False,
    PlotLegends -> SwatchLegend[{1}, {"region 1"}, LegendMarkerSize -> {{30, 30}}, 
    LegendMarkers -> texture[[1]]]]
  ,  
  RegionPlot[(x - 5)^2 + y^2 < 4, {x, -3, 7}, {y, -3, 3},
    PlotStyle -> Texture[texture[[2]]], TextureCoordinateScaling -> False,
    PlotLegends -> SwatchLegend[{1}, {"region 2"}, LegendMarkerSize -> {{30, 30}},
    LegendMarkers -> texture[[2]]]]

  }, PlotRange -> All, AspectRatio -> Automatic, ImageSize -> 500
 ]

enter image description here

$\endgroup$
5
  • $\begingroup$ I'm sorry for the gaps in the code. I always get careless like this. I'll go over your code now. $\endgroup$
    – Amatya
    Jun 5, 2013 at 20:43
  • $\begingroup$ @Amatya Don't worry :) it is not a big deal when question is clear. $\endgroup$
    – Kuba
    Jun 5, 2013 at 20:45
  • $\begingroup$ I don't have MMA9 at school but I do have it at home so I will write back in 6-7 hours. Thanks. $\endgroup$
    – Amatya
    Jun 5, 2013 at 21:03
  • $\begingroup$ @Amatya No problem, but in case of earlier version MeshMarker can be simply in a Grid like in Your code. $\endgroup$
    – Kuba
    Jun 5, 2013 at 21:07
  • $\begingroup$ Sorry I vanished for two weeks. Thanks a lot for your solution! $\endgroup$
    – Amatya
    Jun 22, 2013 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.