Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

BRG blog (https://block.arch.ethz.

ch/blog/)
The weblog of the Block Research Group

(https://block.arch.ethz.ch/blog/feed/)

(http://vimeo.com/blockresearchgroup)

Dynamic plotting with matplotlib Recent Posts


(http://www.flickr.com/photos/blockresearchgroup)

(https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-
(http://block.arch.ethz.ch)
Rhino 5 and new IronPython installations
matplotlib/) (https://block.arch.ethz.ch/blog/2016/12/rhino-5-
Posted on August 4th, 2016,
by tom
in Code (https://block.arch.ethz.ch/blog/category/code/) and-new-ironpython-installations/)
Creating functions dynamically

(https://plus.google.com/share?url=https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with- (https://block.arch.ethz.ch/blog/2016/11/creating-
matplotlib/)

(https://www.facebook.com/sharer.php? functions-dynamically/)
u=https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/)
Bitwise operators in Python
(https://twitter.com/intent/tweet?url=https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with- (https://block.arch.ethz.ch/blog/2016/10/bitwise-
matplotlib/)

(http://www.linkedin.com/shareArticle? operators-in-python/)
mini=true&url=https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/&title=Dynamic Customizing Rhino toolbar button icons
plotting with matplotlib&summary=&source=)

(mailto:?subject=Dynamic plotting with (https://block.arch.ethz.ch/blog/2016/10/customizing-
matplotlib&body=I think you may find this interesting: https://block.arch.ethz.ch/blog/2016/08/dynamic-
rhino-toolbar-button-icons/)
plotting-with-matplotlib/)
PyOpenGL GLUT error
(https://block.arch.ethz.ch/blog/2016/10/pyopengl-
Matplotlib is a great tool to visualise two-dimensional geometric data (and 3D data to some extent). You glut-error/)
can also use it to dynamically visualise the convergence of an iterative solver.

Surprisingly, you don’t need any fancy functionality to accomplish this, such as, for example, the
Archives
FuncAnimation object of the animation package.
December 2016
import matplotlib.pyplot as plt (https://block.arch.ethz.ch/blog/2016/12/)
import time November 2016
import random (https://block.arch.ethz.ch/blog/2016/11/)
 
ysample = random.sample(xrange(-50, 50), 100) October 2016
  (https://block.arch.ethz.ch/blog/2016/10/)
xdata = [] August 2016
ydata = []
(https://block.arch.ethz.ch/blog/2016/08/)
 
plt.show() July 2016 (https://block.arch.ethz.ch/blog/2016/07/)
  June 2016 (https://block.arch.ethz.ch/blog/2016/06/)
axes = plt.gca() February 2016
axes.set_xlim(0, 100)
(https://block.arch.ethz.ch/blog/2016/02/)
axes.set_ylim(-50, +50)
line, = axes.plot(xdata, ydata, 'r-') January 2016
  (https://block.arch.ethz.ch/blog/2016/01/)
for i in range(100): October 2015
xdata.append(i)
ydata.append(ysample[i]) (https://block.arch.ethz.ch/blog/2015/10/)
line.set_xdata(xdata) April 2015 (https://block.arch.ethz.ch/blog/2015/04/)
line.set_ydata(ydata) March 2015
plt.draw() (https://block.arch.ethz.ch/blog/2015/03/)
plt.pause(1e-17)
time.sleep(0.1) January 2015
  (https://block.arch.ethz.ch/blog/2015/01/)
# add this if you don't want the window to disappear at the end November 2014
plt.show()
(https://block.arch.ethz.ch/blog/2014/11/)
October 2014
(https://block.arch.ethz.ch/blog/2014/10/)
7 Comments (https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-
matplotlib/#comments) July 2014 (https://block.arch.ethz.ch/blog/2014/07/)
January 2014
« Running Matlab as a Python subprocess (https://block.arch.ethz.ch/blog/2016/08/running-matlab-as-a-
python-subprocess/) (https://block.arch.ethz.ch/blog/2014/01/)
Computational Geometry in Python (https://block.arch.ethz.ch/blog/2016/08/computational-geometry-in- August 2013
python/) » (https://block.arch.ethz.ch/blog/2013/08/)
November 2012
(https://block.arch.ethz.ch/blog/2012/11/)
7 Responses to “Dynamic plotting with matplotlib”
Categories
Code
1. Aditya says: July 10, 2017 at 11:56 am (https://block.arch.ethz.ch/blog/2016/08/dynamic- (https://block.arch.ethz.ch/blog/category/code/)
plotting-with-matplotlib/#comment-26635)
import matplotlib.pyplot as plt Events
(https://block.arch.ethz.ch/blog/category/events/)
plt.ion() Group
(https://block.arch.ethz.ch/blog/category/group/)
for i in range(10):

Projects
plt.scatter(i, i)

(https://block.arch.ethz.ch/blog/category/projects/)
plt.pause(0.5)
Research
this also works but only for scatter() (https://block.arch.ethz.ch/blog/category/research/)
Teaching
Reply (https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/? (https://block.arch.ethz.ch/blog/category/teaching/)
replytocom=26635#respond) Tools
(https://block.arch.ethz.ch/blog/category/tools/)
Uncategorized
XMR (https://www.crypto-facile.fr/) says: December 25, 2017 at 10:06 am (https://block.arch.ethz.ch/blog/category/uncategorized
(https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/#comment-28933)

Thank you Aditya, Blogroll


I was searching for a simple way to refresh of plot, and yours is the simplest that works! eat-a-bug (http://eat-a-bug.blogspot.ch/)

Reply (https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/?
replytocom=28933#respond) Links
æ-lab (http://www.vub.ac.be/ARCH/ae-lab/)
BLOCK Research Group (http://block.arch.ethz.ch/)
2. Jan Wedekind (http://www.wedesoft.de/) says: November 27, 2017 at 4:25 pm
Computer Graphics and Geometry Laboratory
(https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/#comment-28496)
(http://lgg.epfl.ch)
I think it needs to be range instead of xrange.
eQUILIBRIUM
Also: Thanks a lot for posting this example! (http://block.arch.ethz.ch/equilibrium/)
Escobedo Construction
Reply (https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/?
(http://escobedoconstruction.com/)
replytocom=28496#respond)
Form Finding Lab
(http://formfindinglab.princeton.edu/)
Interactive Geometry Lab (http://igl.ethz.ch/)
3. Edward Wong says: January 31, 2018 at 5:47 am
Masonry & Dynamics Research Group
(https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/#comment-29503)
(http://masonrydynamics.com/)
This post was very helpful! Is there a way I can plot 2 lines and animate them? Masonry at MIT (http://web.mit.edu/masonry/)
ODB Engineering (http://odb-engineering.com/)
Reply (https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/?
Structural Design Lab
replytocom=29503#respond)
(http://web.mit.edu/structuraldesign/)

4. Somayyeh says: March 11, 2018 at 4:34 pm


(https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/#comment-30219)

That’s very simple and awesome.

Thank you so much!

Reply (https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/?
replytocom=30219#respond)

5. hyomin says: August 2, 2018 at 6:00 am


(https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/#comment-32309)

That’s what I’m looking for! Thanks a lot

Reply (https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/?
replytocom=32309#respond)

6. Frank says: June 28, 2019 at 6:52 pm (https://block.arch.ethz.ch/blog/2016/08/dynamic-


plotting-with-matplotlib/#comment-36632)

I’m looking for something similar. This is just plotting the plot with all x and y values from a txt file at
once. But it is not updating the values. I want something which draws (3,4) as an example, then
wait for 1 maybe 2 seconds, and then it should plot (3,4) and (2,3) as an example.

Reply (https://block.arch.ethz.ch/blog/2016/08/dynamic-plotting-with-matplotlib/?
replytocom=36632#respond)
Leave a response

Name (required)

Mail (will not be published) (required)

Website

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote
cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Submit Comment

Copyright 2012 © BLOCK Research Group (http://block.arch.ethz.ch), ETH Zurich, Wolfgang-Pauli-Strasse 15, Log in (https://block.arch.ethz.ch/blog/wp-login.php)
8093 Zurich, Switzerland.
BRG blog is proudly powered by
WordPress (http://wordpress.org/), and built using the HTML5 Boilerplate (http://html5boilerplate.com/).

You might also like