Skip to main content
the picture did not match the code :)
Source Link
gwr
  • 13.6k
  • 2
  • 48
  • 82

There are probably a lot of ways to do this, I will just demonstrate a simple, straight forward ways with which you might experiment.

First we set up a global variable that assigns aspect ratio functions:

$aspectRatioFunctions = Function[ func,
    Switch[ func,
        "ratio2", Function[ {p1,p2}, 2 p1/p2 ],
        "ratio3", Function[ {p1,p2}, p1 / (3 p2) ],
        _ , Function[ {p1, p2}, p1/p2 ] (* ratio1 as Default *)

    ]
];

We can now use this in a simple plotgraphics function or whatever custom function you want to build upon:

Options[ myGraphics ] = {
    "AspectRatioFunction" -> "ratio1"
};

myGraphics[ graphics_List, aspectPars_ , 
    opts : OptionsPattern[{ myGraphics, Graphics }] ] := With[
    {
        aspectRatio = Apply[
            $aspectRatioFunctions@OptionValue["AspectRatioFunction"],
            aspectPars
        ]
   },
   Graphics[
       graphics,
       Evaluate@FilterRules[ {opts}, Options[Graphics] ], (* more robust *)
       AspectRatio -> aspectRatio
   ]
]

gr = { Red, Line[{{1, 1}, {2, 2}}] }

myGraphics[ gr, { 1, 101 }, AspectRatioFunction -> "ratio2", Imagesize -> Tiny ]

Ratio2

There are probably a lot of ways to do this, I will just demonstrate a simple, straight forward ways with which you might experiment.

First we set up a global variable that assigns aspect ratio functions:

$aspectRatioFunctions = Function[ func,
    Switch[ func,
        "ratio2", Function[ {p1,p2}, 2 p1/p2 ],
        "ratio3", Function[ {p1,p2}, p1 / (3 p2) ],
        _ , Function[ {p1, p2}, p1/p2 ] (* ratio1 as Default *)

    ]
];

We can now use this in a simple plot function or whatever custom function you want to build:

Options[ myGraphics ] = {
    "AspectRatioFunction" -> "ratio1"
};

myGraphics[ graphics_List, aspectPars_ , 
    opts : OptionsPattern[{ myGraphics, Graphics }] ] := With[
    {
        aspectRatio = Apply[
            $aspectRatioFunctions@OptionValue["AspectRatioFunction"],
            aspectPars
        ]
   },
   Graphics[
       graphics,
       Evaluate@FilterRules[ {opts}, Options[Graphics] ], (* more robust *)
       AspectRatio -> aspectRatio
   ]
]

gr = { Red, Line[{{1, 1}, {2, 2}}] }

myGraphics[ gr, { 1, 10}, AspectRatioFunction -> "ratio2", Imagesize -> Tiny ]

Ratio2

There are probably a lot of ways to do this, I will just demonstrate a simple, straight forward ways with which you might experiment.

First we set up a global variable that assigns aspect ratio functions:

$aspectRatioFunctions = Function[ func,
    Switch[ func,
        "ratio2", Function[ {p1,p2}, 2 p1/p2 ],
        "ratio3", Function[ {p1,p2}, p1 / (3 p2) ],
        _ , Function[ {p1, p2}, p1/p2 ] (* ratio1 as Default *)

    ]
];

We can now use this in a simple graphics function or whatever custom function you want to build upon:

Options[ myGraphics ] = {
    "AspectRatioFunction" -> "ratio1"
};

myGraphics[ graphics_List, aspectPars_ , 
    opts : OptionsPattern[{ myGraphics, Graphics }] ] := With[
    {
        aspectRatio = Apply[
            $aspectRatioFunctions@OptionValue["AspectRatioFunction"],
            aspectPars
        ]
   },
   Graphics[
       graphics,
       Evaluate@FilterRules[ {opts}, Options[Graphics] ], (* more robust *)
       AspectRatio -> aspectRatio
   ]
]

gr = { Red, Line[{{1, 1}, {2, 2}}] }

