Re: legend scaling

• To: mathgroup at smc.vnet.net
• Subject: [mg54471] Re: [mg54446] legend scaling
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Mon, 21 Feb 2005 03:44:40 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```1. Use a LegendLabel so that you can shorten the individual legends.
2. Scale the LegendSize and LegendPosition with the ImageSize.
3. Wrap the y AxesLabel

If this is not what you want it should at least suggest an approach.

Bob Hanlon

imSize = 400;
EngineTorqueVsEngineSpeedData =
{1000, 1400, 2100, 2800, 3500, 4200, 4900, 5300, 5700},
{61.0, 67.6, 73.7, 78.5,
80.9, 77.3, 76.2, 73.3, 68.7} kg m^2/s^2/rad}];
EnginePowerVsEngineSpeedData =
{#1, #1 #2} &[Sequence @@ #] & /@ EngineTorqueVsEngineSpeedData;
EnginePowerVsEngineSpeed = MapAt[Evaluate,
(Interpolation[{#1 (rad/s)^-1, #2 (kg m^2/s^3)^-1} &[
Sequence @@ #] & /@ EnginePowerVsEngineSpeedData][# \
DrivelineEfficiency[TransmissionReductionRatio_] =
1 - (0.06 + TransmissionReductionRatio^1.5/100);
FinalDriveReductionRatio =
(*Interval[{Min[#], Max[#]} &@Rationalize[*){2.95, 3.55, 3.73}(*]]*);
RollingResistanceCoefficient = 0.015;
CoefficientOfDrag = 0.335;
Area = 2 m^2;
g = 9.81 m/s^2;
CurbWeight = g 1350 kg;
AirDensity = 100000/(286.9*298.15) (kg/m^3);
CarSpeed*(1/2*AirDensity*CarSpeed^2*CoefficientOfDrag*Area +
N[DesiredTopSpeed = 140 km/h*1000 m/km/(3600 s/h)];
CarSpeedAtTopEngineSpeed =
CarSpeed /. EngineSpeed -> EngineTorqueVsEngineSpeedData[[-1, 1]];
TypeBTopSpeedDifference =
DesiredTopSpeed - CarSpeedAtTopEngineSpeed;
LastGearReductionRatioSolution =
Map[Solve[# == 0, TransmissionReductionRatio][[1]] &,
TypeBTopSpeedDifference, {2}];
DisplayLastGearReductionRatio =
Array[junk, Drop[Dimensions[LastGearReductionRatioSolution], -1] + 1];
DisplayLastGearReductionRatio[[Sequence @@ (Range[2, #] & /@
(Drop[Dimensions[LastGearReductionRatioSolution], -1] + 1))]] =
TransmissionReductionRatio /.
LastGearReductionRatioSolution;
DisplayLastGearReductionRatio[[Range[2, #] &[
DisplayLastGearReductionRatio[[1, Range[2, #] &[
Length[FinalDriveReductionRatio] + 1]]] =
FinalDriveReductionRatio;
DisplayLastGearReductionRatio[[1, 1]] = "4th Gear";
TableForm[DisplayLastGearReductionRatio // N,
{"Final", "Drive", "Reduction", "Ratio"}}]
TopGearNVRatio =
EngineTorqueVsEngineSpeedData[[-1, 1]]/CarSpeedAtTopEngineSpeed /.
TransmissionReductionRatio -> 1;
Needs["Graphics`"];
MultipleListPlot[
Append[#, Level[#, {Length@Dimensions@#} - 1] &@
ReplaceAll[#, Line[pts_] :>
List /@ pts] &@First@
Block[{\$DisplayFunction =
CarSpeed*1000 m/(3600 s), 0] /.
kg m^2/s^3 -> W /. W -> 1/1000,
{CarSpeed, 0, 160}]]] &@Level[#, {2}] &@
(# /. kg m^2/s^3 -> W /. W -> 1/1000 /.
{m -> 1/1000, s -> 1/3600} /.
TransmissionReductionRatio -> 1) &@Map[
ReleaseHold@ReplacePart[Function[{CarSpeedDummyVariable},
Null],
Apply[{Hold[
CarSpeedDummyVariable /. EngineSpeed -> #1], \
DrivelineEfficiency[TransmissionReductionRatio] #2} &,
EnginePowerVsEngineSpeedData, {1}], 2], CarSpeed, {2}],
PlotJoined -> True,
SymbolShape -> Append[#, None] &@

Take[#, \
&@Apply[PlotSymbol[#1,
Filled -> #2] &, #, {1}] &@Flatten[#, 1] &@
Outer[List, {Box, Diamond, Star, Triangle}, {True, False}], PlotLegend \
Outer["Radius: " <> ToString[#1 /. m -> 100 cm] <>
", Ratio: " <> ToString[#2] &,
ImageSize -> imSize,
LegendSize -> {450, 300}/imSize,
LegendPosition -> {-250, -5/8imSize - 320}/imSize,
LegendSpacing -> -.3,
LegendTextSpace -> Automatic,
LegendLabel -> "     Rolling Radius & \nFinal Drive Reduction Ratio",
AxesLabel -> {"Speed\n(kph)", "Power\n(kW)"},

>
> From: Chris Chiasson <chris.chiasson at gmail.com>
To: mathgroup at smc.vnet.net
> Date: 2005/02/20 Sun AM 12:10:48 EST
> To: mathgroup at smc.vnet.net
> Subject: [mg54471] [mg54446] legend scaling
>
> Dear MathGroup,
>
> Below, I have attached code that is part of one of my homework
> assignments in my powertrain class. The code contains all input
> statements up to and including a graph I am working on. I mapped
> steady state 100% throttle engine power to top gear vehicle speed for
> power onto the same graph. My concern is with the legend below the
> graph. If I change the ImageSize->600 argument in the last command,
> the legend box becomes larger or smaller. How do I make sure that no
> matter what size I choose for the ImageSize, that the legend always
> stays nicely wrapped around the legend text? Thank you in advance for
>
> EngineTorqueVsEngineSpeedData=
@{1000,1400,2100,2800,3500,4200,4900,5300,
>             5700},{61.0,67.6,73.7,78.5,80.9,77.3,76.2,73.3,68.7} kg m^2/
s^2/
> EnginePowerVsEngineSpeedData={#1,#1 #2}&[Sequence@@#]&/@
>       EngineTorqueVsEngineSpeedData;
> EnginePowerVsEngineSpeed=
>                       Sequence@@#]&/@
s^3&),1];
> DrivelineEfficiency[TransmissionReductionRatio_]=
>     1-(0.06+TransmissionReductionRatio^1.5/100);
>
FinalDriveReductionRatio=(*Interval[{Min[#],Max[#]}&@Rationalize[*){2.95,3.5
5,
>       3.73}(*]]*);
> RollingResistanceCoefficient=0.015;
> CoefficientOfDrag=0.335;
> Area=2 m^2;
> g=9.81 m/s^2;
> CurbWeight=g 1350 kg;
> AirDensity=100000/(286.9*298.15) (kg/m^3);
>       CarSpeed*(1/2*AirDensity*CarSpeed^2*CoefficientOfDrag*Area+
> N[DesiredTopSpeed=140 km/h*1000 m/km/(3600 s/h)];
FinalDriveReductionRatio];
> CarSpeedAtTopEngineSpeed=
>     CarSpeed/.EngineSpeed->EngineTorqueVsEngineSpeedData[[-1,1]];
> TypeBTopSpeedDifference=DesiredTopSpeed-CarSpeedAtTopEngineSpeed;
> LastGearReductionRatioSolution=
>     Map[Solve[# ==0,TransmissionReductionRatio][[1]]&,
>       TypeBTopSpeedDifference,{2}];
> DisplayLastGearReductionRatio=
>     Array[junk,Drop[Dimensions[LastGearReductionRatioSolution],-1]+1];
> DisplayLastGearReductionRatio[[
>       Sequence@@(Range[
>                 2,#]&/@(Drop[
>                   Dimensions[LastGearReductionRatioSolution],-1]+1))]]=
>     TransmissionReductionRatio/.LastGearReductionRatioSolution;
> DisplayLastGearReductionRatio[[1,
>       Range[2,#]&[Length[FinalDriveReductionRatio]+1]]]=
>     FinalDriveReductionRatio;
> DisplayLastGearReductionRatio[[1,1]]="4th Gear";
> TableForm[DisplayLastGearReductionRatio//N,
>         "Ratio"}}]
> TopGearNVRatio=
>     EngineTorqueVsEngineSpeedData[[-1,1]]/
>         CarSpeedAtTopEngineSpeed/.TransmissionReductionRatio\[Rule]1;
> Needs["Graphics`MultipleListPlot`"]
> MultipleListPlot[
>   Append[#,Level[#,{Length@Dimensions@#}-1]&@
>                           ReplaceAll[#,Line[pts_]\[RuleDelayed]List/@pts]&@
>                       First@Block[{\$DisplayFunction=Identity},
>                           ReleaseHold[#]]&@
>                   Hold[Plot[
s^3->
>                             W/.W->1/1000,{CarSpeed,0,160}]]]&@
>             Level[#,{2}]&@(#/.kg m^2/s^3->W/.W->1/1000/.{m\[Rule]1/1000,
>                 s\[Rule]1/3600}/.TransmissionReductionRatio\[Rule]1)&@
>     Map[ReleaseHold@
>         ReplacePart[Function[{CarSpeedDummyVariable},Null],
>           Apply[{Hold[CarSpeedDummyVariable/.EngineSpeed\[Rule]#1],
>                 DrivelineEfficiency[TransmissionReductionRatio] #2}&,
>             EnginePowerVsEngineSpeedData,{1}],2],CarSpeed,{2}],
>   PlotJoined\[Rule]True,
>   SymbolShape\[Rule]Append[#,None]&@
>                     Length[FinalDriveReductionRatio]]&@
>             Apply[PlotSymbol[#1,Filled\[Rule]#2]&,#,{1}]&@Flatten[#,1]&@
>     Outer[List,{Box,Diamond,Star,Triangle},{True,False}],
>     Level[Outer[
>             ", Final Drive Reduction Ratio: "<>ToString[#2]&,RollingRadius,
>         FinalDriveReductionRatio],{2}],ImageSize\[Rule]600,
>   LegendSize\[Rule]{1.6,0.5},LegendPosition\[Rule]{-.75,-1.25},
>   LegendSpacing\[Rule]-.3,LegendTextSpace\[Rule]Automatic,
>   AxesLabel\[Rule]{"Speed (kph)","Power (kW)"},
>
> Regards,
> --
> Chris Chiasson
> Kettering University
> Mechanical Engineering