Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: plot legend with filling

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126973] Re: plot legend with filling
  • From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
  • Date: Thu, 21 Jun 2012 05:19:11 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Dear group:
I have two arrays of numbers, think of something like this:
v1={{1.15,0},{1.15,3},{2.15,1},{2.15,7},{3.15,3},{3.15,9},{4.15,5},{4.15,7}}
v2={{1,1},{1,5},{2,1.8},{2,6},{3,3.5},{3,10},{4,4},{4,6}}

I want to make a graph with these two arrays, where I get:
a. A line from the x axis to each point in each array
b. A legend, with say v1 red and v2  blue
c. Each array has its own filling style (different color, thickness, etc.).

The problem is that I can find ways of plugging in two of these characteristics, but not all three. For example:
<<PlotLegends`
p1=ListPlot[v1,  Filling->Axis, FillingStyle->Directive[AbsoluteThickness[4], Blue]]
p2=p2=ListPlot[v2,  Filling->Axis, FillingStyle->Directive[AbsoluteThickness[4], Red]]
Show[p1,p2], but then I did not manage to find the way of using Show and PlotLegend at the same time.

Or I can put both arrays into a Listplot command, but then I did not find how to attribute a different color AND thickness to the filling of each array.
I'm using Mathematica 8
Can somebody help me?

Francisco

Hi, Francisco,

It is better, if you draw the legend yourself: in this case you have more control. Try this, for example:

v1 = {{1.15, 0}, {1.15, 3}, {2.15, 1}, {2.15, 7}, {3.15, 3}, {3.15,
    9}, {4.15, 5}, {4.15, 7}};
v2 = {{1, 1}, {1, 5}, {2, 1.8}, {2, 6}, {3, 3.5}, {3, 10}, {4, 4}, {4,
     6}};

(* Here are 2 examples of panels with a legend: *)

pan1 = Panel[Column[{
     Row[{Graphics[{Blue, AbsoluteThickness[4],
         Line[{Scaled[{0, 0.6}], Scaled[{0.4, 0.6}]}]},
        ImageSize -> {30, 10}],
       Style["My text1", Blue, 10]}],
     Row[{Graphics[{Red, AbsoluteThickness[4],
         Line[{Scaled[{0, 0.5}], Scaled[{0.4, 0.5}]}]},
        ImageSize -> {30, 10}],
       Style["My text2", Red, 10]}]
     }], ImageSize -> {95, 50}];

pan2 = Framed[Panel[Column[{
      Row[{Graphics[{Blue, AbsoluteThickness[4],
          Line[{Scaled[{0, 0.6}], Scaled[{0.4, 0.6}]}]},
         ImageSize -> {30, 10}],
        Style["My text1", Blue, 10]}],
      Row[{Graphics[{Red, AbsoluteThickness[4],
          Line[{Scaled[{0, 0.5}], Scaled[{0.4, 0.5}]}]},
         ImageSize -> {30, 10}],
        Style["My text2", Red, 10]}]
      }], ImageSize -> {95, 50}, Background -> White]];



p1 = ListPlot[v1, Filling -> Axis,
   FillingStyle -> Directive[AbsoluteThickness[4], Blue]];
p2 = p2 =
   ListPlot[v2, Filling -> Axis,
    FillingStyle -> Directive[AbsoluteThickness[4], Red]];


Show[p1, p2, Epilog -> Inset[pan1, Scaled[{0.82, 0.86}]]]


You may then play with position of the panel entitled "pan1" (under the Epilog/Inset) and its size found in the end of its definition.
You can also change the panel appearance, if you want, such as fixing the background to white. Then use the panel pan2 instead of pan1 under the Epilog/Inset.

Have fun, Alexei 


Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at iee.lu






  • Prev by Date: Re: plot legend with filling
  • Next by Date: Re: Varying a constant in an ODE to Manipulate solution
  • Previous by thread: Re: plot legend with filling
  • Next by thread: Re: plot legend with filling