Skip to content

Commit 825da1e

Browse files
committed
update web
1 parent 8e96fb9 commit 825da1e

File tree

193 files changed

+37232
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+37232
-0
lines changed

build/doctrees/environment.pickle

45.3 KB
Binary file not shown.

build/doctrees/glue_cache.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

build/doctrees/index.doctree

2.76 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

build/html/.buildinfo

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 8c8106cd161cd2ce86ae48c61840ee9f
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7

build/html/_images/index_10_0.png

8.26 KB

build/html/_images/index_10_01.png

15.2 KB

build/html/_images/index_11_0.png

5.68 KB

build/html/_images/index_12_0.png

2.31 KB

build/html/_images/index_12_01.png

4.51 KB

build/html/_images/index_12_02.png

20 KB

build/html/_images/index_13_0.png

14.6 KB

build/html/_images/index_14_0.png

5.86 KB

build/html/_images/index_14_01.png

3.71 KB

build/html/_images/index_16_0.png

2.97 KB

build/html/_images/index_16_01.png

4.18 KB

build/html/_images/index_16_02.png

9.96 KB

build/html/_images/index_17_0.png

3.86 KB

build/html/_images/index_17_01.png

10.3 KB

build/html/_images/index_18_0.png

16.7 KB

build/html/_images/index_18_1.png

15.7 KB

build/html/_images/index_19_0.png

13.6 KB

build/html/_images/index_1_0.png

5.96 KB

build/html/_images/index_20_0.png

13.5 KB

build/html/_images/index_20_01.png

24.7 KB

build/html/_images/index_21_0.png

9 KB

build/html/_images/index_21_01.png

15.3 KB

build/html/_images/index_21_02.png

9.37 KB

build/html/_images/index_23_0.png

6.95 KB

build/html/_images/index_23_01.png

25.5 KB

build/html/_images/index_25_0.png

5.76 KB

build/html/_images/index_25_01.png

10.6 KB

build/html/_images/index_27_0.png

118 KB

build/html/_images/index_27_01.png

10.6 KB

build/html/_images/index_29_0.png

14.2 KB

build/html/_images/index_29_1.png

5.84 KB

build/html/_images/index_2_0.png

10.9 KB

build/html/_images/index_2_01.png

16.5 KB

build/html/_images/index_2_02.png

23 KB

build/html/_images/index_30_0.png

10.9 KB

build/html/_images/index_31_0.png

3.2 KB

build/html/_images/index_33_0.png

3.45 KB

build/html/_images/index_35_1.png

8.56 KB

build/html/_images/index_37_0.png

5.22 KB

build/html/_images/index_39_0.png

16.8 KB

build/html/_images/index_3_0.png

14.6 KB

build/html/_images/index_3_01.png

9.49 KB

build/html/_images/index_3_02.png

16.4 KB

build/html/_images/index_4_0.png

10.9 KB

build/html/_images/index_4_01.png

4.32 KB

build/html/_images/index_4_02.png

10.1 KB

build/html/_images/index_5_0.png

60.9 KB

build/html/_images/index_5_01.png

8.22 KB

build/html/_images/index_6_0.png

15.9 KB

build/html/_images/index_7_0.png

16.8 KB

build/html/_images/index_7_01.png

8.56 KB

build/html/_images/index_8_0.png

15.9 KB

build/html/_images/index_8_01.png

9 KB

build/html/_images/index_9_0.png

11.1 KB

build/html/_images/index_9_01.png

15.5 KB