myGraphics[ gr, { 1, 1 }, AspectRatioFunction -> "ratio2", Imagesize -> Tiny ]

Ratio2

improved code for robustness
Source Link
gwr
  • 13.6k
  • 2
  • 48
  • 82

There are probably a lot of ways to do this, I will just demonstrate a simple, straight forward ways with which you might experiment.

First we set up a global variable that assigns aspect ratio functions:

$aspectRatioFunctions = Function[ func,
    Switch[ func,
        "ratio2", Function[ {p1,p2}, 2 p1/p2 ],
        "ratio3", Function[ {p1,p2}, p1 / (3 p2) ],
        _ , Function[ {p1, p2}, p1/p2 ] (* ratio1 as Default *)

    ]
];

We can now use this in a simple plot function or whatever custom function you want to build:

Options[ myGraphics ] = {
    "AspectRatioFunction" -> "ratio1"
};

myGraphics[ graphics_List, aspectPars_ , 
    opts : OptionsPattern[{ myGraphics, Graphics }] ] := With[
    {
        aspectRatio = Apply[
            $aspectRatioFunctions@OptionValue["AspectRatioFunction"],
            aspectPars
        ]
   },
   Graphics[
       graphics,
       Evaluate@FilterRules[ {opts}, Options[Graphics] ], (* more robust *)
       AspectRatio -> aspectRatio
   ]
]

gr = { Red, Line[{{1, 1}, {2, 2}}] }

myGraphics[ gr, { 1, 10}, AspectRatioFunction -> "ratio2", Imagesize -> Tiny ]

Ratio2

There are probably a lot of ways to do this, I will just demonstrate a simple, straight forward ways with which you might experiment.

First we set up a global variable that assigns aspect ratio functions:

$aspectRatioFunctions = Function[ func,
    Switch[ func,
        "ratio2", Function[ {p1,p2}, 2 p1/p2 ],
        "ratio3", Function[ {p1,p2}, p1 / (3 p2) ],
        _ , Function[ {p1, p2}, p1/p2 ] (* ratio1 as Default *)

    ]
];

We can now use this in a simple plot function or whatever custom function you want to build:

Options[ myGraphics ] = {
    "AspectRatioFunction" -> "ratio1"
};

myGraphics[ graphics_List, aspectPars_ , 
    opts : OptionsPattern[{ myGraphics, Graphics }] ] := With[
    {
        aspectRatio = Apply[
            $aspectRatioFunctions@OptionValue["AspectRatioFunction"],
            aspectPars
        ]
   },
   Graphics[
       graphics,
       opts,
       AspectRatio -> aspectRatio
   ]
]

gr = { Red, Line[{{1, 1}, {2, 2}}] }

myGraphics[ gr, { 1, 10}, AspectRatioFunction -> "ratio2", Imagesize -> Tiny ]

Ratio2

There are probably a lot of ways to do this, I will just demonstrate a simple, straight forward ways with which you might experiment.

First we set up a global variable that assigns aspect ratio functions:

$aspectRatioFunctions = Function[ func,
    Switch[ func,
        "ratio2", Function[ {p1,p2}, 2 p1/p2 ],
        "ratio3", Function[ {p1,p2}, p1 / (3 p2) ],
        _ , Function[ {p1, p2}, p1/p2 ] (* ratio1 as Default *)

    ]
];

We can now use this in a simple plot function or whatever custom function you want to build:

Options[ myGraphics ] = {
    "AspectRatioFunction" -> "ratio1"
};

myGraphics[ graphics_List, aspectPars_ , 
    opts : OptionsPattern[{ myGraphics, Graphics }] ] := With[
    {
        aspectRatio = Apply[
            $aspectRatioFunctions@OptionValue["AspectRatioFunction"],
            aspectPars
        ]
   },
   Graphics[
       graphics,
       Evaluate@FilterRules[ {opts}, Options[Graphics] ], (* more robust *)
       AspectRatio -> aspectRatio
   ]
]

gr = { Red, Line[{{1, 1}, {2, 2}}] }

myGraphics[ gr, { 1, 10}, AspectRatioFunction -> "ratio2", Imagesize -> Tiny ]

