编辑“︁
Matplotlib
”︁
跳转到导航
跳转到搜索
警告:
您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您
登录
或
创建账号
,您的编辑会以您的用户名署名,此外还有其他益处。
反垃圾检查。
不要
加入这个!
{{lowercase title}} {{Roughtranslation}} {{Infobox software |name=matplotlib |logo=<!-- 檔案不存在 [[File:Matplotlib logo.svg|300px]] ,可從英文維基百科取得 --> |screenshot=File:Mpl screenshot figures and code.png |caption=Matplotlib繪製的圖表與程式碼 |author={{le|John D. Hunter}} |developer=[http://matplotlib.org/users/credits.html Michael Droettboom, ''et al.''] |released={{Start date and age|df=yes|2003}}<ref>{{cite web |url=http://matplotlib.org/users/license.html#copyright-policy |title=Copyright Policy |accessdate=2017-02-23 |archive-date=2020-12-02 |archive-url=https://web.archive.org/web/20201202130541/https://matplotlib.org/users/license.html#copyright-policy |dead-url=no }}</ref> | latest release version = 3.3.2 | latest release date = {{Start date and age|2020|09|15|df=yes}}<ref>{{cite web |url=https://github.com/matplotlib/matplotlib/releases |title=Releases – matplotlib |accessdate=2019-05-13 |archive-date=2020-11-11 |archive-url=https://web.archive.org/web/20201111233155/https://github.com/matplotlib/matplotlib/releases |dead-url=no }}</ref> |programming language=[[Python]] |operating system=[[跨平臺]] |genre={{le|信息图形软件列表|List of information graphics software|绘图}} |license=[http://matplotlib.org/users/license.html matplotlib license] |website={{URL|http://matplotlib.org/}} }} '''Matplotlib'''是[[Python]]语言及其数值计算库[[NumPy]]的{{le|绘图|Plot (graphics)}}[[函式庫|库]]。它提供了一个[[面向对象程序设计|面向对象]]的[[应用程序接口|API]],可以将绘图嵌入到使用通用[[部件工具箱|GUI工具包]](如[[Tkinter]]、[[wxPython]]、[[Qt]]或[[GTK]])的程序中。它还有一个基于[[有限状态机|状态机]](就像[[OpenGL]])的[[过程式编程]]“pylab”接口,其设计与[[MATLAB]]非常类似,但由於[[命名空間]]的問題,因此建議改用matplotlib.pyplot取代。<ref>{{cite web|title=API Overview|url=https://matplotlib.org/stable/api/index.html#module-pylab|dead-url=no|publisher=matplotlib.org|access-date=2021-06-18|archive-date=2021-07-01|archive-url=https://web.archive.org/web/20210701015406/https://matplotlib.org/stable/api/index.html#module-pylab}}</ref>[[SciPy]]使用matplotlib进行图形绘制。 Matplotlib最初由美國神經生物學家{{link-en|John D. Hunter}}撰写,於2003年面世,从此它拥有一个活跃的开发社区<ref>{{cite web |url=https://matplotlib.org/users/github_stats.html |title=Matplotlib github stats |publisher=matplotlib.org |access-date=2021-06-18 |archive-date=2021-06-24 |archive-url=https://web.archive.org/web/20210624200621/https://matplotlib.org/users/github_stats.html }}</ref>,并根据[[BSD许可证]]发布。 在John D. Hunter于2012年8月去世前不久,Michael Droettboom被提名为matplotlib的主要开发者<ref name=":0">{{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|accessdate=2017-02-23|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|dead-url=no}}</ref>,随后,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|archive-date=2021-06-28|archive-url=https://web.archive.org/web/20210628070358/https://numfocus.org/blog/matplotlib-lead-developer-explains-why-he-cant-fix-the-docs-but-you-can}}</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|archive-date=2021-06-24|archive-url=https://web.archive.org/web/20210624201400/https://matplotlib.org/users/credits.html}}</ref>Matplotlib是一个由NumFOCUS财政资助的项目。<ref>{{cite web|title=NumFOCUS Sponsored Projects|url=https://numfocus.org/sponsored-projects|access-date=2021-10-25|publisher=NumFOCUS|archive-date=2023-06-04|archive-url=https://web.archive.org/web/20230604220722/https://numfocus.org/sponsored-projects|dead-url=no}}</ref> Matplotlib 2.0.x支持Python 2.7到3.10版本。Matplotlib 1.2是第一个支持Python 3.x的版本。Matplotlib 1.4是最后一个支持Python 2.6的版本。<ref>{{cite web| title = Installing – Matplotlib 2.0.2 documentation| url = https://matplotlib.org/users/installing.html| accessdate = 2017-06-23| archive-date = 2021-06-24| archive-url = https://web.archive.org/web/20210624200621/https://matplotlib.org/users/installing.html}}</ref>Matplotlib已签署Python 3声明,承诺在2020年后不再支持Python 2。<ref>{{Cite web|url=https://github.com/python3statement/python3statement.github.io/pull/20|title=Add Matplotlib to list by takluyver · Pull Request #20 · python3statement/python3statement.github.io|website=GitHub|language=en|access-date=2018-04-11|archive-date=2020-11-20|archive-url=https://web.archive.org/web/20201120101645/https://github.com/python3statement/python3statement.github.io/pull/20}}</ref> == 与MATLAB的比较 == Pyplot是matplotlib的一个模块,它提供了一个类似MATLAB的接口。 <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|archive-date=2021-05-07|archive-url=https://web.archive.org/web/20210507050611/https://matplotlib.org/index.html}}</ref>Matplotlib被设计成与MATLAB一样可用,能够使用Python,并且具有[[自由开源]]的优点。 == 与 Gnuplot的比较 == [[gnuplot]]和matplotlib都是成熟的开源项目。 它们都可以产生多种不同绘图类型。 虽然很难指定一种某人能做而他人不能做的图形类型,但它们仍然具有不同的优点和缺点: {| class="wikitable" style="margin-bottom: 10px;" data-gramm_id="0dbf858f-89ba-efca-0ff6-55f592f0c743" data-gramm="true" spellcheck="false" data-gramm_editor="true" ! ! 优点 ! 缺点 |- | Matplotlib | * 带有内置代码的默认绘图样式 * 与Python的深度集成 * Matlab风格的编程接口(对一些人来说是优点,但对于其他人来说可能是缺点)。 * 图形绘制相较Gnuplot更加美观 | * 高度依赖其他包,如Numpy。 * 只适用于Python:很难/不可能在Python以外的语言中使用。 (但可以从Julia通过PyPlot软件包使用) |- | Gnuplot | * 跨语言解决方案:可以用作通过管道或文件以不同语言编写的应用程序(例如GNU Octave,Maxima,JavaGnuplotHybrid)中的绘图引擎。 * 独立程序:没有外部依赖。 * 处理大型数据集时非常快。 * 更容易操纵绘图细节 | * 旧的默认绘图样式:通常需要小的调整以产生有吸引力的图。 * 在开发中活跃成员的数量较少(与Matplotlib相比)。 |} == 例子 == ''' 曲线图''' [[File:Matplotlib_basic_v.svg|缩略图]] <syntaxhighlight lang="numpy"> >>> import matplotlib.pyplot as plt >>> import numpy as np >>> a = np.linspace(0,10,100) >>> b = np.exp(-a) >>> plt.plot(a,b) >>> plt.show() </syntaxhighlight> '''[[直方图]]''' [[File:Matplotlib_histogram_v.svg|缩略图]] <syntaxhighlight lang="numpy"> >>> import matplotlib.pyplot as plt >>> from numpy.random import normal,rand >>> x = normal(size=200) >>> plt.hist(x,bins=30) >>> plt.show() </syntaxhighlight> '''散点图''' [[File:Matplotlib_scatter_v.svg|缩略图]] <syntaxhighlight lang="numpy"> >>> import matplotlib.pyplot as plt >>> from numpy.random import rand >>> a = rand(100) >>> b = rand(100) >>> plt.scatter(a,b) >>> plt.show() </syntaxhighlight> '''3D 图''' [[File:Matplotlib_3d_v.svg|缩略图]] <syntaxhighlight lang="numpy"> >>> from matplotlib import cm >>> from mpl_toolkits.mplot3d import Axes3D >>> import matplotlib.pyplot as plt >>> import numpy as np >>> fig = plt.figure() >>> # ax = fig.gca(projection='3d') (Old) >>> ax = fig.add_subplot(projection='3d') >>> X = np.arange(-5, 5, 0.25) >>> Y = np.arange(-5, 5, 0.25) >>> X, Y = np.meshgrid(X, Y) >>> R = np.sqrt(X**2 + Y**2) >>> Z = np.sin(R) >>> surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm) >>> plt.show() </syntaxhighlight> '''更多例子'''<gallery> File:Mpl example qbo.svg|Image plot File:Mpl example Helmoltz coils.svg|Contour plot File:Weight Growth of RN First Rate Line-of-Battle Ships 1630-1875.svg|Scatter 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 </gallery> == 轶事 == [[File:Matplotlib xkcd.png|thumb|使用xkcd风格绘制的正弦函数图像]] 为了致敬[[xkcd]],matplotlib加入了matplotlib.pyplot.xkcd()函数,模仿xkcd的漫画风格进行绘图。<ref>{{cite web |title=matplotlib.pyplot.xkcd — Matplotlib 3.4.2 documentation |url=https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.xkcd.html |website=matplotlib.org |accessdate=2021-07-05 |language=en |archive-date=2021-07-09 |archive-url=https://web.archive.org/web/20210709184957/https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.xkcd.html }}</ref><ref>{{cite web |title=XKCD — Matplotlib 3.4.2 documentation |url=https://matplotlib.org/stable/gallery/showcase/xkcd.html |website=matplotlib.org |accessdate=2021-07-05 |language=en |archive-date=2021-07-11 |archive-url=https://web.archive.org/web/20210711021337/https://matplotlib.org/stable/gallery/showcase/xkcd.html }}</ref> == 参考资料 == {{Reflist|2}} == 参见 == {{div col|4}} *[[gnuplot]] *[[MATLAB]] {{div col end}} == 外部链接 == {{Commons category|Matplotlib}} * {{Official website|https://matplotlib.org}} {{SciPy ecosystem}} [[Category:用Python編程的自由軟體]] [[Category:自由圖表軟件]] [[Category:Python科学库]]
摘要:
请注意,所有对Local Chinese Wikipedia的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
Project:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
导航菜单
个人工具
未登录
讨论
贡献
创建账号
登录
命名空间
页面
讨论
大陆简体
不转换
简体
繁體
大陆简体
香港繁體
澳門繁體
大马简体
新加坡简体
臺灣正體
查看
阅读
编辑
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息