SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
“ use the matplotlib, luke ”
            Wen-Wei Liao
          gattacaliao@gmail.com
A long time ago, in a galaxy far, far away ...
NO!
 John Hunter
“   Matplotlib is a Python 2D plotting package which
    produces publication quality figures in a variety of
    hardcopy formats and interactive environments
    across platforms.
Philosophy
       create simple plots with just a few commands, or
                           just one!




import numpy as np
import matplotlib.pyplot as plt


x = np.random.randn(10000)
plt.hist(x, bins=50)
plt.show()
object-oriented
                  interface



FigureCanvas


 Renderer

   Artist      state-machine
                  interface
   pyplot
pyplot provides a MATLAB-style              pylab lumps pyplot together with
state-machine interface to the underlying   numpy in a single namespace, making
object-oriented interface in matplotlib     that environment even more MATLAB-like

 import numpy as np                          from pylab import *
 import matplotlib.pyplot as plt


 x = np.arange(0, 10, 0.1)                   x = arange(0, 10, 0.1)
 y = np.sin(x)                               y = sin(x)
 plt.plot(x, y)                              plot(x, y)
 plt.show()                                  show()
Explicit is better than implicit.
preferred style using pyplot convenience functions,
but object-orientation for the rest

import numpy as np
import matplotlib.pyplot as plt


x = np.arange(0, 10, 0.1)
y = np.sin(x)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y)
plt.show()
2 types of Artists

•   Primitives: Line2D, Rectangle, Text, etc.

•   Containers: Figure, Axes, Axis, Tick




    http://sfillustration.wordpress.com/2012/02/25/star-wars
Figure Container
(matplotlib.figure.Figure)
Axes Container
(matplotlib.axes.Axes)
XAxis Container
(matplotlib.axis.Axis)
YAxis Container
(matplotlib.axis.Axis)
XTick Container
(matplotlib.axis.Tick)
YTick Container
(matplotlib.axis.Tick)
Customizing your objects

each of the properties is accessed with an old-fashioned
setter or getter
a = o.get_alpha()
o.set_alpha(0.5*a)




set a number of properties at once
o.set(alpha=0.5, zorder=2)
import matplotlib.pyplot as plt


fig = plt.figure()
ax = fig.add_subplot(111)


for label in ax.xaxis.get_ticklabels():
    # label is a Text instance
    label.set_color(‘red’)
    label.set_rotation(45)
    label.set_fontsize(20)
    label.set_fontweight(‘bold’)


for line in ax.yaxis.get_ticklines():
    # line is a Line2D instance
    line.set_color(‘green’)
    line.set_markersize(30)
    line.set_markeredgewidth(5)


plt.show()
import matplotlib.pyplot as plt


fig = plt.figure()
ax = fig.add_subplot(111)


for tick in ax.yaxis.get_major_ticks():
    tick.label1On = False
    tick.label2On = True
    tick.label2.set_color(‘blue’)
    tick.label2.set_fontsize(20)
    tick.label2.set_fontweight(‘bold’)


    tick.gridOn = True
    tick.gridline.set_color(‘red’)
    tick.gridline.set_linewidth(2)
    tick.gridline.set_linestyle(‘--’)


plt.show()
import matplotlib.pyplot as plt


fig = plt.figure()
ax = fig.add_subplot(111)


ax.spines[‘top’].set_visible(False)
ax.spines[‘right’].set_visible(False)
ax.spines[‘bottom’].set_position(‘center’)
ax.spines[‘left’].set_position(‘center’)


for tick in ax.xaxis.get_major_ticks():
    tick.tick2On = False


for tick in ax.yaxis.get_major_ticks():
    tick.tick2On = False


plt.show()
Customizing location of Axes




ax1   =   fig.add_subplot(221)
ax2   =   fig.add_subplot(222)
ax3   =   fig.add_subplot(223)
ax4   =   fig.add_subplot(224)
Customizing location of Axes




# add_axes((left, bottom, width, height))


ax1   =   fig.add_axes((0.1, 0.1, 0.2, 0.8))
ax2   =   fig.add_axes((0.35, 0.55, 0.55, 0.35))
ax3   =   fig.add_axes((0.35, 0.1, 0.3, 0.4))
ax4   =   fig.add_axes((0.7, 0.1, 0.2, 0.4))
FREE!
The memory required for a figure is not completely
released until the figure is explicitly closed with close().

     import os
     import glob
     import matplotlib.pyplot as plt


     filelist = glob.glob(‘*.txt’)
     for fname in filelist:


                 ...
                 ...
                 ...


         fig = plt.figure()
         ax = fig.add_subplot(111)
         ax.plot(x, y)
         plt.savefig(os.path.splitext(fname)[0])
         plt.close(fig)
