1 / 15

Matplotlib - 绘画

Matplotlib - 绘画. Outlines Python,Matplotlib 简介 绘画例子 令你眼花缭乱的图表. Python 是一种面向对象的、动态的程序设计语言。具有非常简洁而清晰的语法,适合于完成各种高层任务。它既可以用来快速开发程序脚本,也可以用来开发大规模的软件 。

heinz
Download Presentation

Matplotlib - 绘画

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Matplotlib-绘画

  2. Outlines • Python,Matplotlib简介 • 绘画例子 • 令你眼花缭乱的图表

  3. Python是一种面向对象的、动态的程序设计语言。具有非常简洁而清晰的语法,适合于完成各种高层任务。它既可以用来快速开发程序脚本,也可以用来开发大规模的软件。Python是一种面向对象的、动态的程序设计语言。具有非常简洁而清晰的语法,适合于完成各种高层任务。它既可以用来快速开发程序脚本,也可以用来开发大规模的软件。 • 随着NumPy, SciPy, Matplotlib, Enthoughtlibrarys等众多程序库的开发,Python越来越适合于做科学计算、绘制高质量的2D和3D图像。和科学计算领域最流行的商业软件Matlab相 比,Python是一门通用的程序设计语言,比Matlab所采用的脚本语言的应用范围更广泛,有更多的程序库的支持。 • matplotlib是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图。而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中

  4. 从一个例子开始

  5. 绘制多轴图 • subplot(numRows, numCols, plotNum) • for idx, color in enumerate("rgbyck"): plt.subplot(320+idx+1, axisbg=color) plt.show()

  6. Artists对象 • Artists分为简单类型和容器类型两种。简单类型的Artists为标准的绘图元件,例如Line2D、 Rectangle、 Text、AxesImage等等。而容器类型则可以包含许多简单类型的Artists,使它们组织成一个整体,例如Axis、 Axes、Figure等。

  7. 直接使用Artists创建图表的标准流程如下: • 创建Figure对象 fig = plt.figure() • 用Figure对象创建一个或者多个Axes或者Subplot对象 ax = fig.add_axes([0.15, 0.1, 0.7, 0.3]) • 调用Axies等对象的方法创建各种简单类型的Artists line, = ax.plot([1,2,3],[1,2,1])

  8. Figure容器 • >>> from matplotlib.lines import Line2D • >>> fig = plt.figure() • >>> line1 = Line2D([0,1],[0,1], transform=fig.transFigure, figure=fig, color="r") • >>> line2 = Line2D([0,1],[1,0], transform=fig.transFigure, figure=fig, color="g") • >>> fig.lines.extend([line1, line2]) • >>> fig.show()

  9. Figure对象包含其它的Artist对象的属性: axes : Axes对象列表 patch : 作为背景的Rectangle对象 images : FigureImage对象列表,用来显示图片 legends : Legend对象列表 lines : Line2D对象列表 patches : patch对象列表 texts : Text对象列表,用来显示文字

  10. Axes容器 Axes包含各种Artist对象的属性: artists : Artist对象列表 patch : 作为Axes背景的Patch对象,可以是 Rectangle或者Circle collections : Collection对象列表 images : AxesImage对象列表 legends : Legend对象列表 lines : Line2D对象列表 patches : Patch对象列表 texts : Text对象列表 xaxis: XAxis对象 yaxis: YAxis对象

  11. 散列图 fig = plt.figure() ax = fig.add_subplot(111) t = ax.scatter(np.random.rand(20), np.random.rand(20))

  12. Axis容器 • Axis容器包括坐标轴上的刻度线、刻度文本、坐标网格以及坐标轴标题等内容 plt.plot([1,2,3],[4,5,6]) axis = plt.gca().xaxis for label in axis.get_ticklabels(): label.set_color("red") label.set_rotation(45) label.set_fontsize(16) for line in axis.get_ticklines(): line.set_color("green") line.set_markersize(25) line.set_markeredgewidth(3) plt.show()

  13. Happy thanks giving day

More Related