Message Boards Message Boards

Convert code V4.1 into code V11?

Posted 6 years ago

Hi all,

I'm struggling with rewriting of some old code from mathematica V4.1....I'm using V11. I have problems with follwoing (old) commands:

ShowLegend
MultipleListPlot
LegendPosition

That's the code which I try to bring it into V11.

<< Graphics`Legend`
<< Graphics`MultipleListPlot`
a1 = 1.5; a2 = 3; a3 = 6;
X = 1000;
\[Lambda] = 0.01;
R = Range[-10.01, 10.01, 0.1];
I1[R_] := (BesselJ[1, 
      2*Pi*a1*(R/(\[Lambda]*X))]/(2*Pi*a1*(R/(\[Lambda]*X))))^2;
I2[R_] := (BesselJ[1, 
      2*Pi*a2*(R/(\[Lambda]*X))]/(2*Pi*a2*(R/(\[Lambda]*X))))^2;
I3[R_] := (BesselJ[1, 
      2*Pi*a3*(R/(\[Lambda]*X))]/(2*Pi*a3*(R/(\[Lambda]*X))))^2;


ShowLegend[
  MultipleListPlot[Transpose[{R, I1[R]}], Transpose[{R, I2[R]}], 
   Transpose[{R, I3[R]}], PlotJoined -> True, 
   DisplayFunction -> Identity, 
   PlotStyle -> {Hue[1], Hue[0.5], Hue[0.25]}, 
   AxesLabel -> {"R", "I"}, 
   PlotRange -> {{-15, 10}, {0, 0.3}}], {{{Hue[1], 
     "I1[R]"}, {Hue[0.5], "I2[R]"}, {Hue[0.25], "I3[R]"}}, 
   LegendPosition -> {1.1, -0}}];

I would be grateful for your support!

POSTED BY: Nikki Peter
2 Replies

For starters:

a1 = 1.5; a2 = 3; a3 = 6;
X = 1000;
\[Lambda] = 0.01;
R = Range[-10.01, 10.01, 0.1];
I1[R_] := (BesselJ[1, 2*Pi*a1*(R/(\[Lambda]*X))]/(2*Pi*a1*(R/(\[Lambda]*X))))^2;
I2[R_] := (BesselJ[1, 2*Pi*a2*(R/(\[Lambda]*X))]/(2*Pi*a2*(R/(\[Lambda]*X))))^2;
I3[R_] := (BesselJ[1,  2*Pi*a3*(R/(\[Lambda]*X))]/(2*Pi*a3*(R/(\[Lambda]*X))))^2;

With[{data = Transpose /@ {{R, I1[R]}, {R, I2[R]}, {R, I3[R]}}},
 ListLinePlot[data, AxesLabel -> {"R", "I"},
  PlotRange -> {{-15, 10}, {0, 0.3}}, 
  PlotLegends -> {"I1[R]", "I2[R]", "I3[R]"}]
 ]

Mathematica graphics

You can include your PlotStyle if you like (looks a bit old-school) and you can wrap the list of legend-strings with Placed to give an exact position.

POSTED BY: Patrick Scheibe

You need to look in the documentation for similar functionality. The Legend package, for example, was obsoleted in 5.2, and that functionality was folded into the main system in v 9. Check the Guide page

http://reference.wolfram.com/language/guide/Legends.html

The same guide page is in the desktop Documentation center. I hesitate to provide a direct replacement, since the functionality has been expanded, and you may prefer some of the new functionality, rather than just recreating the old.

The same thing applies for MultipleListPlot.

You can just use ListPlot[{plot1, plot2}], where, in your case, plot1 is Transpose[{R, I1[R]}], etc.

In general, there are very few add-on packages in the current Mathematica. Not all the obsolete code may be in the desktop Documentation center, but most of it seems to be in the on-line version. In most cases, it is pretty obvious which new functions replace the old.

Hope this helps.

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