Signal propagation




• Vogels TP, Abbott LF (2005) Signal propagation and logic gating in networks of integrate-and-fire neurons. J Neurosci 25: 10786-10795.
• Brian: a simulator for spiking neural networks in Python (http://briansimulator.org)
Hierarchical clustering
mpl_toolkits.mplot3d
provides some basic 3D plotting tools
May the Matplotlib be with You :)

Contenu connexe

Tendances

Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Edureka!
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1Jatin Miglani
 
The TensorFlow dance craze
The TensorFlow dance crazeThe TensorFlow dance craze
The TensorFlow dance crazeGabriel Hamilton
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruzrpmcruz
 
PYTHON-Chapter 4-Plotting and Data Science PyLab - MAULIK BORSANIYA
PYTHON-Chapter 4-Plotting and Data Science  PyLab - MAULIK BORSANIYAPYTHON-Chapter 4-Plotting and Data Science  PyLab - MAULIK BORSANIYA
PYTHON-Chapter 4-Plotting and Data Science PyLab - MAULIK BORSANIYAMaulik Borsaniya
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyKimikazu Kato
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)PyData
 
Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. yazad dumasia
 
Gopher conbr golang e data science - oficial
Gopher conbr   golang e data science - oficialGopher conbr   golang e data science - oficial
Gopher conbr golang e data science - oficialRodrigo Pinheiro
 
Matplotlib demo code
Matplotlib demo codeMatplotlib demo code
Matplotlib demo codepythonsd
 
Functional Programming, simplified
Functional Programming, simplifiedFunctional Programming, simplified
Functional Programming, simplifiedNaveenkumar Muguda
 
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from..."PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...Edge AI and Vision Alliance
 

Tendances (20)

Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
 
Plotting data with python and pylab
Plotting data with python and pylabPlotting data with python and pylab
Plotting data with python and pylab
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1
 
The TensorFlow dance craze
The TensorFlow dance crazeThe TensorFlow dance craze
The TensorFlow dance craze
 
NumPy/SciPy Statistics
NumPy/SciPy StatisticsNumPy/SciPy Statistics
NumPy/SciPy Statistics
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
Gnuplot 2
Gnuplot 2Gnuplot 2
Gnuplot 2
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruz
 
Introduction to numpy
Introduction to numpyIntroduction to numpy
Introduction to numpy
 
NumPy
NumPyNumPy
NumPy
 
PYTHON-Chapter 4-Plotting and Data Science PyLab - MAULIK BORSANIYA
PYTHON-Chapter 4-Plotting and Data Science  PyLab - MAULIK BORSANIYAPYTHON-Chapter 4-Plotting and Data Science  PyLab - MAULIK BORSANIYA
PYTHON-Chapter 4-Plotting and Data Science PyLab - MAULIK BORSANIYA
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPy
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib.
 
Numpy
NumpyNumpy
Numpy
 
Gopher conbr golang e data science - oficial
Gopher conbr   golang e data science - oficialGopher conbr   golang e data science - oficial
Gopher conbr golang e data science - oficial
 
Matplotlib demo code
Matplotlib demo codeMatplotlib demo code
Matplotlib demo code
 
Functional Programming, simplified
Functional Programming, simplifiedFunctional Programming, simplified
Functional Programming, simplified
 
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from..."PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
 
Dma
DmaDma
Dma
 

En vedette

Data Visualization in matplotlib
Data Visualization in matplotlibData Visualization in matplotlib
Data Visualization in matplotlibBartosz Telenczuk
 
GR.jl - Plotting for Julia based on GR
GR.jl - Plotting for Julia based on GRGR.jl - Plotting for Julia based on GR
GR.jl - Plotting for Julia based on GRJosef Heinen
 
Quantitative management minimal spanning tree and dijkstra
Quantitative management minimal spanning tree and dijkstraQuantitative management minimal spanning tree and dijkstra
Quantitative management minimal spanning tree and dijkstraadarsh
 
Life after Matplotlib: Harder, Better, Faster, Stronger by Kayla Lacovino
Life after Matplotlib: Harder, Better, Faster, Stronger by Kayla LacovinoLife after Matplotlib: Harder, Better, Faster, Stronger by Kayla Lacovino
Life after Matplotlib: Harder, Better, Faster, Stronger by Kayla LacovinoPyData
 