build/html/_sources/index.md.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Content
2+
3+
4+
5+
```{toctree}
6+
:maxdepth: 2
7+
8+
9+
第一回:Matplotlib初相识/index
10+
第二回:艺术画笔见乾坤/index
11+
第三回:布局格式定方圆/index
12+
第四回:文字图例尽眉目/index
13+
第五回:样式色彩秀芳华/index
14+
```
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
jupytext:
3+
text_representation:
4+
format_name: myst
5+
kernelspec:
6+
display_name: Python 3
7+
name: python3
8+
---
9+
# 第一回:Matplotlib初相识
10+
11+
12+
13+
## 一、认识matplotlib
14+
15+
Matplotlib是一个Python 2D绘图库,能够以多种硬拷贝格式和跨平台的交互式环境生成出版物质量的图形,用来绘制各种静态,动态,交互式的图表。
16+
17+
Matplotlib可用于Python脚本,Python和IPython Shell、Jupyter notebook,Web应用程序服务器和各种图形用户界面工具包等。
18+
19+
Matplotlib是Python数据可视化库中的泰斗,它已经成为python中公认的数据可视化工具,我们所熟知的pandas和seaborn的绘图接口其实也是基于matplotlib所作的高级封装。
20+
21+
为了对matplotlib有更好的理解,让我们从一些最基本的概念开始认识它,再逐渐过渡到一些高级技巧中。
22+
23+
## 二、一个最简单的绘图例子
24+
25+
Matplotlib的图像是画在figure(如windows,jupyter窗体)上的,每一个figure又包含了一个或多个axes(一个可以指定坐标系的子区域)。最简单的创建figure以及axes的方式是通过`pyplot.subplots`命令,创建axes以后,可以使用`Axes.plot`绘制最简易的折线图。
26+
27+
28+
```{code-cell} ipython3
29+
import matplotlib.pyplot as plt
30+
import numpy as np
31+
```
32+
33+
34+
```{code-cell} ipython3
35+
fig, ax = plt.subplots() # 创建一个包含一个axes的figure
36+
ax.plot([1, 2, 3, 4], [1, 4, 2, 3]); # 绘制图像
37+
```
38+
39+
**Trick**:
40+
在jupyter notebook中使用matplotlib时会发现,代码运行后自动打印出类似`<matplotlib.lines.Line2D at 0x23155916dc0>`这样一段话,这是因为matplotlib的绘图代码默认打印出最后一个对象。如果不想显示这句话,有以下三种方法,在本章节的代码示例中你能找到这三种方法的使用。
41+
42+
1. 在代码块最后加一个分号`;`
43+
2. 在代码块最后加一句plt.show()
44+
3. 在绘图时将绘图对象显式赋值给一个变量,如将plt.plot([1, 2, 3, 4]) 改成line =plt.plot([1, 2, 3, 4])
45+
46+
47+
48+
和MATLAB命令类似,你还可以通过一种更简单的方式绘制图像,`matplotlib.pyplot`方法能够直接在当前axes上绘制图像,如果用户未指定axes,matplotlib会帮你自动创建一个。所以上面的例子也可以简化为以下这一行代码。
49+
50+
51+
```{code-cell} ipython3
52+
line =plt.plot([1, 2, 3, 4], [1, 4, 2, 3])
53+
```
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
## 三、Figure的组成
64+
65+
现在我们来深入看一下figure的组成。通过一张figure解剖图,我们可以看到一个完整的matplotlib图像通常会包括以下四个层级,这些层级也被称为容器(container),下一节会详细介绍。在matplotlib的世界中,我们将通过各种命令方法来操纵图像中的每一个部分,从而达到数据可视化的最终效果,一副完整的图像实际上是各类子元素的集合。
66+
67+
- `Figure`:顶层级,用来容纳所有绘图元素
68+
69+
- `Axes`:matplotlib宇宙的核心,容纳了大量元素用来构造一幅幅子图,一个figure可以由一个或多个子图组成
70+
71+
- `Axis`:axes的下属层级,用于处理所有和坐标轴,网格有关的元素
72+
73+
- `Tick`:axis的下属层级,用来处理所有和刻度有关的元素
74+
75+
![](https://matplotlib.org/_images/anatomy.png)
76+
77+
## 四、两种绘图接口
78+
79+
matplotlib提供了两种最常用的绘图接口
80+
81+
1. 显式创建figure和axes,在上面调用绘图方法,也被称为OO模式(object-oriented style)
82+
83+
2. 依赖pyplot自动创建figure和axes,并绘图
84+
85+
使用第一种绘图接口,是这样的:
86+
87+
88+
```{code-cell} ipython3
89+
x = np.linspace(0, 2, 100)
90+
91+
fig, ax = plt.subplots()
92+
ax.plot(x, x, label='linear')
93+
ax.plot(x, x**2, label='quadratic')
94+
ax.plot(x, x**3, label='cubic')
95+
ax.set_xlabel('x label')
96+
ax.set_ylabel('y label')
97+
ax.set_title("Simple Plot")
98+
ax.legend()
99+
plt.show()
100+
```
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
而如果采用第二种绘图接口,绘制同样的图,代码是这样的:
113+
114+
115+
```{code-cell} ipython3
116+
x = np.linspace(0, 2, 100)
117+
118+
plt.plot(x, x, label='linear')
119+
plt.plot(x, x**2, label='quadratic')
120+
plt.plot(x, x**3, label='cubic')
121+
plt.xlabel('x label')
122+
plt.ylabel('y label')
123+
plt.title("Simple Plot")
124+
plt.legend()
125+
plt.show()
126+
```
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+
## 参考资料
139+
140+
[1.matplotlib官网用户指南](https://matplotlib.org/stable/tutorials/introductory/usage.html)
141+

0 commit comments

Comments
 (0)