1

I`m using matplotlib to plot a reward vs episode plot in a reinforcement learning application. So basically I update the plot every time the episode ends. Searching here python-How do I plot in real time in a while loop using matplotlib I get to make my plot update every time my episode finished. My code for the plot is:

reward_plot = plt.plot(i,total_reward, '-ro')
plt.title('Reward vs episodes')
plt.xlabel("Episodes", fontsize=12)
plt.ylabel("Reward", fontsize=12)
plt.pause(0.05)

And the plot, actually looks like this:

enter image description here

I just want to make the plot draw a line linking the dots each time the graph is updated. It is possible? I tried with different methods but I didn't have any luck. I'm using Python 3.6.6.

DavidG
  • 24,279
  • 14
  • 89
  • 82
Joaquin
  • 139
  • 1
  • 3
  • 12
  • 1
    So you are adding points one-by-one, and what you would like to see is a plot where there is a line between each adjacent (on the x-axis) points? For that you would have to remove a previous line each time you add a new point and introduce two new. I'd be surprised if that functionality would be implemented in matplotlib – g.a Nov 15 '18 at 04:12
  • 1
    Is this example (https://matplotlib.org/gallery/animation/animate_decay.html#sphx-glr-gallery-animation-animate-decay-py) relevant to you ? – Patol75 Nov 15 '18 at 04:17
  • Yes, I`m adding points one by one, the function it`s inside a for loop; so what I want is when I add the second point, matplotlib draw a line between the first and second point; then when the third episode finishes, a line between second and third point; and so on. So it`s not possible? – Joaquin Nov 16 '18 at 03:57
  • I tried the example you showed to me; it only draws a animated line; I need the points because it`s not a continuous value. Thanks anyway! – Joaquin Nov 16 '18 at 04:00

0 Answers0