Python lines linking dots in a updating plot with matplotlib












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.










share|improve this question




















  • 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 4:12








  • 1





    Is this example (matplotlib.org/gallery/animation/…) relevant to you ?

    – Patol75
    Nov 15 '18 at 4:17











  • Yes, Im adding points one by one, the function its 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 3: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 4:00
















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.










share|improve this question




















  • 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 4:12








  • 1





    Is this example (matplotlib.org/gallery/animation/…) relevant to you ?

    – Patol75
    Nov 15 '18 at 4:17











  • Yes, Im adding points one by one, the function its 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 3: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 4:00














1












1








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.










share|improve this question
















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.







python matplotlib plot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 4:04









DavidG

11.2k103242




11.2k103242










asked Nov 15 '18 at 4:02









JoaquinJoaquin

28110




28110








  • 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 4:12








  • 1





    Is this example (matplotlib.org/gallery/animation/…) relevant to you ?

    – Patol75
    Nov 15 '18 at 4:17











  • Yes, Im adding points one by one, the function its 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 3: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 4:00














  • 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 4:12








  • 1





    Is this example (matplotlib.org/gallery/animation/…) relevant to you ?

    – Patol75
    Nov 15 '18 at 4:17











  • Yes, Im adding points one by one, the function its 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 3: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 4:00








1




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 4:12







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 4:12






1




1





Is this example (matplotlib.org/gallery/animation/…) relevant to you ?

– Patol75
Nov 15 '18 at 4:17





Is this example (matplotlib.org/gallery/animation/…) relevant to you ?

– Patol75
Nov 15 '18 at 4:17













Yes, Im adding points one by one, the function its 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 3:57





Yes, Im adding points one by one, the function its 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 3: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 4:00





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 4:00












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312261%2fpython-lines-linking-dots-in-a-updating-plot-with-matplotlib%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312261%2fpython-lines-linking-dots-in-a-updating-plot-with-matplotlib%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine