1
$\begingroup$

My problem is very simple. I'm trying to create an animation with a function's plot. Here is my code:

Azul := RGBColor["#19A3CD"]
f[x_] := Piecewise[{{(x - 3)^3 + 2 (x - 3)^2 + 3, 0 <= x <= t}, {0, 
    x > t}}]
funcao := 
 Plot[f[x], {x, -0.6, 5}, PlotStyle -> Thickness[0.006], 
  Background -> Black]

PlotSet := {PlotStyle -> {Thickness[0.006], Azul}, 
  AxesStyle -> Directive[White, Thickness[0.005]], 
  PlotRange -> {-0.2, 6}, 
  Ticks -> {{{1, 1, 0.04}, {2, 2, 0.04}, {3, 3, 0.04}, {4, 4, 
      0.04}, {5, 5, 0.05}}, {{1, 1, 0.04}, {2, 2, 0.04}, {3, 3, 
      0.04}, {4, 4, 0.04}, {5, 5, 0.04}, {6, 6, 0.04}}}, 
  TicksStyle -> 
   Directive[White, Bold, FontSize -> 48, FontColor -> White, 
    FontFamily -> "Montserrat"], ImageSize -> {1920, 1080}}
A := Show[funcao, Axes -> True, Evaluate@PlotSet]
GraficoAnimado = Table[A, {t, 0, 4.5, 0.1}]

And, at the beggining, the first plots looks ok, like this one: enter image description here

But the nexts plots completely lose the pattern, like this one: enter image description here

And, after some time, the plots continue ok.

enter image description here

Why on the earth is this happening?

$\endgroup$
2
  • $\begingroup$ Table localizes the variable t. Therefore, make A[t] a function of t. And also funcao[t] and f[x,t] $\endgroup$ Nov 3 '20 at 21:13
  • $\begingroup$ @DanielHuber I did it, and the problem is still there. Could you try to run it in your Mathematica, and see what happens? Because I really think it is a bug. $\endgroup$ Nov 3 '20 at 22:13
3
$\begingroup$

Your code is over complicated and buggy. Here is a simple way of writing what you want.

Azul = RGBColor["#19A3CD"];
ticks = {#, #, .04} & /@ Range[6];
f[x_] := (x - 3)^3 + 2 (x - 3)^2 + 3
plot[t_] :=
  Plot[f[x], {x, -0.6, t},
    PlotStyle -> Directive[Azul, Thickness[0.006]],
    Background -> Black,
    AxesStyle -> Directive[White, Thickness[0.005]],
    PlotRange -> {{-0.5, 5.1}, {-0.5, 6.2}},
    Ticks -> {Most @ ticks, ticks},
    TicksStyle -> Directive[White, Bold, 48, FontFamily -> "Montserrat"],
    ImageSize -> {1920, 1080}]
GraficoAnimado = Table[plot[t], {t, 0.5, 4.5, 0.1}];

The table of plots is too big to show in full, but here is what the first, 20th, and last plots look like.

Magnify[Column[GraficoAnimado[[{1, 20, -1}]], Spacings -> 5], .33]

plots

$\endgroup$
1
  • $\begingroup$ It worked. Thank you! $\endgroup$ Nov 3 '20 at 23:34
3
$\begingroup$

The following gives you a Manipulate within which you can just run an animation.

Manipulate[
 Plot[
  Piecewise[{{(x - 3)^3 + 2 (x - 3)^2 + 3, 0 <= x <= t}, {0, 
     x > t}}],
  {x, -0.6, 5},
  Axes -> True,
  PlotStyle -> {Thickness[0.006], RGBColor["#19A3CD"]},
  AxesStyle -> Directive[White, Thickness[0.005]],
  PlotRange -> {-0.2, 12},
  TicksStyle -> 
   Directive[White, Bold, FontSize -> 10, FontColor -> White, 
    FontFamily -> "Montserrat"], 
  ImageSize -> {1920/4, 1080/4}, Background -> Black
  ],
 {t, 0, 4.5, 0.1}
 ]

enter image description here

OR... Simply change the Head of the above to Table:

Table[
 Plot[
  Piecewise[{{(x - 3)^3 + 2 (x - 3)^2 + 3, 0 <= x <= t}, {0, 
     x > t}}],
  {x, -0.6, 5},
  Axes -> True,
  PlotStyle -> {Thickness[0.006], RGBColor["#19A3CD"]},
  AxesStyle -> Directive[White, Thickness[0.005]],
  PlotRange -> {-0.2, 12},
  TicksStyle -> 
   Directive[White, Bold, FontSize -> 10, FontColor -> White, 
    FontFamily -> "Montserrat"], 
  ImageSize -> {1920/4, 1080/4}, Background -> Black
  ],
 {t, 0, 4.5, 0.1}
 ]

Which will give you all of the individual Plots.

$\endgroup$
1
  • $\begingroup$ sorry, that's not what I need. I know that I can do an animation with manipulation, but for now, I need the table with all the plots $\endgroup$ Nov 3 '20 at 20:43
0
$\begingroup$

I am running MMA 12.0. The following code, using functions instead of expressions gives (I made the image size and font smaller because I do not have a XXL monitor).

Azul := RGBColor["#19A3CD"]
f[x_, t_] := 
 Piecewise[{{(x - 3)^3 + 2 (x - 3)^2 + 3, 0 <= x <= t}, {0, x > t}}]
funcao[t_] := 
 Plot[f[x, t], {x, -0.6, 5}, PlotStyle -> Thickness[0.006], 
  Background -> Black]

PlotSet := {PlotStyle -> {Thickness[0.006], Azul}, 
  AxesStyle -> Directive[White, Thickness[0.005]], 
  PlotRange -> {-0.2, 6}, 
  Ticks -> {{{1, 1, 0.04}, {2, 2, 0.04}, {3, 3, 0.04}, {4, 4, 
      0.04}, {5, 5, 0.05}}, {{1, 1, 0.04}, {2, 2, 0.04}, {3, 3, 
      0.04}, {4, 4, 0.04}, {5, 5, 0.04}, {6, 6, 0.04}}}, 
  TicksStyle -> 
   Directive[White, Bold, FontSize -> 4.8, FontColor -> White, 
    FontFamily -> "Montserrat"], ImageSize -> {192, 108}}
A[t_] := Show[funcao[t], Axes -> True, Evaluate@PlotSet]
GraficoAnimado = Table[A[t], {t, 0, 4.5, 0.1}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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