Ratio2

changed the order within OptionsPattern
Source Link
gwr
  • 13.6k
  • 2
  • 48
  • 82

There are probably a lot of ways to do this, I will just demonstrate a simple, straight forward ways with which you might experiment.

First we set up a global variable that assigns aspect ratio functions:

$aspectRatioFunctions = Function[ func,
    Switch[ func,
        "ratio2", Function[ {p1,p2}, 2 p1/p2 ],
        "ratio3", Function[ {p1,p2}, p1 / (3 p2) ],
        _ , Function[ {p1, p2}, p1/p2 ] (* ratio1 as Default *)

    ]
];

We can now use this in a simple plot function or whatever custom function you want to build:

Options[ myGraphics ] = {
    "AspectRatioFunction" -> "ratio1"
};

myGraphics[ graphics_List, aspectPars_ , 
    opts : OptionsPattern[{ GraphicsmyGraphics, myGraphicsGraphics }] ] := With[
    {
        aspectRatio = Apply[
            $aspectRatioFunctions@OptionValue["AspectRatioFunction"],
            aspectPars
        ]
   },
   Graphics[
       graphics,
       opts,
       AspectRatio -> aspectRatio
   ]
]

gr = { Red, Line[{{1, 1}, {2, 2}}] }

myGraphics[ gr, { 1, 10}, AspectRatioFunction -> "ratio2", Imagesize -> Tiny ]

Ratio2

There are probably a lot of ways to do this, I will just demonstrate a simple, straight forward ways with which you might experiment.

First we set up a global variable that assigns aspect ratio functions:

$aspectRatioFunctions = Function[ func,
    Switch[ func,
        "ratio2", Function[ {p1,p2}, 2 p1/p2 ],
        "ratio3", Function[ {p1,p2}, p1 / (3 p2) ],
        _ , Function[ {p1, p2}, p1/p2 ] (* ratio1 as Default *)

    ]
];

We can now use this in a simple plot function or whatever custom function you want to build:

Options[ myGraphics ] = {
    "AspectRatioFunction" -> "ratio1"
};

myGraphics[ graphics_List, aspectPars_ , 
    opts : OptionsPattern[{ Graphics, myGraphics }] ] := With[
    {
        aspectRatio = Apply[
            $aspectRatioFunctions@OptionValue["AspectRatioFunction"],
            aspectPars
        ]
   },
   Graphics[
       graphics,
       opts,
       AspectRatio -> aspectRatio
   ]
]

gr = { Red, Line[{{1, 1}, {2, 2}}] }

myGraphics[ gr, { 1, 10}, AspectRatioFunction -> "ratio2", Imagesize -> Tiny ]

Ratio2

There are probably a lot of ways to do this, I will just demonstrate a simple, straight forward ways with which you might experiment.

First we set up a global variable that assigns aspect ratio functions:

$aspectRatioFunctions = Function[ func,
    Switch[ func,
        "ratio2", Function[ {p1,p2}, 2 p1/p2 ],
        "ratio3", Function[ {p1,p2}, p1 / (3 p2) ],
        _ , Function[ {p1, p2}, p1/p2 ] (* ratio1 as Default *)

    ]
];

We can now use this in a simple plot function or whatever custom function you want to build:

Options[ myGraphics ] = {
    "AspectRatioFunction" -> "ratio1"
};

myGraphics[ graphics_List, aspectPars_ , 
    opts : OptionsPattern[{ myGraphics, Graphics }] ] := With[
    {
        aspectRatio = Apply[
            $aspectRatioFunctions@OptionValue["AspectRatioFunction"],
            aspectPars
        ]
   },
   Graphics[
       graphics,
       opts,
       AspectRatio -> aspectRatio
   ]
]

gr = { Red, Line[{{1, 1}, {2, 2}}] }

myGraphics[ gr, { 1, 10}, AspectRatioFunction -> "ratio2", Imagesize -> Tiny ]

Ratio2

Source Link
gwr
  • 13.6k
  • 2
  • 48
  • 82
Loading