diff --git a/docs/tutorials/introductory/sample_plots.md b/docs/tutorials/introductory/sample_plots.md index 436daf2..9e2e3cd 100644 --- a/docs/tutorials/introductory/sample_plots.md +++ b/docs/tutorials/introductory/sample_plots.md @@ -2,15 +2,12 @@ sidebarDepth: 3 sidebar: auto --- +# 使用Matplotlib绘制简单图形 +在此会提供很多图例以及绘制他们的代码. -# Sample plots in Matplotlib +## 折线图(line plot) -Here you'll find a host of example plots with the code that -generated them. - -## Line Plot - -Here's how to create a line plot with text labels using +创建带有文本标签的折线图 [``plot()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot).
@@ -18,28 +15,27 @@ Here's how to create a line plot with text labels using

- Simple Plot + 简单绘图

-## Multiple subplots in one figure +## 一个图(figure)中含多个子图(subplots) -Multiple axes (i.e. subplots) are created with the -[``subplot()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot) function: +多子图使用 +[``subplot()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot) 函数创建:

- Subplot + 子图

-## Images +## 图像显示(image) -Matplotlib can display images (assuming equally spaced -horizontal dimensions) using the [``imshow()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imshow.html#matplotlib.pyplot.imshow) function. +可以使用 [``imshow()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imshow.html#matplotlib.pyplot.imshow) 函数来显示图像.
@@ -47,15 +43,12 @@ horizontal dimensions) using the [``imshow()``](https://matplotlib.org/api/_as_g
-**Example of using [``imshow()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imshow.html#matplotlib.pyplot.imshow) to display a CT scan** +**上图为使用[``imshow()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imshow.html#matplotlib.pyplot.imshow)展示的CT图** -## Contouring and pseudocolor +## 热力图(pcolormesh)与等高线(contour) -The [``pcolormesh()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pcolormesh.html#matplotlib.pyplot.pcolormesh) function can make a colored -representation of a two-dimensional array, even if the horizontal dimensions -are unevenly spaced. The -[``contour()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.contour.html#matplotlib.pyplot.contour) function is another way to represent -the same data: + 函数[``pcolormesh()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pcolormesh.html#matplotlib.pyplot.pcolormesh) 可以使用色彩来描绘横坐标间隔一致或不一致的二维向量。 + 函数[``contour()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.contour.html#matplotlib.pyplot.contour)与其类似:
@@ -63,164 +56,137 @@ the same data:
-**Example comparing [``pcolormesh()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pcolormesh.html#matplotlib.pyplot.pcolormesh) and [``contour()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.contour.html#matplotlib.pyplot.contour) for plotting two-dimensional data** +**[``pcolormesh()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pcolormesh.html#matplotlib.pyplot.pcolormesh) 与[``contour()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.contour.html#matplotlib.pyplot.contour)的比较** -## Histograms +## 直方图(Histogram) -The [``hist()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hist.html#matplotlib.pyplot.hist) function automatically generates -histograms and returns the bin counts or probabilities: +函数 [``hist()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hist.html#matplotlib.pyplot.hist) 自动生成直方图,并且返回每bin的数目或概率:

- Histogram Features + 直方图

-## Paths +## 折线轨迹(Paths) -You can add arbitrary paths in Matplotlib using the -[``matplotlib.path``](https://matplotlib.org/api/path_api.html#module-matplotlib.path) module: +matplotlib中用于折线处理的类主要是[``matplotlib.path``](https://matplotlib.org/api/path_api.html#module-matplotlib.path) ,几乎所有矢量绘图都在绘图管道(drawing pipeline)中使用了折线,虽然无法绘制path实例本身,但也可以使其可视化:

- Path Patch + 轨迹绘制

-## Three-dimensional plotting +## 绘制三维图表 -The mplot3d toolkit (see [Getting started](https://matplotlib.org//toolkits/mplot3d.html#toolkit-mplot3d-tutorial) and -[3D plotting](https://matplotlib.org/gallery/index.html#mplot3d-examples-index)) has support for simple 3d graphs -including surface, wireframe, scatter, and bar charts. +matpltlib三维工具箱(The mplot3d toolkit)能够支持简单的三维图表,其中包括曲面图,线框图,散点图与条形图。 (详见 [Getting started](https://matplotlib.org//toolkits/mplot3d.html#toolkit-mplot3d-tutorial) 与[3D plotting](https://matplotlib.org/gallery/index.html#mplot3d-examples-index))

- Surface3d + 3维曲面

-Thanks to John Porter, Jonathon Taylor, Reinier Heeres, and Ben Root for -the ``mplot3d`` toolkit. This toolkit is included with all standard Matplotlib -installs. +感谢John Porter, Jonathon Taylor, Reinier Heeres, 与 Ben Root 对 +``mplot3d``所做出的贡献 . 该工具箱在所有完整版的matpltlib中均已包含,无需再次安装. -## Streamplot +## 流量图(Streamplot) -The [``streamplot()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.streamplot.html#matplotlib.pyplot.streamplot) function plots the streamlines of -a vector field. In addition to simply plotting the streamlines, it allows you -to map the colors and/or line widths of streamlines to a separate parameter, -such as the speed or local intensity of the vector field. +函数[``streamplot()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.streamplot.html#matplotlib.pyplot.streamplot)绘制向量场的流量图. 除了简单的绘制流线外, 它还允许您将流线的颜色和(或)线宽映射到单独的参数,例如矢量场的速度或局部强度。

- Streamplot with various plotting options. + 流量图的各种类型.

-This feature complements the [``quiver()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.quiver.html#matplotlib.pyplot.quiver) function for -plotting vector fields. Thanks to Tom Flannaghan and Tony Yu for adding the -streamplot function. +感谢Tom Flannaghan 与 Tony Yu 为[``quiver()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.quiver.html#matplotlib.pyplot.quiver) 提供了绘制向量场的功能. -## Ellipses +## 椭圆(Ellipses) -In support of the [Phoenix](http://www.jpl.nasa.gov/news/phoenix/main.php) -mission to Mars (which used Matplotlib to display ground tracking of -spacecraft), Michael Droettboom built on work by Charlie Moad to provide -an extremely accurate 8-spline approximation to elliptical arcs (see -[``Arc``](https://matplotlib.org/api/_as_gen/matplotlib.patches.Arc.html#matplotlib.patches.Arc)), which are insensitive to zoom level. +迈克尔·德罗特布姆(Michael Droettboom)以查理·莫阿德(Charlie Moad)的作品为基础,为椭圆弧提供了极其精确的八次贝塞尔样条近似(eight cubic Bezier splines)(详见[``Arc``](https://matplotlib.org/api/_as_gen/matplotlib.patches.Arc.html#matplotlib.patches.Arc)), 这种椭圆弧其对缩放级别不敏感.

- Ellipse Demo + 椭圆展示

-## Bar charts +## 条形图(Bar charts) -Use the [``bar()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.bar.html#matplotlib.pyplot.bar) function to make bar charts, which -includes customizations such as error bars: +使用 [``bar()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.bar.html#matplotlib.pyplot.bar) 函数来创建一个条形图, 其中包括自定义设置,例如错误栏:

- Barchart Demo + 条形图展示

-You can also create stacked bars +你也可以创建多分类累计柱状图(stacked bars) ([bar_stacked.py](https://matplotlib.org/gallery/lines_bars_and_markers/bar_stacked.html)), -or horizontal bar charts +或是水平条状态(horizontal bar charts) ([barh.py](https://matplotlib.org/gallery/lines_bars_and_markers/barh.html)). -## Pie charts +## 饼图(Pie charts) -The [``pie()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pie.html#matplotlib.pyplot.pie) function allows you to create pie -charts. Optional features include auto-labeling the percentage of area, -exploding one or more wedges from the center of the pie, and a shadow effect. -Take a close look at the attached code, which generates this figure in just -a few lines of code. +函数[``pie()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pie.html#matplotlib.pyplot.pie) 可以创建一个饼图.可选功能包括自动标记面积百分比,从饼图中心爆炸一个或多个楔形以及阴影效果,只需几行代码即可生成此图形。

- Pie Features + 饼图展示

-## Tables - -The [``table()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.table.html#matplotlib.pyplot.table) function adds a text table -to an axes. +## 表格(Tables) +函数[``table()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.table.html#matplotlib.pyplot.table) 添加表格到坐标轴上。

- Table Demo + 表格展示

-## Scatter plots +## 散点图(Scatter plots) -The [``scatter()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html#matplotlib.pyplot.scatter) function makes a scatter plot -with (optional) size and color arguments. This example plots changes -in Google's stock price, with marker sizes reflecting the -trading volume and colors varying with time. Here, the -alpha attribute is used to make semitransparent circle markers. +函数 [``scatter()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html#matplotlib.pyplot.scatter)用于绘制可设置大小及颜色的散点图,本示例绘制了Google股票价格的变化图,散点大小反映了交易量,颜色随时间变化,函数中的alpha为透明度。

- Scatter Demo2 + 散点图展示

-## GUI widgets +## 图形界面控件(GUI widgets) -Matplotlib has basic GUI widgets that are independent of the graphical -user interface you are using, allowing you to write cross GUI figures -and widgets. See [``matplotlib.widgets``](https://matplotlib.org/api/widgets_api.html#module-matplotlib.widgets) and the +Matplotlib提供了一些基本的独立于用户所使用的交互界面的GUI控件, 供用户跨GUI绘图. 详见 [``matplotlib.widgets``](https://matplotlib.org/api/widgets_api.html#module-matplotlib.widgets) 与 [widget examples](https://matplotlib.org/gallery/index.html).
@@ -228,138 +194,123 @@ and widgets. See [``matplotlib.widgets``](https://matplotlib.org/api/widgets_api

- Slider and radio-button GUI. + 滑动条与播放旋钮.

-## Filled curves +## 色彩填充(Filled curves) -The [``fill()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.fill.html#matplotlib.pyplot.fill) function lets you -plot filled curves and polygons: +函数 [``fill()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.fill.html#matplotlib.pyplot.fill) 可以让你填充曲线与多边形:

- Fill + 填充

-Thanks to Andrew Straw for adding this function. +感谢 Andrew Straw 添加了这个函数. -## Date handling +## 时间处理(Date handling) -You can plot timeseries data with major and minor ticks and custom -tick formatters for both. +你可以绘制可设置主次刻度的时间序列。

- Date + 时间序列

-See [``matplotlib.ticker``](https://matplotlib.org/api/ticker_api.html#module-matplotlib.ticker) and [``matplotlib.dates``](https://matplotlib.org/api/dates_api.html#module-matplotlib.dates) for details and usage. +详见 [``matplotlib.ticker``](https://matplotlib.org/api/ticker_api.html#module-matplotlib.ticker) and [``matplotlib.dates``](https://matplotlib.org/api/dates_api.html#module-matplotlib.dates). -## Log plots +## 对数图(Log plots) -The [``semilogx()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.semilogx.html#matplotlib.pyplot.semilogx), -[``semilogy()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.semilogy.html#matplotlib.pyplot.semilogy) and -[``loglog()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.loglog.html#matplotlib.pyplot.loglog) functions simplify the creation of -logarithmic plots. +函数 [``semilogx()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.semilogx.html#matplotlib.pyplot.semilogx), +[``semilogy()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.semilogy.html#matplotlib.pyplot.semilogy) 与 +[``loglog()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.loglog.html#matplotlib.pyplot.loglog) 简化了对数图的创建。

- Log Demo + 对数图展示

-Thanks to Andrew Straw, Darren Dale and Gregory Lielens for contributions -log-scaling infrastructure. +感谢 Andrew Straw, Darren Dale 与 Gregory Lielens 对log-scaling infrastructure的贡献. -## Polar plots +## 极坐标图(Polar plots) -The [``polar()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.polar.html#matplotlib.pyplot.polar) function generates polar plots. +函数 [``polar()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.polar.html#matplotlib.pyplot.polar) 可生成极坐标图.

- Polar Demo + 极坐标图展示

-## Legends +## 图例(Legends) -The [``legend()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.legend.html#matplotlib.pyplot.legend) function automatically -generates figure legends, with MATLAB-compatible legend-placement -functions. +函数 [``legend()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.legend.html#matplotlib.pyplot.legend) 使用了MATLAB-compatible legend-placement自动生成图例

- Legend + 图例

-Thanks to Charles Twardy for input on the legend function. +感谢 Charles Twardy 添加 legend 函数. -## TeX-notation for text objects +## 文本对象的TeX表示法(TeX-notation for text objects) -Below is a sampling of the many TeX expressions now supported by Matplotlib's -internal mathtext engine. The mathtext module provides TeX style mathematical -expressions using [FreeType](https://www.freetype.org/) -and the DejaVu, BaKoMa computer modern, or [STIX](http://www.stixfonts.org) -fonts. See the [``matplotlib.mathtext``](https://matplotlib.org/api/mathtext_api.html#module-matplotlib.mathtext) module for additional details. +下面是Matplotlib的mathtext引擎当前支持的TeX表达式的示例。它使用了[FreeType](https://www.freetype.org/)与DejaVu, BaKoMa computer modern, 以及 [STIX](http://www.stixfonts.org),详见 [``matplotlib.mathtext``](https://matplotlib.org/api/mathtext_api.html#module-matplotlib.mathtext).

- Mathtext Examples + Mathtext示例

-Matplotlib's mathtext infrastructure is an independent implementation and -does not require TeX or any external packages installed on your computer. See -the tutorial at [Writing mathematical expressions](https://matplotlib.org//text/mathtext.html). +Matplotlib的mathtext架构的实现是独立的,不依赖于 TeX 以及其他需要安装到电脑的包. 教程详见 [Writing mathematical expressions](https://matplotlib.org//text/mathtext.html). -## Native TeX rendering +## 原生TeX渲染(Native TeX rendering) -Although Matplotlib's internal math rendering engine is quite -powerful, sometimes you need TeX. Matplotlib supports external TeX -rendering of strings with the *usetex* option. +尽管Matplotlib原生的渲染引擎已非常强大,但有时你还可能需要TeX. Matplotlib可通过 *usetex*选项支持第三方TeX字符渲染。

- Tex Demo + TeX 展示

-## EEG GUI +## 脑电图图形界面(EEG GUI) -You can embed Matplotlib into pygtk, wx, Tk, or Qt applications. -Here is a screenshot of an EEG viewer called [pbrain](https://github.com/nipy/pbrain). +你可以将Matplotlib的界面插入到pygtk, wx, Tk, Qt,PyQt中去.以下是EEG界面[pbrain](https://github.com/nipy/pbrain)的截图。 ![eeg_small](https://matplotlib.org/_images/eeg_small.png) -The lower axes uses [``specgram()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.specgram.html#matplotlib.pyplot.specgram) -to plot the spectrogram of one of the EEG channels. +最下方的图像是使用 [``specgram()``](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.specgram.html#matplotlib.pyplot.specgram) +绘制的脑电图的一个通道的频谱图。 -For examples of how to embed Matplotlib in different toolkits, see: +以下是将Matplotlib插入到不同界面的方式: - [Embedding in GTK3](https://matplotlib.org/gallery/user_interfaces/embedding_in_gtk3_sgskip.html) - [Embedding in wx #2](https://matplotlib.org/gallery/user_interfaces/embedding_in_wx2_sgskip.html) @@ -367,9 +318,9 @@ For examples of how to embed Matplotlib in different toolkits, see: - [Embedding in Qt](https://matplotlib.org/gallery/user_interfaces/embedding_in_qt_sgskip.html) - [Embedding in Tk](https://matplotlib.org/gallery/user_interfaces/embedding_in_tk_sgskip.html) -## XKCD-style sketch plots +## XKCD风格草图绘制(XKCD-style sketch plots) -Just for fun, Matplotlib supports plotting in the style of ``xkcd``. +Matplotlib 支持名为 ``xkcd``的风格,不过这图没啥用,只能用来玩玩
@@ -380,10 +331,9 @@ Just for fun, Matplotlib supports plotting in the style of ``xkcd``.

-## Subplot example +## 子图实例(Subplot example) -Many plot types can be combined in one figure to create -powerful and flexible representations of data. +可以将不同的图组合到一个图中,以创建功能强大且灵活的数据表示形式。
@@ -405,7 +355,7 @@ axs[1, 1].hist2d(data[0], data[1]) plt.show() ``` -## Download +## 下载(Download) - [Download Python source code: sample_plots.py](https://matplotlib.org/_downloads/6b0f2d1b3dc8d0e75eaa96feb738e947/sample_plots.py) - [Download Jupyter notebook: sample_plots.ipynb](https://matplotlib.org/_downloads/dcfd63fc031d50e9c085f5dc4aa458b1/sample_plots.ipynb)