Introduction to plotting in Python
Introduction to plotting in Python Introduction to plotting in Python
Introduction to plotting in Python bzamecnik
 
Dijkastra’s algorithm
Dijkastra’s algorithmDijkastra’s algorithm
Dijkastra’s algorithmPulkit Goel
 
Networks dijkstra's algorithm- pgsr
Networks  dijkstra's algorithm- pgsrNetworks  dijkstra's algorithm- pgsr
Networks dijkstra's algorithm- pgsrLinawati Adiman
 

En vedette (10)

Data Visualization in matplotlib
Data Visualization in matplotlibData Visualization in matplotlib
Data Visualization in matplotlib
 
Poscat seminar 10
Poscat seminar 10Poscat seminar 10
Poscat seminar 10
 
GR.jl - Plotting for Julia based on GR
GR.jl - Plotting for Julia based on GRGR.jl - Plotting for Julia based on GR
GR.jl - Plotting for Julia based on GR
 
Quantitative management minimal spanning tree and dijkstra
Quantitative management minimal spanning tree and dijkstraQuantitative management minimal spanning tree and dijkstra
Quantitative management minimal spanning tree and dijkstra
 
Life after Matplotlib: Harder, Better, Faster, Stronger by Kayla Lacovino
Life after Matplotlib: Harder, Better, Faster, Stronger by Kayla LacovinoLife after Matplotlib: Harder, Better, Faster, Stronger by Kayla Lacovino
Life after Matplotlib: Harder, Better, Faster, Stronger by Kayla Lacovino
 
Introduction to plotting in Python
Introduction to plotting in Python Introduction to plotting in Python
Introduction to plotting in Python
 
Dijkastra’s algorithm
Dijkastra’s algorithmDijkastra’s algorithm
Dijkastra’s algorithm
 
Networks dijkstra's algorithm- pgsr
Networks  dijkstra's algorithm- pgsrNetworks  dijkstra's algorithm- pgsr
Networks dijkstra's algorithm- pgsr
 
Dijekstra algorithm
Dijekstra algorithmDijekstra algorithm
Dijekstra algorithm
 
graph theory
graph theory graph theory
graph theory
 

Similaire à Use the Matplotlib, Luke @ PyCon Taiwan 2012

Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxSharmilaMore5
 
Python matplotlib cheat_sheet
Python matplotlib cheat_sheetPython matplotlib cheat_sheet
Python matplotlib cheat_sheetNishant Upadhyay
 
Numba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyNumba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyTravis Oliphant
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guideArulalan T
 
Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화Tae wook kang
 
14-visualization.pptx
14-visualization.pptx14-visualization.pptx
14-visualization.pptxssuser6e6eec
 
Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 
Python for Machine Learning(MatPlotLib).pptx
Python for Machine Learning(MatPlotLib).pptxPython for Machine Learning(MatPlotLib).pptx
Python for Machine Learning(MatPlotLib).pptxDr. Amanpreet Kaur
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
The Ring programming language version 1.3 book - Part 84 of 88
The Ring programming language version 1.3 book - Part 84 of 88The Ring programming language version 1.3 book - Part 84 of 88
The Ring programming language version 1.3 book - Part 84 of 88Mahmoud Samir Fayed
 
Python seaborn cheat_sheet
Python seaborn cheat_sheetPython seaborn cheat_sheet
Python seaborn cheat_sheetNishant Upadhyay
 
Python 培训讲义
Python 培训讲义Python 培训讲义
Python 培训讲义leejd
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 

Similaire à Use the Matplotlib, Luke @ PyCon Taiwan 2012 (20)

Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
 
MatplotLib.pptx
MatplotLib.pptxMatplotLib.pptx
MatplotLib.pptx
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
 
Python matplotlib cheat_sheet
Python matplotlib cheat_sheetPython matplotlib cheat_sheet
Python matplotlib cheat_sheet
 
Numba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyNumba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPy
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guide
 
Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화
 
Python programing
Python programingPython programing
Python programing
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
14-visualization.pptx
14-visualization.pptx14-visualization.pptx
14-visualization.pptx
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Python for Machine Learning(MatPlotLib).pptx
Python for Machine Learning(MatPlotLib).pptxPython for Machine Learning(MatPlotLib).pptx
Python for Machine Learning(MatPlotLib).pptx
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
The Ring programming language version 1.3 book - Part 84 of 88
The Ring programming language version 1.3 book - Part 84 of 88The Ring programming language version 1.3 book - Part 84 of 88
The Ring programming language version 1.3 book - Part 84 of 88
 
