python matplotlib
play

Python Matplotlib Han-Wei Shen The Ohio State University - PowerPoint PPT Presentation

Python Matplotlib Han-Wei Shen The Ohio State University First Thing First Install the Matplotlib package if you have not had it


  1. Python ¡Matplotlib ¡ Han-­‑Wei ¡Shen ¡ ¡ The ¡Ohio ¡State ¡University ¡ ¡

  2. First ¡Thing ¡First ¡ ¡ • Install ¡the ¡Matplotlib ¡package ¡if ¡you ¡have ¡not ¡ had ¡it ¡already ¡ – Typically ¡Matplotlib ¡is ¡installed ¡together ¡with ¡ numpy ¡and ¡scipy ¡ ¡ – Example: ¡Use ¡Anaconda ¡Python ¡ ¡ ¡ ¡ ¡ ¡(hHps://store.conKnuum.io/cshop/anaconda/) ¡ ¡

  3. A ¡Typical ¡Matplotlib ¡Program ¡ ¡ Start ¡your ¡Python ¡program ¡by ¡including ¡matplotlib ¡and ¡numpy ¡packages ¡ • (numpy ¡arrays ¡are ¡typically ¡used ¡as ¡the ¡input ¡to ¡matplotlib ¡) ¡ import ¡matplotlib.pyplot ¡as ¡plt ¡ ¡ import ¡numpy ¡as ¡np ¡ ¡ ¡ Create ¡a ¡figure ¡as ¡the ¡drawing ¡area. ¡You ¡can ¡have ¡mulKple ¡figures ¡in ¡a ¡ • program ¡ plt.figure() ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡default ¡argument ¡is ¡empty, ¡but ¡you ¡use ¡a ¡numbr, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡a ¡string, ¡etc. ¡as ¡the ¡input ¡ ¡ Plot ¡the ¡data ¡using ¡a ¡plot ¡type ¡of ¡your ¡choice ¡(line ¡graph, ¡bar ¡chart, ¡ • histogram, ¡pie ¡chart, ¡etc) ¡ plt.plot(np.array[4,6,3,10,7]) ¡ ¡// ¡use ¡line ¡graph ¡here ¡ ¡ Add ¡Ktle, ¡labels, ¡Kckmarks, ¡legends, ¡etc. ¡ ¡ • plt.xlabel(‘input ¡parameter ¡(seconds)’ ¡ ¡// ¡label ¡the ¡x ¡axis ¡ ¡ ¡ Display ¡the ¡plot ¡either ¡to ¡an ¡interacKve ¡window ¡or ¡a ¡file ¡ • plt.show() ¡// ¡draw ¡to ¡a ¡window ¡ ¡ ¡ plt.savefig(‘myplot.png’) ¡// ¡save ¡to ¡a ¡file ¡ ¡

  4. A ¡Typical ¡Matplotlib ¡Program ¡ ¡ Start ¡your ¡Python ¡program ¡by ¡including ¡matplotlib ¡and ¡numpy ¡packages ¡ • (numpy ¡arrays ¡are ¡typically ¡used ¡as ¡the ¡input ¡to ¡matplotlib ¡) ¡ import ¡matplotlib.pyplot ¡as ¡plt ¡ ¡ import ¡numpy ¡as ¡np ¡ ¡ ¡ Create ¡a ¡figure ¡as ¡the ¡drawing ¡area. ¡You ¡can ¡have ¡mulKple ¡figures ¡in ¡a ¡ • program ¡ plt.figure() ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡default ¡argument ¡is ¡empty, ¡but ¡you ¡use ¡a ¡numbr, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡a ¡string, ¡etc. ¡as ¡the ¡input ¡ ¡ Plot ¡the ¡data ¡using ¡a ¡plot ¡type ¡of ¡your ¡choice ¡(line ¡graph, ¡bar ¡chart, ¡ • histogram, ¡pie ¡chart, ¡etc) ¡ plt.plot(np.array[4,6,3,10,7]) ¡ ¡// ¡use ¡line ¡graph ¡here ¡ ¡ Add ¡Ktle, ¡labels, ¡Kckmarks, ¡legends, ¡etc. ¡ ¡ • plt.xlabel(‘input ¡parameter ¡(seconds)’ ¡ ¡// ¡label ¡the ¡x ¡axis ¡ ¡ ¡ Display ¡the ¡plot ¡either ¡to ¡an ¡interacKve ¡window ¡or ¡a ¡file ¡ • plt.show() ¡// ¡draw ¡to ¡a ¡window ¡ ¡ ¡ plt.savefig(‘myplot.png’) ¡// ¡save ¡to ¡a ¡file ¡ ¡

  5. A ¡Typical ¡Matplotlib ¡Program ¡ ¡ Start ¡your ¡Python ¡program ¡by ¡including ¡matplotlib ¡and ¡numpy ¡packages ¡ • (numpy ¡arrays ¡are ¡typically ¡used ¡as ¡the ¡input ¡to ¡matplotlib ¡) ¡ import ¡matplotlib.pyplot ¡as ¡plt ¡ ¡ import ¡numpy ¡as ¡np ¡ ¡ ¡ Create ¡a ¡figure ¡as ¡the ¡drawing ¡area. ¡You ¡can ¡have ¡mulKple ¡figures ¡in ¡a ¡ • program ¡ plt.figure() ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡default ¡argument ¡is ¡empty, ¡but ¡you ¡use ¡a ¡number, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡a ¡string, ¡etc. ¡as ¡the ¡input ¡ ¡ Plot ¡the ¡data ¡using ¡a ¡plot ¡type ¡of ¡your ¡choice ¡(line ¡graph, ¡bar ¡chart, ¡ • histogram, ¡pie ¡chart, ¡etc) ¡ plt.plot(np.array[4,6,3,10,7]) ¡ ¡// ¡use ¡line ¡graph ¡here ¡ ¡ Add ¡Ktle, ¡labels, ¡Kckmarks, ¡legends, ¡etc. ¡ ¡ • plt.xlabel(‘input ¡parameter ¡(seconds)’ ¡ ¡// ¡label ¡the ¡x ¡axis ¡ ¡ ¡ Display ¡the ¡plot ¡either ¡to ¡an ¡interacKve ¡window ¡or ¡a ¡file ¡ • plt.show() ¡// ¡draw ¡to ¡a ¡window ¡ ¡ ¡ plt.savefig(‘myplot.png’) ¡// ¡save ¡to ¡a ¡file ¡ ¡

  6. A ¡Typical ¡Matplotlib ¡Program ¡ ¡ Start ¡your ¡Python ¡program ¡by ¡including ¡matplotlib ¡and ¡numpy ¡packages ¡ • (numpy ¡arrays ¡are ¡typically ¡used ¡as ¡the ¡input ¡to ¡matplotlib ¡) ¡ import ¡matplotlib.pyplot ¡as ¡plt ¡ ¡ import ¡numpy ¡as ¡np ¡ ¡ ¡ Create ¡a ¡figure ¡as ¡the ¡drawing ¡area. ¡You ¡can ¡have ¡mulKple ¡figures ¡in ¡a ¡ • program ¡ plt.figure() ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡default ¡argument ¡is ¡empty, ¡but ¡you ¡use ¡a ¡numbr, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡a ¡string, ¡etc. ¡as ¡the ¡input ¡ ¡ Plot ¡the ¡data ¡using ¡a ¡plot ¡type ¡of ¡your ¡choice ¡(line ¡graph, ¡bar ¡chart, ¡ • histogram, ¡pie ¡chart, ¡etc) ¡ plt.plot(np.array[4,6,3,10,7]) ¡ ¡// ¡use ¡line ¡graph ¡here ¡ ¡ Add ¡Ktle, ¡labels, ¡Kckmarks, ¡legends, ¡etc. ¡ ¡ • plt.xlabel(‘input ¡parameter ¡(seconds)’ ¡ ¡// ¡label ¡the ¡x ¡axis ¡ ¡ ¡ Display ¡the ¡plot ¡either ¡to ¡an ¡interacKve ¡window ¡or ¡a ¡file ¡ • plt.show() ¡// ¡draw ¡to ¡a ¡window ¡ ¡ ¡ plt.savefig(‘myplot.png’) ¡// ¡save ¡to ¡a ¡file ¡ ¡

  7. A ¡Typical ¡Matplotlib ¡Program ¡ ¡ Start ¡your ¡Python ¡program ¡by ¡including ¡matplotlib ¡and ¡numpy ¡packages ¡ • (numpy ¡arrays ¡are ¡typically ¡used ¡as ¡the ¡input ¡to ¡matplotlib ¡) ¡ import ¡matplotlib.pyplot ¡as ¡plt ¡ ¡ import ¡numpy ¡as ¡np ¡ ¡ ¡ Create ¡a ¡figure ¡as ¡the ¡drawing ¡area. ¡You ¡can ¡have ¡mulKple ¡figures ¡in ¡a ¡ • program ¡ plt.figure() ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡default ¡argument ¡is ¡empty, ¡but ¡you ¡use ¡a ¡numbr, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡a ¡string, ¡etc. ¡as ¡the ¡input ¡ ¡ Plot ¡the ¡data ¡using ¡a ¡plot ¡type ¡of ¡your ¡choice ¡(line ¡graph, ¡bar ¡chart, ¡ • histogram, ¡pie ¡chart, ¡etc) ¡ plt.plot(np.array[4,6,3,10,7]) ¡ ¡// ¡use ¡line ¡graph ¡here ¡ ¡ Add ¡Ktle, ¡labels, ¡Kckmarks, ¡legends, ¡etc. ¡ ¡ • plt.xlabel(‘input ¡parameter ¡(seconds)’ ¡ ¡// ¡label ¡the ¡x ¡axis ¡ ¡ ¡ Display ¡the ¡plot ¡either ¡to ¡an ¡interacKve ¡window ¡or ¡a ¡file ¡ • plt.show() ¡// ¡draw ¡to ¡a ¡window ¡ ¡ ¡ plt.savefig(‘myplot.png’) ¡// ¡save ¡to ¡a ¡file ¡ ¡

  8. A ¡Typical ¡Matplotlib ¡Program ¡ ¡ Start ¡your ¡Python ¡program ¡by ¡including ¡matplotlib ¡and ¡numpy ¡packages ¡ • (numpy ¡arrays ¡are ¡typically ¡used ¡as ¡the ¡input ¡to ¡matplotlib ¡) ¡ import ¡matplotlib.pyplot ¡as ¡plt ¡ ¡ import ¡numpy ¡as ¡np ¡ ¡ ¡ Create ¡a ¡figure ¡as ¡the ¡drawing ¡area. ¡You ¡can ¡have ¡mulKple ¡figures ¡in ¡a ¡ • program ¡ plt.figure() ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡default ¡argument ¡is ¡empty, ¡but ¡you ¡use ¡a ¡numbr, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡a ¡string, ¡etc. ¡as ¡the ¡input ¡ ¡ Plot ¡the ¡data ¡using ¡a ¡plot ¡type ¡of ¡your ¡choice ¡(line ¡graph, ¡bar ¡chart, ¡ • histogram, ¡pie ¡chart, ¡etc) ¡ plt.plot(np.array([4,6,3,10,7])) ¡ ¡// ¡use ¡line ¡graph ¡here ¡ ¡ Add ¡Ktle, ¡labels, ¡Kckmarks, ¡legends, ¡etc. ¡ ¡ • plt.xlabel(‘input ¡parameter ¡(seconds)’ ¡) ¡// ¡label ¡the ¡x ¡axis ¡ ¡ ¡ Display ¡the ¡plot ¡either ¡to ¡an ¡interacKve ¡window ¡or ¡a ¡file ¡ • plt.show() ¡// ¡draw ¡to ¡a ¡window ¡ ¡ ¡ plt.savefig(‘myplot.png’) ¡// ¡save ¡to ¡a ¡file ¡ ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend