Plotting with matplotlib in Python
Main.PythonPlots History
Hide minor edits - Show changes to markup
(:html:)
<div id="disqus_thread"></div> <script type="text/javascript"> /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname /* * * DON'T EDIT BELOW THIS LINE * * */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> <a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
(:htmlend:)
import numpy as np x = np.linspace(0,6,100) y = np.sin(x) z = np.cos(x) import matplotlib.pyplot as plt plt.plot(x,y,'r--',linewidth=3) plt.plot(x,z,'k:',linewidth=2) plt.legend(['y','z']) plt.xlabel('x') plt.ylabel('values') plt.xlim([0, 3]) plt.ylim([-1.5, 1.5]) plt.savefig('myFigure.png') plt.savefig('myFigure.eps') plt.show()
(:source lang=python:) import numpy as np x = np.linspace(0,6,100) y = np.sin(x) z = np.cos(x)
import matplotlib.pyplot as plt plt.plot(x,y,'r--',linewidth=3) plt.plot(x,z,'k:',linewidth=2) plt.legend(['y','z']) plt.xlabel('x') plt.ylabel('values') plt.xlim([0, 3]) plt.ylim([-1.5, 1.5]) plt.savefig('myFigure.png') plt.savefig('myFigure.eps') plt.show() (:sourceend:)
import numpy as np x = np.linspace(0,6,100) y = np.sin(x) z = np.cos(x) %matplotlib inline import matplotlib.pyplot as plt plt.plot(x,y,'r--',linewidth=3) plt.plot(x,z,'k:',linewidth=2) plt.legend(['y','z']) plt.xlabel('x') plt.ylabel('values') plt.xlim([0, 3]) plt.ylim([-1.5, 1.5]) plt.savefig('myFigure.png') plt.savefig('myFigure.eps')
(:source lang=python:) import numpy as np x = np.linspace(0,6,100) y = np.sin(x) z = np.cos(x)
%matplotlib inline import matplotlib.pyplot as plt plt.plot(x,y,'r--',linewidth=3) plt.plot(x,z,'k:',linewidth=2) plt.legend(['y','z']) plt.xlabel('x') plt.ylabel('values') plt.xlim([0, 3]) plt.ylim([-1.5, 1.5]) plt.savefig('myFigure.png') plt.savefig('myFigure.eps') (:sourceend:)
Source Code
import numpy as np x = np.linspace(0,6,100) y = np.sin(x) z = np.cos(x) import matplotlib.pyplot as plt plt.plot(x,y,'r--',linewidth=3) plt.plot(x,z,'k:',linewidth=2) plt.legend(['y','z']) plt.xlabel('x') plt.ylabel('values') plt.xlim([0, 3]) plt.ylim([-1.5, 1.5]) plt.savefig('myFigure.png') plt.savefig('myFigure.eps') plt.show()
If using the iPython notebook, exclude the command plt.show() and include %matplotlib inline before loading matplotlib.pyplot as shown below.
import numpy as np x = np.linspace(0,6,100) y = np.sin(x) z = np.cos(x) %matplotlib inline import matplotlib.pyplot as plt plt.plot(x,y,'r--',linewidth=3) plt.plot(x,z,'k:',linewidth=2) plt.legend(['y','z']) plt.xlabel('x') plt.ylabel('values') plt.xlim([0, 3]) plt.ylim([-1.5, 1.5]) plt.savefig('myFigure.png') plt.savefig('myFigure.eps')
Additional Tutorials
<iframe width="560" height="315" src="https://www.youtube.com/embed/abL-fDq4p_o" frameborder="0" allowfullscreen></iframe>
<iframe width="560" height="315" src="https://www.youtube.com/embed/xRzuzT2Kmsw" frameborder="0" allowfullscreen></iframe>
(:title Plotting with matplotlib in Python:) (:keywords big data, data analysis, Python programming, matplotlib, scatter plot, graph, university course:) (:description Plot data with Python and export for a presentation or report:)
Effective plots are important to synthesize the information into relevant and persuasive information. The following tutorial details some of the common data plotting functions within Python.
(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/abL-fDq4p_o" frameborder="0" allowfullscreen></iframe> (:htmlend:)
This tutorial can also be completed with scripting programming languages like Excel and MATLAB. Click on the appropriate link for additional information and source code.
(:html:)
<div id="disqus_thread"></div> <script type="text/javascript"> /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname /* * * DON'T EDIT BELOW THIS LINE * * */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> <a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
(:htmlend:)