2
$\begingroup$

I have plot code something like this:

g1 = Plot[x, {x, 0, 1}, Frame -> True, PlotRange -> All, 
   PlotStyle -> {Blue, Thickness[0.006], Dashing[{.07, 0.02}]}];
g2 = Plot[x^2, {x, 0, 1}, Frame -> True, PlotRange -> All, 
   PlotStyle -> {Green, Thickness[0.006]}];
g3 = Plot[x^3, {x, 0, 1}, Frame -> True, PlotRange -> All, 
   PlotStyle -> {Red, Thickness[0.007], Dashing[{.01, 0.015}]}];
fig = Show[g1, g2, g3, AspectRatio -> 1.4]

That I simplify it, I want to use plotlegends, type "a=0.1" and "d=10" for g1 plot, "d=100" for g2 plot and "d=200" for g3 plot and control size and font and place of them. the problem is, their is 4 information, one of them general and 3 of them related to each plot that they are different from the plot function i.e. "x, x^2 and x^3" and I want all of them inside one graph for example {Left, Top}.

$\endgroup$

3 Answers 3

3
$\begingroup$

I think you can do it like this. It's better to use AbsoluteDashing and AbsoluteThickness. Add LabelStyle -> {} as an option for LineLegend to change font, colour and so on.

g1 = Plot[x, {x, 0, 1}, Frame -> True, PlotRange -> All,
   PlotStyle -> {Blue, AbsoluteThickness[1], AbsoluteDashing[{20, 5}]},
   PlotLegends -> Placed[LineLegend[{"a=0.1, d=10"}, LegendMarkerSize -> {50, 10}], {Left,Top}]];
g2 = Plot[x^2, {x, 0, 1}, Frame -> True, PlotRange -> All,
   PlotStyle -> {Green, AbsoluteThickness[1]}, 
   PlotLegends -> Placed[LineLegend[{"d=100"}, LegendMarkerSize -> {50, 10}], {Left, Top}]];
g3 = Plot[x^3, {x, 0, 1}, Frame -> True, PlotRange -> All, 
   PlotStyle -> {Red, AbsoluteThickness[1], AbsoluteDashing[{5, 5}]},
   PlotLegends -> Placed[LineLegend[{"d=200"}, LegendMarkerSize -> {50, 10}],{Left, Top}]];
fig = Show[g1, g2, g3, AspectRatio -> 1.4]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks a lot! It works good! $\endgroup$
    – Sasan
    Commented Oct 9, 2018 at 12:21
2
$\begingroup$

How about this:

Manipulate[
 g1 = Plot[a x, {x, 0, 1}, Frame -> True, PlotRange -> All, 
   PlotStyle -> {Blue, AbsoluteThickness[1], 
     AbsoluteDashing[{20, 5}]}, 
   PlotLegends -> 
    Placed[LineLegend[{"a"}, LegendMarkerSize -> {50, 10}], {Left, 
      Top}]];
 g2 = Plot[b x^2, {x, 0, 1}, Frame -> True, PlotRange -> All, 
   PlotStyle -> {Green, AbsoluteThickness[1]}, 
   PlotLegends -> 
    Placed[LineLegend[{"b"}, LegendMarkerSize -> {50, 10}], {Left, 
      Top}]];
 g3 = Plot[c x^3, {x, 0, 1}, Frame -> True, PlotRange -> All, 
   PlotStyle -> {Red, AbsoluteThickness[1], AbsoluteDashing[{5, 5}]}, 
   PlotLegends -> 
    Placed[LineLegend[{"c"}, LegendMarkerSize -> {50, 10}], {Left, 
      Top}]];
 fig = Show[g1, g2, g3, AspectRatio -> 1.4],
 {{a, 0.1, "g1(a)"}, 0.1, 1, 0.1},
 {{b, 0.1, "g2(b)"}, 0.1, 1, 0.1},
 {{c, 0.1, "g3(c)"}, 0.1, 1, 0.1}
 ]

which gives much more flexibility to play with the plots by changing the parameters.

enter image description here

$\endgroup$
2
$\begingroup$

Hope this will help,

  g1 = Plot[x, {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}, Frame -> True, 
  PlotRange -> All, 
  PlotStyle -> {Blue, Thickness[0.006], Dashing[{.07, 0.02}]}, 
  PlotLegends -> Placed[{TraditionalForm["d=10"]}, {Left, Top}]]
  g2 = Plot[x^2, {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}, 
  Frame -> True, PlotRange -> All, 
  PlotStyle -> {Red, Thickness[0.006], Dashing[{.07, 0.02}]}, 
  PlotLegends -> Placed[{TraditionalForm["d=100"]}, {Left, Top}]]
  g3 = Plot[x^3, {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}, 
  Frame -> True, PlotRange -> All, 
  PlotStyle -> {Green, Thickness[0.006], Dashing[{.07, 0.02}]}, 
  PlotLegends -> Placed[{TraditionalForm["d=200"]}, {Left, Top}]]
  lText = Text[Style["a=0.1", Medium], {0.5, 0.89}];
  txt = Graphics[{lText}];
  Show[{g1, g2, g3, txt}, PlotRangeClipping -> True, 
  AxesLabel -> {Style["x", FontSize -> 18], 
  Style["f(x)", FontSize -> 18]}, 
  LabelStyle -> {Directive[FontSize -> 14]}, 
  Ticks -> {{0, 0.5}, {0, 0.5}}]

enter image description here

$\endgroup$
4
  • $\begingroup$ I want to plot all 3 graphs in one graph and also for different d with their type that mentioned in code $\endgroup$
    – Sasan
    Commented Oct 9, 2018 at 11:58
  • $\begingroup$ @Sasan, Modified, Now take a look. $\endgroup$ Commented Oct 9, 2018 at 12:08
  • $\begingroup$ Thanks a lot! It works good! $\endgroup$
    – Sasan
    Commented Oct 9, 2018 at 12:22
  • $\begingroup$ @Sasan If it has helped you, then you may accept it as an answer. $\endgroup$ Commented Oct 9, 2018 at 12:45

Your Answer

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

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