How do I animate circles and line with matplotlib?











up vote
0
down vote

favorite












I can animate six circles, and I can animate a line. When I try to animate both, I cannot figure out what init() and animate() should return. For six circles I "return tuple(pins)" and for the line I "return line,". Each pin is a "class 'matplotlib.patches.Circle'" and the line is "class 'matplotlib.lines.Line2D'."



When I try to animate both the circles and the line, I have tried many different return statements without success. Here are the some of the results:



return line, tuple(pins) GIVES 'tuple' object has no attribute 'set_animated'



return tuple(pins) + (line) GIVES can only concatenate tuple (not "Line2D") to tuple



return tuple(pins) + tuple(line) GIVES 'Line2D' object is not iterable










share|improve this question
























  • provide a Minimal, Complete, and Verifiable example
    – eyllanesc
    Nov 14 at 6:01










  • You say what pin is, but not what pins is.
    – ImportanceOfBeingErnest
    Nov 14 at 9:49















up vote
0
down vote

favorite












I can animate six circles, and I can animate a line. When I try to animate both, I cannot figure out what init() and animate() should return. For six circles I "return tuple(pins)" and for the line I "return line,". Each pin is a "class 'matplotlib.patches.Circle'" and the line is "class 'matplotlib.lines.Line2D'."



When I try to animate both the circles and the line, I have tried many different return statements without success. Here are the some of the results:



return line, tuple(pins) GIVES 'tuple' object has no attribute 'set_animated'



return tuple(pins) + (line) GIVES can only concatenate tuple (not "Line2D") to tuple



return tuple(pins) + tuple(line) GIVES 'Line2D' object is not iterable










share|improve this question
























  • provide a Minimal, Complete, and Verifiable example
    – eyllanesc
    Nov 14 at 6:01










  • You say what pin is, but not what pins is.
    – ImportanceOfBeingErnest
    Nov 14 at 9:49













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I can animate six circles, and I can animate a line. When I try to animate both, I cannot figure out what init() and animate() should return. For six circles I "return tuple(pins)" and for the line I "return line,". Each pin is a "class 'matplotlib.patches.Circle'" and the line is "class 'matplotlib.lines.Line2D'."



When I try to animate both the circles and the line, I have tried many different return statements without success. Here are the some of the results:



return line, tuple(pins) GIVES 'tuple' object has no attribute 'set_animated'



return tuple(pins) + (line) GIVES can only concatenate tuple (not "Line2D") to tuple



return tuple(pins) + tuple(line) GIVES 'Line2D' object is not iterable










share|improve this question















I can animate six circles, and I can animate a line. When I try to animate both, I cannot figure out what init() and animate() should return. For six circles I "return tuple(pins)" and for the line I "return line,". Each pin is a "class 'matplotlib.patches.Circle'" and the line is "class 'matplotlib.lines.Line2D'."



When I try to animate both the circles and the line, I have tried many different return statements without success. Here are the some of the results:



return line, tuple(pins) GIVES 'tuple' object has no attribute 'set_animated'



return tuple(pins) + (line) GIVES can only concatenate tuple (not "Line2D") to tuple



return tuple(pins) + tuple(line) GIVES 'Line2D' object is not iterable







animation matplotlib






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 5:58

























asked Nov 14 at 5:50









user3286261

36127




36127












  • provide a Minimal, Complete, and Verifiable example
    – eyllanesc
    Nov 14 at 6:01










  • You say what pin is, but not what pins is.
    – ImportanceOfBeingErnest
    Nov 14 at 9:49


















  • provide a Minimal, Complete, and Verifiable example
    – eyllanesc
    Nov 14 at 6:01










  • You say what pin is, but not what pins is.
    – ImportanceOfBeingErnest
    Nov 14 at 9:49
















provide a Minimal, Complete, and Verifiable example
– eyllanesc
Nov 14 at 6:01




provide a Minimal, Complete, and Verifiable example
– eyllanesc
Nov 14 at 6:01












You say what pin is, but not what pins is.
– ImportanceOfBeingErnest
Nov 14 at 9:49




You say what pin is, but not what pins is.
– ImportanceOfBeingErnest
Nov 14 at 9:49












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Note that you only need to return something from the animating function if you use blitting.



From the documentation:




If blit == True, func must return an iterable of all artists that were modified or created. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. The return value is unused if blit == False and may be omitted in that case.




So just ommiting the return altogether may be the easiest option.



If you need/want to use blitting, you need to return an iterable of artists. This can e.g. be a tuple or a list. Unfortunately, it's not clear what pins is from the question.



Supposing pins is a list,



return pins + [line]


or if you want to make it a list,



return list(pins) + [line]


