4
$\begingroup$

I use ContourPlot,PolarPlot,Graph to plot. For example:

ContourPlot[x^2/3 + y^2/9 == 1, {x, -10, 10}, {y, -10, 10},
   PlotPoints -> 100, MaxRecursion->1]  

I get plot like:
enter image description here

I want this plot object to be 2 times bigger, then

ContourPlot[(0.5x)^2/3+(0.5*y)^2/9 == 1, {x, -10, 10},{y, -10, 10},
  PlotPoints -> 100, MaxRecursion -> 1]

get plot as my will:

enter image description here

But my method is primitive. What's a better general method that can be used for various plot functions?

$\endgroup$

2 Answers 2

4
$\begingroup$

You can use ScalingTransform on the graphics primitives:

ClearAll[resize]
resize[sc_] :=  MapAt[GeometricTransformation[#, ScalingTransform[sc]] &, #, {1}] &;

Examples:

cp = ContourPlot[x^2/3 + y^2/9 == 1, {x, -10, 10}, {y, -10, 10}, 
   PlotPoints -> 100, MaxRecursion -> 1, ImageSize -> 300];
Row[{cp, resize[{3, 3}] @ cp}]

enter image description here

pp = PolarPlot[Sin[3 t], {t, 0, Pi}, Frame -> True, FrameTicks -> All,
    PlotRange -> {{-5, 5}, {-5, 5}}, ImageSize -> 300];
Row[{pp, resize[{3, 3}] @ pp}]

enter image description here

For a Graph object gr, you need first wrap gr with Show to get a Graphics object before using resize on it:

gr = Graph[{1 -> 2, 2 -> 3,  3 -> 1}, Frame -> True, FrameTicks -> All, 
   PlotRange -> {{-5, 5}, {-5, 5}}, ImageSize -> 300];
Row[{gr, resize[{3, 3}] @ Show @ gr}]

enter image description here

For 3D plots use a list with three numbers, one for each dimension, as the scaling parameter:

cp3d = ContourPlot3D[Cos[x] + Cos[y] + Cos[z] == 0, {x, -π, π}, {y, -π, π}, {z, -π,  π}, 
  PlotRange -> {{-4 π, 4 π}, {-4 π, 4 π}, {-4 π, 4 π}}, Mesh -> None, ImageSize -> 300];
Row[{cp3d, resize[{2, 3, 3}] @ cp3d}]

enter image description here

$\endgroup$
0
$\begingroup$

Use Manipulate

Manipulate[
 ContourPlot[x^2/a^2 + y^2/b^2 == f^2,
  {x, -10, 10}, {y, -10, 10},
  PlotLabel -> TraditionalForm[x^2/"a"^2 + y^2/"b"^2 == "f"^2]],
 {{a, Sqrt[3], "x control (a)"}, 1, 5, Appearance -> "Labeled"},
 {{b, 3, "y control (b)"}, 1, 5, Appearance -> "Labeled"},
 {{f, 1, "scale (f)"}, .25, 3, .05, Appearance -> "Labeled"}]

enter image description here

EDIT: The f^2 above resulted from dividing both x and y by f and simplifying the equation by multiplying through by f^2. In general, scaling all x and y by f won't produce a simple f^2 factor but you still want to divide all of the occurrences of x and y by f.

Manipulate[
 ContourPlot[
  (x/f)^(3/2) - Sqrt[1.65]*(x/f) + (y/f)^2 == 0,
  {x, -20, 20}, {y, -20, 20}],
 {{f, 1, "scale (f)"}, 1, 12, 1, Appearance -> "Labeled"}]

enter image description here

$\endgroup$
3
  • $\begingroup$ If the object is not ellipse,this method doesn't work. $\endgroup$
    – kittygirl
    Mar 8, 2018 at 0:48
  • $\begingroup$ @kittygirl - so what implicit equation is causing a problem? $\endgroup$
    – Bob Hanlon
    Mar 8, 2018 at 0:52
  • $\begingroup$ ,ContourPlot[ Power[(x), 3/2] - Power[1.65, 0.5]*(x) + ((y))^2 == 0, {x, -20, 20}, {y, -20, 20}, PlotPoints -> 100, MaxRecursion -> 1],for more complex objects, we cannot resize them just by f^2 $\endgroup$
    – kittygirl
    Mar 8, 2018 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.