5

My code right now plots a function, and animates an image moving along the curve of the function. I want to reduce the size of the image for this animation but I can't figure out how. If I try to change

image = Import["image.png"]

to

image = Import["image.png",ImageSize -> Tiny]

it just makes the image blurry in the animation. This is the animation code:

Animate[Plot[{f[z]}, {z, 0, 50}, 
  PlotRange -> {{0, 50}, {0, 10}}, 
  Epilog -> Inset[image, {x, f[x]}]], {x, 
  0, 30}]

Does anyone know how to fix this?

bbgodfrey
  • 61,439
  • 17
  • 89
  • 156
Frederick
  • 81
  • 2

2 Answers2

5

Use the fourth parameter of Inset:

enter image description here

f = Sin[#] + 5 &;
image = ExampleData[{"TestImage", "Lena"}];

Animate[Plot[{f[z]}, {z, 0, 50}, PlotRange -> {{0, 50}, {0, 10}}, 
  Epilog -> Inset[image, {x, f[x]}, Automatic, 10]], {x, 0, 30}]

enter image description here

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
1

You can also use Show with the option ImageSize:

image = Show[ExampleData[{"TestImage", "Lena"}], ImageSize -> 40];
f = 5 + Sin[#] + Sin[Sqrt[2] #] &;

Animate[Plot[{f[z]}, {z, 0, 50}, PlotRange -> {{0, 50}, {0, 10}}, 
  Epilog -> Inset[image, {x, f[x]}]], {x, 0, 50}]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896