Supposing pins is a tuple,



return pins + (line,)


or if you want to make it a tuple,



return tuple(pins) + (line,)





share|improve this answer





















  • Removing blit from anim worked. Since pins is a list so did adding a line list. Making a tuple, for reasons I no longer remember, was the cause of my problem because I was not handling the tuple correctly. Thank you very much.
    – user3286261
    Nov 14 at 17:33











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',
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%2f53293911%2fhow-do-i-animate-circles-and-line-with-matplotlib%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Note that you only need to return something from the animating function if you use blitting.



From the documentation:




If blit == True, func must return an iterable of all artists that were modified or created. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. The return value is unused if blit == False and may be omitted in that case.




So just ommiting the return altogether may be the easiest option.



If you need/want to use blitting, you need to return an iterable of artists. This can e.g. be a tuple or a list. Unfortunately, it's not clear what pins is from the question.



Supposing pins is a list,



return pins + [line]


or if you want to make it a list,



return list(pins) + [line]


Supposing pins is a tuple,



return pins + (line,)


or if you want to make it a tuple,



return tuple(pins) + (line,)





share|improve this answer





















  • Removing blit from anim worked. Since pins is a list so did adding a line list. Making a tuple, for reasons I no longer remember, was the cause of my problem because I was not handling the tuple correctly. Thank you very much.
    – user3286261
    Nov 14 at 17:33















up vote
1
down vote



accepted










Note that you only need to return something from the animating function if you use blitting.



From the documentation:




If blit == True, func must return an iterable of all artists that were modified or created. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. The return value is unused if blit == False and may be omitted in that case.




So just ommiting the return altogether may be the easiest option.



If you need/want to use blitting, you need to return an iterable of artists. This can e.g. be a tuple or a list. Unfortunately, it's not clear what pins is from the question.



Supposing pins is a list,



return pins + [line]


or if you want to make it a list,



return list(pins) + [line]


Supposing pins is a tuple,



return pins + (line,)


or if you want to make it a tuple,



return tuple(pins) + (line,)





share|improve this answer





















  • Removing blit from anim worked. Since pins is a list so did adding a line list. Making a tuple, for reasons I no longer remember, was the cause of my problem because I was not handling the tuple correctly. Thank you very much.
    – user3286261
    Nov 14 at 17:33













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Note that you only need to return something from the animating function if you use blitting.



From the documentation:




If blit == True, func must return an iterable of all artists that were modified or created. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. The return value is unused if blit == False and may be omitted in that case.




So just ommiting the return altogether may be the easiest option.



If you need/want to use blitting, you need to return an iterable of artists. This can e.g. be a tuple or a list. Unfortunately, it's not clear what pins is from the question.



Supposing pins is a list,



return pins + [line]


or if you want to make it a list,



return list(pins) + [line]


Supposing pins is a tuple,



return pins + (line,)


or if you want to make it a tuple,



return tuple(pins) + (line,)





share|improve this answer












Note that you only need to return something from the animating function if you use blitting.



From the documentation:




If blit == True, func must return an iterable of all artists that were modified or created. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. The return value is unused if blit == False and may be omitted in that case.




So just ommiting the return altogether may be the easiest option.



If you need/want to use blitting, you need to return an iterable of artists. This can e.g. be a tuple or a list. Unfortunately, it's not clear what pins is from the question.



Supposing pins is a list,



return pins + [line]


or if you want to make it a list,



return list(pins) + [line]


Supposing pins is a tuple,



return pins + (line,)


or if you want to make it a tuple,



return tuple(pins) + (line,)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 at 9:58









ImportanceOfBeingErnest

121k10124196




121k10124196












  • Removing blit from anim worked. Since pins is a list so did adding a line list. Making a tuple, for reasons I no longer remember, was the cause of my problem because I was not handling the tuple correctly. Thank you very much.
    – user3286261
    Nov 14 at 17:33


















  • Removing blit from anim worked. Since pins is a list so did adding a line list. Making a tuple, for reasons I no longer remember, was the cause of my problem because I was not handling the tuple correctly. Thank you very much.
    – user3286261
    Nov 14 at 17:33
















Removing blit from anim worked. Since pins is a list so did adding a line list. Making a tuple, for reasons I no longer remember, was the cause of my problem because I was not handling the tuple correctly. Thank you very much.
– user3286261
Nov 14 at 17:33




Removing blit from anim worked. Since pins is a list so did adding a line list. Making a tuple, for reasons I no longer remember, was the cause of my problem because I was not handling the tuple correctly. Thank you very much.
– user3286261
Nov 14 at 17:33


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53293911%2fhow-do-i-animate-circles-and-line-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

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?