Python seaborn cheat_sheet
Python seaborn cheat_sheetPython seaborn cheat_sheet
Python seaborn cheat_sheet
 
Python 培训讲义
Python 培训讲义Python 培训讲义
Python 培训讲义
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 

Dernier

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Dernier (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Use the Matplotlib, Luke @ PyCon Taiwan 2012

  • 1. “ use the matplotlib, luke ” Wen-Wei Liao gattacaliao@gmail.com
  • 2. A long time ago, in a galaxy far, far away ...
  • 4. Matplotlib is a Python 2D plotting package which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms.
  • 5. Philosophy create simple plots with just a few commands, or just one! import numpy as np import matplotlib.pyplot as plt x = np.random.randn(10000) plt.hist(x, bins=50) plt.show()
  • 6. object-oriented interface FigureCanvas Renderer Artist state-machine interface pyplot
  • 7. pyplot provides a MATLAB-style pylab lumps pyplot together with state-machine interface to the underlying numpy in a single namespace, making object-oriented interface in matplotlib that environment even more MATLAB-like import numpy as np from pylab import * import matplotlib.pyplot as plt x = np.arange(0, 10, 0.1) x = arange(0, 10, 0.1) y = np.sin(x) y = sin(x) plt.plot(x, y) plot(x, y) plt.show() show()
  • 8. Explicit is better than implicit.
  • 9. preferred style using pyplot convenience functions, but object-orientation for the rest import numpy as np import matplotlib.pyplot as plt x = np.arange(0, 10, 0.1) y = np.sin(x) fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x, y) plt.show()
  • 10. 2 types of Artists • Primitives: Line2D, Rectangle, Text, etc. • Containers: Figure, Axes, Axis, Tick http://sfillustration.wordpress.com/2012/02/25/star-wars
  • 17. Customizing your objects each of the properties is accessed with an old-fashioned setter or getter a = o.get_alpha() o.set_alpha(0.5*a) set a number of properties at once o.set(alpha=0.5, zorder=2)
  • 18. import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) for label in ax.xaxis.get_ticklabels(): # label is a Text instance label.set_color(‘red’) label.set_rotation(45) label.set_fontsize(20) label.set_fontweight(‘bold’) for line in ax.yaxis.get_ticklines(): # line is a Line2D instance line.set_color(‘green’) line.set_markersize(30) line.set_markeredgewidth(5) plt.show()
  • 19. import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) for tick in ax.yaxis.get_major_ticks(): tick.label1On = False tick.label2On = True tick.label2.set_color(‘blue’) tick.label2.set_fontsize(20) tick.label2.set_fontweight(‘bold’) tick.gridOn = True tick.gridline.set_color(‘red’) tick.gridline.set_linewidth(2) tick.gridline.set_linestyle(‘--’) plt.show()
  • 20. import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax.spines[‘top’].set_visible(False) ax.spines[‘right’].set_visible(False) ax.spines[‘bottom’].set_position(‘center’) ax.spines[‘left’].set_position(‘center’) for tick in ax.xaxis.get_major_ticks(): tick.tick2On = False for tick in ax.yaxis.get_major_ticks(): tick.tick2On = False plt.show()
  • 21. Customizing location of Axes ax1 = fig.add_subplot(221) ax2 = fig.add_subplot(222) ax3 = fig.add_subplot(223) ax4 = fig.add_subplot(224)
  • 22. Customizing location of Axes # add_axes((left, bottom, width, height)) ax1 = fig.add_axes((0.1, 0.1, 0.2, 0.8)) ax2 = fig.add_axes((0.35, 0.55, 0.55, 0.35)) ax3 = fig.add_axes((0.35, 0.1, 0.3, 0.4)) ax4 = fig.add_axes((0.7, 0.1, 0.2, 0.4))
  • 23. FREE!
  • 24. The memory required for a figure is not completely released until the figure is explicitly closed with close(). import os import glob import matplotlib.pyplot as plt filelist = glob.glob(‘*.txt’) for fname in filelist: ... ... ... fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x, y) plt.savefig(os.path.splitext(fname)[0]) plt.close(fig)
  • 25. Signal propagation • Vogels TP, Abbott LF (2005) Signal propagation and logic gating in networks of integrate-and-fire neurons. J Neurosci 25: 10786-10795. • Brian: a simulator for spiking neural networks in Python (http://briansimulator.org)
  • 28. May the Matplotlib be with You :)