Need help with prompt for using matplotlib with davinvi-codex

I saw a post on stack overflow and wanted to see if the davinci-codex model was smart enough to handle it. I feel like I’m close to making this work, but can’t quite put my finger on it.

What I have so far link here:

My prompt:

#: Explanation of what the code does
This code creates a loop that draws points on a 
plot and then shows the plot to the user.

#: Python 3 
import matplotlib.pyplot as plt
for i in range(1, 10):
    plt.plot(i, i**2, '-o')

plt.show()

#: Explanation of what the code does
This code does the same as the above example, except 
that it also draws a line from the pervious point to the current point.

#: Python 3

My output:

import matplotlib.pyplot as plt
for i in range(1, 10):
    plt.plot(i, i**2, '-o')
    plt.plot([i-1, i], [i**2-1, i**2], '-o')

plt.show()

The initial code creates this image:

Figure_1

As you can see the output is very close but not quite right.

Figure_2

If it had entered plt.plot([i-1, i], [(i-1)**2, i**2], '-o') then we would have had the correct answer of

Figure_3

Any idea what I could be tweaking parameter wise to better help the system guess, or is there a more clear way I could have formatted my prompt to yield better results?

Thanks.

2 Likes

Could it be that correcting the typo “pervious” to previous would help?

That is embarrassing haha. But no, it seems to give the same result without the typo.