Ask Your Question

Revision history [back]

That is quite impressive for half a Sunday! I'd suggest to forget about the legend command and use text. Add the two lines

  • text(r'$y^2=x^3+3.8x^2-0.8x{0:+}$'.format(float(k)),(3,-18),fontsize='large', fontweight='bold', color='red')
  • text(r'$y=x^3+3.8x^2-0.8x{0:+}$'.format(float(k)),(-3,18),fontsize='large', fontweight='bold', color='blue')

right after the plot of the cubic, ie as separate Graphics objects. I've tried this, the coordinates (3,-18) and (-3,18) put it in a nice spot within your animation. And with the text color, you don't need a little colored line telling the viewer what the label refers to. BUT did you notice the 0:+ instead of your curly braces formatting { } ?? The 0:+ needs curly braces around it as well, I swear I typed them, can even see them in Preview, but they get eaten when it's displayed. Likewise, instead of bullet points, you want plus signs to add the text elements.

Inserting 0:+ displays k with a + if positive, - if negative (in your version, you get a plus AND a minus sign if k<0). For more details than you ever want to know, see help('FORMATTING') There is still a weird instability for k=0, I wonder if that's coming from the math - maybe choose a range for k which does not hit zero exactly?