Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

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)
  • Reply-to: hanlonr at cox.net
  • 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 =
    Transpose[{# 2?/60 (rad)/s & /@
          {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][# \
(rad/s)^-1]kg m^2/s^3 &), 1];
DrivelineEfficiency[TransmissionReductionRatio_] =
    1 - (0.06 + TransmissionReductionRatio^1.5/100);
FinalDriveReductionRatio =
    (*Interval[{Min[#], Max[#]} &@Rationalize[*){2.95, 3.55, 3.73}(*]]*);
RollingRadius =(*Interval[*){300/1000, 310/1000}(*]*) m;
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);
RoadLoadPower =
    Function[{CarSpeed, GradeAngle},
      CarSpeed*(1/2*AirDensity*CarSpeed^2*CoefficientOfDrag*Area +
            RollingResistanceCoefficient*CurbWeight*Cos[GradeAngle] +
            CurbWeight*Sin[GradeAngle])];
N[DesiredTopSpeed = 140 km/h*1000 m/km/(3600 s/h)];
Outer[Times, RollingRadius,
    1/rad/TransmissionReductionRatio/FinalDriveReductionRatio];
CarSpeed = Outer[Times, RollingRadius,
      EngineSpeed/rad/TransmissionReductionRatio/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[[Range[2, #] &[
          Length[RollingRadius] + 1], 1]] =
    RollingRadius;
DisplayLastGearReductionRatio[[1, Range[2, #] &[
          Length[FinalDriveReductionRatio] + 1]]] =
    FinalDriveReductionRatio;
DisplayLastGearReductionRatio[[1, 1]] = "4th Gear";
TableForm[DisplayLastGearReductionRatio // N,
  TableHeadings -> {{"Rolling", "", "Radius"},
      {"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 = 
    Identity}, ReleaseHold[#]] &@Hold[Plot[RoadLoadPower[
    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[#, \
Length[RollingRadius]*Length[FinalDriveReductionRatio]] 
&@Apply[PlotSymbol[#1,
                   Filled -> #2] &, #, {1}] &@Flatten[#, 1] &@
      Outer[List, {Box, Diamond, Star, Triangle}, {True, False}], PlotLegend \
-> Append[#, "Road Load"] &@Level[
        Outer["Radius: " <> ToString[#1 /. m -> 100 cm] <>
              ", Ratio: " <> ToString[#2] &,
          RollingRadius, FinalDriveReductionRatio], {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)"},
    PlotLabel -> "Top Gear Power Curves and Road Load"];

> 
> 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
> different drivetrain configurations. I superimposed the road load
> 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
> your valuable time.
> 
> EngineTorqueVsEngineSpeedData=
>     Transpose[{# 2\[Pi]/60 (rad)/s&/
@{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][# (rad/s)^-1]kg m^2/
s^3&),1];
> DrivelineEfficiency[TransmissionReductionRatio_]=
>     1-(0.06+TransmissionReductionRatio^1.5/100);
> 
FinalDriveReductionRatio=(*Interval[{Min[#],Max[#]}&@Rationalize[*){2.95,3.5
5,
>       3.73}(*]]*);
> RollingRadius=(*Interval[*){300/1000 ,310/1000}(*]*) m;
> 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);
> RoadLoadPower=
>     Function[{CarSpeed,GradeAngle},
>       CarSpeed*(1/2*AirDensity*CarSpeed^2*CoefficientOfDrag*Area+
>             RollingResistanceCoefficient*CurbWeight*Cos[GradeAngle]+
>             CurbWeight*Sin[GradeAngle])];
> N[DesiredTopSpeed=140 km/h*1000 m/km/(3600 s/h)];
> Outer[Times,RollingRadius,
>     1/rad/TransmissionReductionRatio/FinalDriveReductionRatio];
> CarSpeed=Outer[Times,RollingRadius,
>       EngineSpeed/rad/TransmissionReductionRatio/
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[[Range[2,#]&[Length[RollingRadius]+1],1]]=
>     RollingRadius;
> DisplayLastGearReductionRatio[[1,
>       Range[2,#]&[Length[FinalDriveReductionRatio]+1]]]=
>     FinalDriveReductionRatio;
> DisplayLastGearReductionRatio[[1,1]]="4th Gear";
> TableForm[DisplayLastGearReductionRatio//N,
>   TableHeadings\[Rule]{{"Rolling","","Radius"},{"Final","Drive","Reduction",
>         "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[
>                       RoadLoadPower[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\[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]&@
>                 Take[#,Length[RollingRadius]*
>                     Length[FinalDriveReductionRatio]]&@
>             Apply[PlotSymbol[#1,Filled\[Rule]#2]&,#,{1}]&@Flatten[#,1]&@
>     Outer[List,{Box,Diamond,Star,Triangle},{True,False}],
>   PlotLegend\[Rule]Append[#,"Road Load"]&@
>     Level[Outer[
>         "Rolling Radius: "<>ToString[#1/.m\[Rule]100 cm]<>
>             ", 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)"},
>   PlotLabel->"Top Gear Power Curves and Road Load"]
> 
> Regards,
> -- 
> Chris Chiasson
> Kettering University
> Mechanical Engineering
> Graduate Student
> 1 810 265 3161
> 
> 


  • Prev by Date: Re: legend scaling
  • Next by Date: keyboard shortkey needed
  • Previous by thread: Re: legend scaling
  • Next by thread: Kalman Filter in Mathematica