Matplotlib: Difference between revisions

Content deleted Content added
Added the section "Usage in Scientific Research and Education"
Tags: Reverted Visual edit
m Reverted edits by 223.178.87.68 (talk) (HG) (3.4.13)
 
(30 intermediate revisions by 7 users not shown)
Line 25:
| website = {{URL|https://matplotlib.org}}
}}
'''<big>M</big>atplotlibMatplotlib''' (portmanteau of [[MATLAB]], plot, and library<ref>{{cite web | url=https://matplotlib.org/stable/project/history.html | title=History — Matplotlib 3.9.2 documentation }}</ref>) is a [[Plotter|plotting]] [[Library (computer science)|library]] for the [[Python (programming language)|Python]] [[programming language]] and its [[Numerical analysis|numerical mathematics]] extension [[NumPy]]. It provides an [[Object-oriented programming|object-oriented]] [[API]] for embedding plots into applications using general-purpose [[GUI toolkit]]s like [[Tkinter]], [[wxPython]], [[Qt (software)|Qt]], or [[GTK]]. There is also a [[Procedural programming|procedural]] "pylab" interface based on a [[state machine]] (like [[OpenGL]]), designed to closely resemble that of [[MATLAB]], though its use is discouraged.<ref>{{cite web|title=API Overview|url=https://matplotlib.org/stable/api/index.html#module-pylab|publisher=matplotlib.org}}</ref> [[SciPy]] makes use of Matplotlib.
 
Matplotlib was originally written by [[John D. Hunter]]. Since then it has had an active development community<ref>{{cite web |url=https://matplotlib.org/users/github_stats.html |title=Matplotlib github stats |publisher=matplotlib.org }}</ref> and is distributed under a [[BSD licenses|BSD-style license]]. Michael Droettboom was nominated as matplotlib's lead developer shortly before John Hunter's death in August 2012<ref>{{cite web |url=http://matplotlib.1069221.n5.nabble.com/ANN-Michael-Droettboom-matplotlib-lead-developer-td5037.html |title=Announcing Michael Droettboom as the lead Matplotlib developer |publisher=matplotlib.org |access-date=2013-04-24 |archive-date=2020-10-27 |archive-url=https://web.archive.org/web/20201027122844/http://matplotlib.1069221.n5.nabble.com/ANN-Michael-Droettboom-matplotlib-lead-developer-td5037.html |url-status=dead }}</ref> and was further joined by Thomas Caswell.<ref>{{Cite news|url=https://www.numfocus.org/blog/matplotlib-lead-developer-explains-why-he-cant-fix-the-docs-but-you-can|title=Matplotlib Lead Developer Explains Why He Can't Fix the Docs—But You Can – NumFOCUS|date=2017-10-05|work=NumFOCUS|access-date=2018-04-11|language=en-US}}</ref><ref>{{Cite web|url=https://matplotlib.org/users/credits.html|title=Credits – Matplotlib 2.2.2 documentation|website=matplotlib.org|access-date=2018-04-11}}</ref> Matplotlib is a [[NumFOCUS]] fiscally sponsored project.<ref>{{cite web|title=NumFOCUS Sponsored Projects|url=https://numfocus.org/sponsored-projects|publisher=NumFOCUS|access-date=2021-10-25}}</ref>
 
== Usage in Scientific Research and Education ==
 
Matplotlib is widely utilizedused in scientific research as a tool for data visualization. Researchers across many disciplines such as physics, astronomy, engineering, and biology use Matplotlib to create publication-quality graphs and plots for their analyses and papers. An analysis of the [[arXiv]] preprint repository found that roughly 15% of all papers included figures generated with Matplotlib.<ref name="CoiledMatplotlib">{{cite web |title=How Popular is Matplotlib? |url=https://docs.coiled.io/user_guide/arxiv-matplotlib.html |website=Coiled Documentation |access-date=22 April 2025}}</ref> The library has been employed in well-known scientific projects; forFor example, the [[Event Horizon Telescope]] collaboration used Matplotlib to produce visualizations during the effort to create the first-ever image of a black hole.<ref name="NumPyBlackHole">{{cite web |title=Case Study: First Image of a Black Hole |url=https://numpy.org/case-studies/blackhole-image/ |website=NumPy |access-date=22 April 2025}}</ref> Matplotlib also underpins the plotting functionality of many scientific [[Python (Programmingprogramming Languagelanguage)|Python]] libraries (for instance, [[pandas (software)|pandas’pandas]] data frame plotting uses Matplotlib as its default backend).<ref name="SoftwareCarpentry">{{citefor web |title=Plotting and Programming in Python |url=https://swcarpentry.github.io/python-novice-gapminder/09-plotting/index).html |website=Software Carpentry |access-date=22 April 2025}}</ref> Its importance to the scientific community has been acknowledged by institutions likesuch as [[NASA]], which in 2024 awarded a grant to support Matplotlib’s continued development as part of an initiative to supportfund widely used open-source scientific software.<ref name="NASAOpenSource">{{cite web |title=NASA Funds Open-Source Software Underpinning Scientific Innovation |url=https://www.nasa.gov/news-release/nasa-funds-open-source-software-underpinning-scientific-innovation/ |website=NASA |access-date=22 April 2025}}</ref>
[[File:Matplotlib in jupyter notebook.png|thumb|284x284px|Example of Matplotlib being used in Jupyter Notebook]]
In education and data science, Matplotlib is a standard tool for teaching programming and visualization. It integrates seamlessly with [[Jupyter Notebook]], allowing students and instructors to generate inline plots and interactively explore data within a notebook environment.<ref name="GeeksforGeeksJupyter">{{cite web |title=Using Matplotlib with Jupyter Notebook |url=https://www.geeksforgeeks.org/using-matplotlib-with-jupyter-notebook/ |website=GeeksforGeeks |access-date=22 April 2025}}</ref> Matplotlib’s syntax is believed to be straightforward with extensive documentation available online, making it suitable for introducing concepts of data analysis and scientific computing in classrooms. Educational institutions commonly use Matplotlib in their curriculum to teach data visualization and STEM concepts,<ref name="MatplotlibTutorial">{{cite web |title=Pyplot tutorial |url=https://matplotlib.org/stable/tutorials/introductory/pyplot.html |website=Matplotlib |access-date=22 April 2025}}</ref> and it is featured in many tutorials, workshops, and open online courses as a primary plotting library. This widespread adoption in both academia and industry has solidified Matplotlib’s role as a commonly used in scientific and educational visualization workflows.
 
[[File:Matplotlib in jupyter notebook.png|thumb|284x284px258x258px|ExampleA ofscatter Matplotlibplot being usedcreated in Jupyter Notebook using Matplotlib]]
==Comparison with MATLAB==
Pyplot is a Matplotlib module that provides a MATLAB-like interface.<ref>{{Cite web|url=https://matplotlib.org/index.html|title=Matplotlib: Python plotting — Matplotlib 3.2.0 documentation|website=matplotlib.org|access-date=2020-03-14}}</ref> Matplotlib is designed to be as usable as MATLAB, with the ability to use Python, and the advantage of being free and [[Open source|open-source]].
 
In education and data science, Matplotlib is afrequently standardused toolto for teachingteach programming and data visualization. It integrates seamlessly with [[Jupyter Notebook]], allowing students and instructors to generate inline plots and interactively explore data within a notebook environment.<ref name="GeeksforGeeksJupyterJupyterNature">{{cite webnews |title=UsingInteractive Matplotlibnotebooks: withSharing Jupyterthe Notebookcode |url=https://www.geeksforgeeksnature.orgcom/usingarticles/d41586-matplotlib018-with07196-jupyter-notebook/1 |websitework=GeeksforGeeksNature |date=18 September 2018 |access-date=22 April 2025}}</ref> Matplotlib’sMany syntax is believed to be straightforward with extensive documentation available online, making it suitable for introducing concepts of data analysis and scientific computing in classrooms. Educationaleducational institutions commonly useincorporate Matplotlib ininto their curriculumcurricula tofor teach data visualization andteaching STEM concepts,<ref name="MatplotlibTutorial">{{cite web |title=Pyplot tutorial |url=https://matplotlib.org/stable/tutorials/introductory/pyplot.html |website=Matplotlib |access-date=22 April 2025}}</ref> and it is widely featured in many tutorials, workshops, and open online courses as a primary plotting library. This widespread adoption in both academia and industry has solidified Matplotlib’s role as a commonly used in scientific and educational visualization workflows.
==Plot Types==
[[Matplotlib]] supports various types of 2 dimensional and 3 dimensional plots. The support for two dimensional plots is robust. The support for three dimensional plots was added later and while it is good, it is not as robust as 2 dimensional plots.
 
===Examples===
<gallery mode="packed">
File:Synchrotron Functions.svg|'''Line plot'''
File:Matplotlib histogram v.svg|'''Histogram'''
File:Sparse data.png|'''Scatter plot'''
File:Matplotlib 3d v.svg|'''3D plot'''
File:Mpl example qbo.svg|'''Image plot'''
File:Mpl example Helmoltz coils.svg|'''Contour plot'''
File:Logarithmic Spiral Pylab.svg|'''Polar plot'''
File:Temp-sunspot-co2.svg|'''Line plot'''
File:Mpl example Rosenbrock function.svg|'''3-D plot'''
File:Mandelbrot set, plotted with Matplotlib.svg|'''Image plot'''
File:BOXPLOT.png|'''Box Plot'''<br/>Used to show the distribution of a data set. The median and outliers are highlighted
File:PIECHART.png|'''Pie Chart'''<br/>Useful for showing the proportions of each category involved.
File:BARGRAPH.png|'''Bar Graph'''<br/>Useful for comparing different groups side by side
</gallery>
 
==Animations==
Matplotlib-animation<ref>{{cite web|url=https://matplotlib.org/stable/users/explain/animations/animations.html|title=Animations using Matplotlib|publisher=matplotlib.org|accessdate=30 Aug 2024}}</ref> capabilities are intended for visualizing how certain data changes. However, one can use the functionality in any way required.
 
These animations are defined as a function of frame number (or time). In other words, one defines a function that takes a frame number as input and defines/updates the matplotlib-figure based on it.
 
<blockquote> The time at the beginning of a frame-number since the start of animation can be calculated as - <math>\text{time} = \frac{\text{frame-number}-1}{\text{FPS}}</math></blockquote>
 
==Toolkits==
Several toolkits are available which extend Matplotlib functionality. Some are separate [[Download|downloads]], others ship with the Matplotlib [[source code]] but have external dependencies.<ref>{{cite web |url=https://matplotlib.org/thirdpartypackages/index.html |title=Toolkits |publisher=matplotlib.org}}</ref>
 
*[[Web mapping|Basemap]]: map plotting with various [[Map projection|map projections]], [[Coast|coastlines]], and political boundaries<ref name=basemap>{{cite web|last=Whitaker|first=Jeffrey|title=The Matplotlib Basemap Toolkit User's Guide (v. 1.0.5)|url=https://matplotlib.org/basemap/index.html|work=Matplotlib Basemap Toolkit documentation|accessdate=24 April 2013}}</ref>
*Cartopy: a mapping library featuring object-oriented map projection definitions, and arbitrary point, line, [[polygon]] and image transformation capabilities.<ref name=cartopy>{{cite web|last=Elson|first=Philip|title=Cartopy|url=http://scitools.org.uk/cartopy/docs/latest/|accessdate=24 April 2013}}</ref> (Matplotlib v1.2 and above)
*Excel tools: utilities for exchanging data with [[Microsoft Excel]]
*GTK tools: interface to the GTK library
*Qt interface
*Mplot3d: 3-D plots
*Natgrid: interface to the natgrid library for gridding irregularly spaced data.
*tikzplotlib: export to Pgfplots for smooth integration into [[LaTeX]] documents (formerly known as ''matplotlib2tikz'')<ref name=tikzplotlib>{{cite web|last=Schlömer|first=Nico|title=tikzplotlib|website=[[GitHub]]|url=https://github.com/nschloe/tikzplotlib|accessdate=7 November 2016}}</ref>
* Seaborn: provides an API on top of Matplotlib that offers sane choices for plot style and color defaults, defines simple high-level functions for common statistical plot types, and integrates with the functionality provided by [[Pandas (software)|Pandas]]
* GeoPandas:<ref>{{Cite web |title=GeoPandas 0.14.4 — GeoPandas 0.14.4+0.g60c9773.dirty documentation |url=https://geopandas.org/en/stable/ |access-date=2024-04-29 |website=geopandas.org}}</ref> simplifies geospatial work in Python without needing a spatial database like PostGIS<ref>{{Citation |last=Jordahl |first=Kelsey |title=geopandas: Geographic pandas extensions |url=https://pypi.org/project/geopandas/ |access-date=2024-04-29}}</ref>
* Cartopy: streamlines map creation in matplotlib by enabling users to specify a projection and add coastlines with a single line of code<ref>{{Cite web |title=Using cartopy with matplotlib — cartopy 0.15.0 documentation |url=https://scitools.org.uk/cartopy/docs/v0.15/matplotlib/intro.html |access-date=2024-04-30 |website=scitools.org.uk}}</ref>
 
==Related projects==
* Biggles<ref>{{cite web |url=http://biggles.sourceforge.net/ |title=Bigglessimple, elegant python plotting |publisher=biggles.sourceforge.net |accessdate=24 November 2010}}</ref>
* Chaco<ref>{{cite web |url=http://docs.enthought.com/chaco/ |title=Chaco |publisher=code.enthought.com}}</ref>
* [[DISLIN]]
* [[GNU Octave]]
* [[Plotly]] – for interactive, online Matplotlib and Python graphs
* [https://github.com/dkogan/gnuplotlib/ gnuplotlib] – plotting for numpy with a gnuplot backend
* [[Gnuplot]]-py<ref>{{cite web |url=http://gnuplot-py.sourceforge.net/ |title=Gnuplot.py on |publisher=gnuplot-py.sourceforge.net |accessdate=24 November 2010}}</ref>
* [[PLplot]] – Python bindings available
* [[SageMath]] – uses <code>Matplotlib</code> to draw plots
* SciPy (modules <code>plt</code> and <code>gplt</code>)
* [[Plotly]] – for interactive, online Matplotlib and Python graphs
* Bokeh<ref>{{Cite web|url=https://docs.bokeh.org/en/latest/|title=Bokeh 2.0.0 Documentation|website=docs.bokeh.org|access-date=2020-03-14}}</ref> – Python interactive visualization library that targets modern web browsers for presentation
 
==References==