Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_48998305
TRHX-github-io
提交
4e6b8dad
T
TRHX-github-io
项目概览
weixin_48998305
/
TRHX-github-io
与 Fork 源项目一致
Fork自
IT.BOB / TRHX-github-io
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TRHX-github-io
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4e6b8dad
编写于
8月 06, 2020
作者:
T
TRHX
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Back up my www.itrhx.com blog
上级
db4ed43e
变更
22
隐藏空白更改
内联
并排
Showing
22 changed file
with
428 addition
and
89 deletion
+428
-89
source/_posts/A60-2019-summary.md
source/_posts/A60-2019-summary.md
+0
-1
source/_posts/A62-NumPy-01.md
source/_posts/A62-NumPy-01.md
+12
-2
source/_posts/A63-NumPy-02.md
source/_posts/A63-NumPy-02.md
+6
-0
source/_posts/A64-NumPy-03.md
source/_posts/A64-NumPy-03.md
+6
-0
source/_posts/A68-Matplotlib-01.md
source/_posts/A68-Matplotlib-01.md
+6
-0
source/_posts/A69-Matplotlib-02.md
source/_posts/A69-Matplotlib-02.md
+24
-2
source/_posts/A70-Matplotlib-03.md
source/_posts/A70-Matplotlib-03.md
+20
-1
source/_posts/A71-Matplotlib-04.md
source/_posts/A71-Matplotlib-04.md
+18
-2
source/_posts/A72-Matplotlib-05.md
source/_posts/A72-Matplotlib-05.md
+20
-1
source/_posts/A73-Matplotlib-06.md
source/_posts/A73-Matplotlib-06.md
+30
-0
source/_posts/A74-Matplotlib-07.md
source/_posts/A74-Matplotlib-07.md
+14
-0
source/_posts/A75-Matplotlib-08.md
source/_posts/A75-Matplotlib-08.md
+16
-2
source/_posts/A76-Matplotlib-09.md
source/_posts/A76-Matplotlib-09.md
+20
-0
source/_posts/A77-Matplotlib-10.md
source/_posts/A77-Matplotlib-10.md
+30
-0
source/_posts/A78-Matplotlib-11.md
source/_posts/A78-Matplotlib-11.md
+116
-6
source/_posts/A79-Pandas-01.md
source/_posts/A79-Pandas-01.md
+4
-0
source/_posts/A84-Pandas-06.md
source/_posts/A84-Pandas-06.md
+2
-0
source/_posts/A88-Pandas-10.md
source/_posts/A88-Pandas-10.md
+30
-2
source/_posts/A89-COVID-19.md
source/_posts/A89-COVID-19.md
+14
-0
source/_posts/A90-pyspider-51job.md
source/_posts/A90-pyspider-51job.md
+21
-1
source/friends/index.md
source/friends/index.md
+18
-68
themes/material-x-1.2.1/layout/_partial/scripts.ejs
themes/material-x-1.2.1/layout/_partial/scripts.ejs
+1
-1
未找到文件。
source/_posts/A60-2019-summary.md
浏览文件 @
4e6b8dad
...
...
@@ -9,7 +9,6 @@ music:
type
:
song
id
:
413829859
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/CDN-for-itrhx.com@3.0.4/images/trhx.png
top
:
true
---
<fancybox>
...
...
source/_posts/A62-NumPy-01.md
浏览文件 @
4e6b8dad
...
...
@@ -69,7 +69,9 @@ Python 列表的元素不同类型举例:
Python 列表中的每一项必须包含各自的类型信息、引用计数和其他信息,也就是说,每一项都是一个完整的 Python 对象,同时,Python 列表还包含一个指向指针块的指针,其中的每一个指针对应一个完整的 Python 对象,另外,列表的优势是灵活,因为每个列表元素是一个包含数据和类型信息的完整结构体。相反 NumPy 数组缺乏这种灵活性,但是 NumPy 却能更有效地存储和操作数据。
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A62/01.png
)
</fancybox>
## <font color=#ff0000>【3x00】理解 NumPy Ndarray 对象</font>
...
...
@@ -82,7 +84,9 @@ Ndarray 内部由以下内容组成:
-
一个表示数组形状(shape)的元组,表示各维度大小的元组;
-
一个跨度元组(stride),其中的整数指的是为了前进到当前维度下一个元素需要“跨过”的字节数。
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A62/02.png
)
</fancybox>
## <font color=#FF0000>【4x00】理解不同维度的数组</font>
...
...
@@ -103,7 +107,9 @@ NumPy 数组的维数称为秩(rank),秩就是轴的数量,即数组的
(
4
,)
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A62/03.png
)
</fancybox>
---
...
...
@@ -122,7 +128,9 @@ NumPy 数组的维数称为秩(rank),秩就是轴的数量,即数组的
> a.shape 输出数组的维度,对于此二维数组,可以理解为 2 行 4 列。
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A62/04.png
)
</fancybox>
---
...
...
@@ -147,11 +155,15 @@ NumPy 数组的维数称为秩(rank),秩就是轴的数量,即数组的
> a.shape 输出数组的维度,对于此三维数组,可以理解为 3 块,每块有 2 行 4 列。
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A62/05.png
)
</fancybox>
有网友对三维数组的这个图有疑问,认为横线应该是 axis=0,竖线是 axis=1,斜线是 axis=2,这个确实有点儿绕,不要受到前面一维二维的影响,我把我的理解又画了一张图出来,另外大家可以尝试去取三维数组里面的某个值,多想一下就可以理解了。欢迎各位大佬一起交流学习!
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A62/06.png
)
</fancybox>
## <font color=#FF0000>【5x00】创建 Ndarray 对象(创建数组)</font>
...
...
@@ -487,8 +499,6 @@ numpy.logspace() 方法用于创建一个一维数组,该数组由一个等比
[
1
2
4
8
16
32
64
128
256
512
]
```
### <font color=#1BC3FB>【5x07】numpy.empty()</font>
numpy.empty() 方法可用来创建一个指定形状(shape)、数据类型(dtype)且未初始化的数组。
...
...
source/_posts/A63-NumPy-02.md
浏览文件 @
4e6b8dad
...
...
@@ -586,7 +586,9 @@ ValueError: operands could not be broadcast together with shapes (3,4,5) (4,2)
[
30
31
32
]]
```
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A63/01.png
)
</fancybox>
实例二:一个
<font
color=
#ff0000
>
**4 行 3 列**
</font>
的二维数组与一个
<font
color=
#ff0000
>
**4 行 1 列**
</font>
的二维数组相加,此时就会触发广播机制,代码与图解如下:
...
...
@@ -611,7 +613,9 @@ ValueError: operands could not be broadcast together with shapes (3,4,5) (4,2)
[
14
15
16
]]
```
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A63/02.png
)
</fancybox>
实例三:一个
<font
color=
#ff0000
>
**3 块 4 行 2 列,即 shape=(3, 4, 2)**
</font>
的三维数组与一个
<font
color=
#ff0000
>
**1 块 4 行 2 列,即 shape=(1, 4, 2)**
</font>
的三维数组相加,此时就会触发广播机制,代码与图解如下:
...
...
@@ -660,7 +664,9 @@ ValueError: operands could not be broadcast together with shapes (3,4,5) (4,2)
[
30
32
]]]
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A63/03.png
)
</fancybox>
---
...
...
source/_posts/A64-NumPy-03.md
浏览文件 @
4e6b8dad
...
...
@@ -253,7 +253,9 @@ True
False
```
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A64/01.png
)
</fancybox>
```
python
>>>
import
numpy
as
np
...
...
@@ -278,7 +280,9 @@ True
False
```
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A64/02.png
)
</fancybox>
```
python
>>>
import
numpy
as
np
...
...
@@ -303,7 +307,9 @@ True
False
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A64/03.png
)
</fancybox>
### <font color=#1BC3FB>【1x06】广播数组迭代</font>
...
...
source/_posts/A68-Matplotlib-01.md
浏览文件 @
4e6b8dad
...
...
@@ -60,11 +60,15 @@ Matplotlib 是建立在 NumPy 数组基础上的多平台数据可视化程序
>>>
plt
.
show
()
```
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A68/01.png
)
</fancybox>
### <font color=#1BC3FB>【1x02】图像结构</font>
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A68/02.png
)
</fancybox>
### <font color=#1BC3FB>【1x03】三层结构</font>
...
...
@@ -164,7 +168,9 @@ plt.legend(['图例一', '图例二'])
plt
.
show
()
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A68/03.png
)
</fancybox>
---
...
...
source/_posts/A69-Matplotlib-02.md
浏览文件 @
4e6b8dad
...
...
@@ -73,7 +73,9 @@ plt.plot(x, y)
plt
.
show
()
```
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/01.png
)
</fancybox>
### <font color=#1BC3FB>【1x02】为坐标轴添加标签:matplotlib.pyplot.xlabel() / ylabel()</font>
...
...
@@ -110,7 +112,9 @@ plt.plot(a, b)
plt
.
show
()
```
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/02.png
)
</fancybox>
### <font color=#1BC3FB>【1x03】任意位置添加文本:matplotlib.pyplot.text()</font>
...
...
@@ -152,7 +156,9 @@ plt.plot(a, b)
plt
.
show
()
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/03.png
)
</fancybox>
### <font color=#1BC3FB>【1x03】任意位置添加文本:matplotlib.pyplot.annotate()</font>
...
...
@@ -243,7 +249,9 @@ plt.show()
<table><tr><td
bgcolor=
"#7FFFD4"
colspan=
"2"
><strong><font
color=
#FF0000
size=
3px
>
connectionstyle 样式举例
</font></strong></td></tr></table>
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/04.png
)
</fancybox>
应用举例:
...
...
@@ -270,7 +278,9 @@ plt.annotate(r'$\lim_{x\to 0}\frac{\sin(x)}{x}=1$', # 插入 LaTeX 表达式
plt
.
show
()
```
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/05.png
)
</fancybox>
---
...
...
@@ -364,8 +374,9 @@ plt.plot(a, b)
plt
.
show
()
```
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/06.png
)
</fancybox>
### <font color=#1BC3FB>【2x03】指定单个字体:fontproperties</font>
...
...
@@ -389,14 +400,17 @@ plt.plot(a, b)
plt
.
show
()
```
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/07.png
)
</fancybox>
### <font color=#1BC3FB>【2x04】指定文字路径:FontProperties</font>
`matplotlib`
中
`font_manager`
模块的
`FontProperties`
方法可以通过指定文字路径来使用本地文字,在 Windows 中,文字路径一般是
`C:\Windows\Fonts\`,文字名称可以通过其属性来获取,部分用户自己安装的字体可能包含多个类型,可打开字体合集后通过其属性来获取。
<fancybox>
![08](https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/08.png)
</fancybox>
```python
import matplotlib.pyplot as plt
...
...
@@ -414,7 +428,9 @@ plt.plot(a, b)
plt.show()
```
<fancybox>
![09](https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/09.png)
</fancybox>
### <font color=#1BC3FB>【2x05】文字更多属性:rc</font>
...
...
@@ -444,7 +460,9 @@ plt.plot(a, b)
plt.show()
```
<fancybox>
![10](https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/10.png)
</fancybox>
## <font color=#FF0000>【3x00】设置画布大小 / 分辨率 / 颜色</font>
...
...
@@ -475,7 +493,9 @@ plt.plot(x, y)
plt.show()
```
<fancybox>
![11](https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/11.png)
</fancybox>
## <font color=#FF0000>【4x00】设置网格</font>
...
...
@@ -518,7 +538,9 @@ plt.plot(a, b)
plt.show()
```
<fancybox>
![12](https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A69/12.png)
</fancybox>
---
...
...
source/_posts/A70-Matplotlib-03.md
浏览文件 @
4e6b8dad
...
...
@@ -156,7 +156,9 @@ plt.show()
以上三种方法绘制的图形均一致:
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A70/01.png
)
</fancybox>
## <font color=#FF0000>【2x00】数学公式 LaTeX</font>
...
...
@@ -181,7 +183,9 @@ plt.plot(t, s)
plt
.
show
()
```
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A70/02.png
)
</fancybox>
## <font color=#FF0000>【3x00】调整 x / y 轴刻度和范围</font>
...
...
@@ -215,8 +219,9 @@ plt.xticks(range(2, 26, 3), ('the {} ticks'.format(i) for i in range(2, 26, 3)),
plt
.
show
()
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A70/03.png
)
</fancybox>
```
python
import
matplotlib.pyplot
as
plt
...
...
@@ -231,7 +236,9 @@ plt.plot(x, y)
plt
.
show
()
```
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A70/04.png
)
</fancybox>
## <font color=#FF0000>【4x00】画布边框与坐标轴的移动</font>
...
...
@@ -273,7 +280,9 @@ ax.spines['left'].set_position(('data', 0)) # 设置 y 轴在 (0, 0) 位置
plt
.
show
()
```
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A70/05.png
)
</fancybox>
---
...
...
@@ -320,7 +329,9 @@ ax4.plot(-x, x ** 2)
plt
.
show
()
```
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A70/06.png
)
</fancybox>
### <font color=#1BC3FB>【5x02】方法二:pyplot.subplot()</font>
...
...
@@ -349,7 +360,9 @@ plt.plot(x, x ** 4)
plt
.
show
()
```
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A70/07.png
)
</fancybox>
### <font color=#1BC3FB>【5x03】方法三:pyplot.subplots()</font>
...
...
@@ -372,7 +385,9 @@ axes[1][1].plot(x, -x ** 2) # 绘制第2行第2列
plt
.
show
()
```
<fancybox>
![
08
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A70/08.png
)
</fancybox>
## <font color=#FF0000>【6x00】填充补丁</font>
...
...
@@ -437,7 +452,9 @@ plt.plot(x, y)
plt
.
show
()
```
<fancybox>
![
09
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A70/09.png
)
</fancybox>
## <font color=#FF0000>【7x00】保存图像</font>
...
...
@@ -475,7 +492,9 @@ plt.savefig('D:\\data\\pic.png', transparent=True) # 保存为透明文件
plt
.
show
()
```
<fancybox>
![
10
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A70/10.png
)
</fancybox>
---
...
...
source/_posts/A71-Matplotlib-04.md
浏览文件 @
4e6b8dad
...
...
@@ -158,8 +158,10 @@ plt.ylabel('y 轴') # 设置 y 轴标签
plt
.
plot
(
x
,
y
)
plt
.
show
()
```
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A71/01.png
)
</fancybox>
## <font color=#FF0000>【3x00】多条数据</font>
...
...
@@ -186,7 +188,9 @@ plt.plot(x, y3)
plt
.
show
()
```
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A71/02.png
)
</fancybox>
## <font color=#FF0000>【4x00】设置颜色 / 样式 / 图例</font>
...
...
@@ -217,7 +221,9 @@ plt.legend(edgecolor='#87A3CC', facecolor='#F5F5F5') # 图例
plt
.
show
()
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A71/03.png
)
</fancybox>
---
...
...
@@ -260,7 +266,9 @@ plt.yticks((-1, 0, 1, 2, 3))
plt
.
show
()
```
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A71/04.png
)
</fancybox>
## <font color=#FF0000>【6x00】隐藏画布边框</font>
...
...
@@ -303,7 +311,9 @@ ax.spines['top'].set_visible(False) # 获取绘图区的轴对象(spines
plt
.
show
()
```
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A71/05.png
)
</fancybox>
## <font color=#FF0000>【7x00】移动坐标轴</font>
...
...
@@ -343,8 +353,10 @@ ax.yaxis.set_ticks_position('left') # 设置 y 坐标轴标签的位
plt
.
show
()
```
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A71/06.png
)
</fancybox>
## <font color=#FF0000>【8x00】指定位置显示文本</font>
`matplotlib.pyplot.annotate()`
方法可以在指定坐标点添加文本或 LaTeX 描述,也可以在其他位置添加描述后,使用箭头指向某个坐标点。
...
...
@@ -434,7 +446,9 @@ plt.show()
<table><tr><td
bgcolor=
"#7FFFD4"
colspan=
"2"
><strong><font
color=
#FF0000
size=
3px
>
connectionstyle 样式举例
</font></strong></td></tr></table>
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A71/07.png
)
</fancybox>
应用举例:
...
...
@@ -482,7 +496,9 @@ plt.annotate(r'$\lim_{x\to 0}\frac{\sin(x)}{x}=1$', # 插入 LaTeX 表达式
plt
.
show
()
```
<fancybox>
![
08
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A71/08.png
)
</fancybox>
---
...
...
source/_posts/A72-Matplotlib-05.md
浏览文件 @
4e6b8dad
...
...
@@ -124,7 +124,9 @@ plt.scatter(x, y)
plt
.
show
()
```
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A72/01.png
)
</fancybox>
## <font color=#FF0000>【3x00】多条数据</font>
...
...
@@ -151,7 +153,9 @@ plt.scatter(x, y3)
plt
.
show
()
```
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A72/02.png
)
</fancybox>
## <font color=#FF0000>【4x00】设置颜色 / 样式 / 图例</font>
...
...
@@ -178,7 +182,9 @@ plt.legend(framealpha=0) # 显示图例,设置为全透明
plt
.
show
()
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A72/03.png
)
</fancybox>
## <font color=#FF0000>【5x00】指定位置显示文本注释</font>
...
...
@@ -213,7 +219,9 @@ for m, n in zip(x, y):
plt
.
show
()
```
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A72/04.png
)
</fancybox>
---
...
...
@@ -257,8 +265,9 @@ plt.scatter(x, y, alpha=0.5)
plt
.
show
()
```
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A72/05.png
)
</fancybox>
## <font color=#FF0000>【7x00】随机颜色与色条</font>
...
...
@@ -284,7 +293,9 @@ plt.scatter(x, y, c=color, s=size, alpha=0.5)
plt
.
show
()
```
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A72/06.png
)
</fancybox>
可以用
`pyplot.colorbar()`
方法绘制颜色对照条。
...
...
@@ -322,7 +333,9 @@ plt.colorbar()
plt
.
show
()
```
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A72/07.png
)
</fancybox>
## <font color=#FF0000>【8x00】不同图像之间的层级调整</font>
...
...
@@ -352,7 +365,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
08
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A72/08.png
)
</fancybox>
设置
`zorder`
参数后:
...
...
@@ -378,7 +393,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
09
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A72/09.png
)
</fancybox>
## <font color=#FF0000>【9x00】框选部分数据</font>
...
...
@@ -419,7 +436,9 @@ ax.add_patch(polygon) # 将补丁添加到当前绘图区
plt
.
show
()
```
<fancybox>
![
10
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A72/10.png
)
</fancybox>
---
...
...
source/_posts/A73-Matplotlib-06.md
浏览文件 @
4e6b8dad
...
...
@@ -117,7 +117,9 @@ plt.ylabel('y axis label') # y 轴标签
plt
.
show
()
```
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/01.png
)
</fancybox>
### <font color=##4876FF>【2x03】堆积的直方图</font>
...
...
@@ -146,7 +148,9 @@ plt.legend(loc="upper left")
plt
.
show
()
```
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/02.png
)
</fancybox>
### <font color=##4876FF>【2x04】填充其他样式</font>
...
...
@@ -171,7 +175,9 @@ plt.ylabel('y axis label') # y 轴标签
plt
.
show
()
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/03.png
)
</fancybox>
![
分割线
](
https://img-blog.csdnimg.cn/20200509010455973.png
)
...
...
@@ -236,7 +242,9 @@ plt.ylabel('y axis label')
plt
.
show
()
```
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/04.png
)
</fancybox>
### <font color=##4876FF>【3x03】添加与标准差的误差线</font>
...
...
@@ -276,7 +284,9 @@ plt.ylabel('y axis label')
plt
.
show
()
```
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/05.png
)
</fancybox>
### <font color=##4876FF>【3x04】多序列柱状图</font>
...
...
@@ -310,7 +320,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/06.png
)
</fancybox>
### <font color=##4876FF>【3x05】堆积的柱状图</font>
...
...
@@ -340,7 +352,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/07.png
)
</fancybox>
### <font color=##4876FF>【3x06】填充其他样式</font>
...
...
@@ -370,7 +384,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
08
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/08.png
)
</fancybox>
### <font color=##4876FF>【3x07】添加文字描述</font>
...
...
@@ -411,7 +427,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
09
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/09.png
)
</fancybox>
![
分割线
](
https://img-blog.csdnimg.cn/20200509010455973.png
)
...
...
@@ -483,7 +501,9 @@ plt.ylabel('y axis label')
plt
.
show
()
```
<fancybox>
![
10
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/10.png
)
</fancybox>
### <font color=##4876FF>【4x03】添加与标准差的误差线</font>
...
...
@@ -523,7 +543,9 @@ plt.ylabel('y axis label')
plt
.
show
()
```
<fancybox>
![
11
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/11.png
)
</fancybox>
### <font color=##4876FF>【4x04】多序列条形图</font>
...
...
@@ -557,7 +579,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
12
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/12.png
)
</fancybox>
### <font color=##4876FF>【4x05】堆积的条形图</font>
...
...
@@ -587,7 +611,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
13
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/13.png
)
</fancybox>
### <font color=##4876FF>【4x06】填充其他样式</font>
...
...
@@ -617,7 +643,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
14
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/14.png
)
</fancybox>
### <font color=##4876FF>【4x07】添加文字描述</font>
...
...
@@ -658,7 +686,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
15
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A73/15.png
)
</fancybox>
---
...
...
source/_posts/A74-Matplotlib-07.md
浏览文件 @
4e6b8dad
...
...
@@ -98,7 +98,9 @@ plt.title('饼状图简单示例')
plt
.
show
()
```
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A74/01.png
)
</fancybox>
## <font color=#FF0000>【3x00】按角度调整扇形标签</font>
...
...
@@ -120,7 +122,9 @@ plt.title('饼状图按角度调整 labels 示例')
plt
.
show
()
```
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A74/02.png
)
</fancybox>
## <font color=#FF0000>【4x00】显示图例</font>
...
...
@@ -142,7 +146,9 @@ plt.legend(bbox_to_anchor=(1, 1))
plt
.
show
()
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A74/03.png
)
</fancybox>
---
...
...
@@ -177,7 +183,9 @@ plt.legend(bbox_to_anchor=(1, 1))
plt
.
show
()
```
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A74/04.png
)
</fancybox>
## <font color=#FF0000>【6x00】显示各扇区所占百分比</font>
...
...
@@ -207,7 +215,9 @@ plt.legend(bbox_to_anchor=(1, 1)) # 显示图例
plt
.
show
()
```
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A74/05.png
)
</fancybox>
## <font color=#FF0000>【7x00】旋转饼状图</font>
...
...
@@ -238,7 +248,9 @@ plt.legend(bbox_to_anchor=(1, 1)) # 显示图例
plt
.
show
()
```
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A74/06.png
)
</fancybox>
## <font color=#FF0000>【8x00】自定义每个扇形和文字属性</font>
...
...
@@ -281,7 +293,9 @@ plt.legend(bbox_to_anchor=(1, 1), borderpad=0.6) # 显示图例
plt
.
show
()
```
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A74/07.png
)
</fancybox>
---
...
...
source/_posts/A75-Matplotlib-08.md
浏览文件 @
4e6b8dad
...
...
@@ -58,11 +58,13 @@ Matplotlib 系列文章:
<font
color=
#FF0000
>
**在 Matplotlib 等高线的绘制中,需要传递三个基本参数:某个点的 x、y 轴坐标以及其高度。**
</font>
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A75/01.png
)
</fancybox>
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A75/02.png
)
</fancybox>
## <font color=#FF0000>【2x00】理解 numpy.meshgrid()</font>
...
...
@@ -190,7 +192,9 @@ print(res)
官方文档:
[
https://matplotlib.org/tutorials/colors/colormaps.html
](
https://matplotlib.org/tutorials/colors/colormaps.html
)
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A75/03.png
)
</fancybox>
![
分割线
](
https://img-blog.csdnimg.cn/20200512112427932.png
)
...
...
@@ -221,7 +225,9 @@ plt.ylabel('y axis label')
plt
.
show
()
```
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A75/04.png
)
</fancybox>
![
分割线
](
https://img-blog.csdnimg.cn/20200512112427932.png
)
...
...
@@ -256,7 +262,9 @@ plt.ylabel('y axis label')
plt
.
show
()
```
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A75/05.png
)
</fancybox>
![
分割线
](
https://img-blog.csdnimg.cn/20200512112427932.png
)
...
...
@@ -292,7 +300,9 @@ plt.ylabel('y axis label')
plt
.
show
()
```
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A75/06.png
)
</fancybox>
如果想启用渐变色,则可以设置
`cmap`
,取值参见
<font
color=
#FF0000
>
**【6x00】Colormap 取值**
</font>
,
`colorbar()`
方法可以显示颜色对照条。
...
...
@@ -325,7 +335,9 @@ plt.ylabel('y axis label')
plt
.
show
()
```
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A75/07.png
)
</fancybox>
![
分割线
](
https://img-blog.csdnimg.cn/20200512112427932.png
)
...
...
@@ -363,7 +375,9 @@ plt.ylabel('y axis label')
plt
.
show
()
```
<fancybox>
![
08
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A75/08.png
)
</fancybox>
---
...
...
source/_posts/A76-Matplotlib-09.md
浏览文件 @
4e6b8dad
...
...
@@ -51,7 +51,9 @@ Matplotlib 系列文章:
参考百度百科:极坐标,属于二维坐标系统,创始人是牛顿,主要应用于数学领域。极坐标是指在平面内取一个定点
<font
color=
#FF0000
>
O
</font>
,叫极点,引一条射线
<font
color=
#FF0000
>
Ox
</font>
,叫做极轴,再选定一个长度单位和角度的正方向(通常取逆时针方向)。对于平面内任何一点
<font
color=
#FF0000
>
M
</font>
,用
<font
color=
#FF0000
>
ρ
</font>
表示线段
<font
color=
#FF0000
>
OM
</font>
的长度(有时也用
<font
color=
#FF0000
>
r
</font>
表示),
<font
color=
#FF0000
>
θ
</font>
表示从
<font
color=
#FF0000
>
Ox
</font>
到
<font
color=
#FF0000
>
OM
</font>
的角度,
<font
color=
#FF0000
>
ρ
</font>
叫做点
<font
color=
#FF0000
>
M
</font>
的极径,
<font
color=
#FF0000
>
θ
</font>
叫做点
<font
color=
#FF0000
>
M
</font>
的极角,有序数对
<font
color=
#FF0000
>
(ρ,θ)
</font>
就叫点
<font
color=
#FF0000
>
M
</font>
的极坐标,这样建立的坐标系叫做极坐标系。通常情况下,
<font
color=
#FF0000
>
M
</font>
的极径坐标单位为
<font
color=
#FF0000
>
1
</font>
(长度单位),极角坐标单位为
<font
color=
#FF0000
>
rad
</font>
(或
<font
color=
#FF0000
>
°
</font>
)。
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A76/01.png
)
</fancybox>
## <font color=#FF0000>【2x00】基本方法 matplotlib.pyplot.polar()</font>
...
...
@@ -172,7 +174,9 @@ plt.show()
绘制结果如下图:
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A76/02.png
)
</fancybox>
## <font color=#FF0000>【4x00】绘制雷达图</font>
...
...
@@ -258,7 +262,9 @@ plt.title('matplotlib.pyplot.thetagrids() 用法示例', pad=15)
plt
.
show
()
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A76/03.png
)
</fancybox>
---
...
...
@@ -301,7 +307,9 @@ plt.legend(bbox_to_anchor=(1.3, 1))
plt
.
show
()
```
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A76/04.png
)
</fancybox>
---
...
...
@@ -354,7 +362,9 @@ plt.title('极坐标散点图示例一', pad=15)
plt
.
show
()
```
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A76/05.png
)
</fancybox>
---
...
...
@@ -386,7 +396,9 @@ plt.title('极坐标散点图示例二', pad=15)
plt
.
show
()
```
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A76/06.png
)
</fancybox>
---
...
...
@@ -418,7 +430,9 @@ plt.title('极坐标散点图示例三', pad=15)
plt
.
show
()
```
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A76/07.png
)
</fancybox>
## <font color=#FF0000>【6x00】高级用法:绘制极坐标柱状图</font>
...
...
@@ -457,7 +471,9 @@ plt.title('极坐标柱状图示例一', pad=15)
plt
.
show
()
```
<fancybox>
![
08
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A76/08.png
)
</fancybox>
---
...
...
@@ -486,7 +502,9 @@ plt.title('极坐标柱状图示例二', pad=15)
plt
.
show
()
```
<fancybox>
![
09
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A76/09.png
)
</fancybox>
---
...
...
@@ -516,7 +534,9 @@ plt.title('极坐标柱状图示例三', pad=15)
plt
.
show
()
```
<fancybox>
![
10
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A76/10.png
)
</fancybox>
---
...
...
source/_posts/A77-Matplotlib-10.md
浏览文件 @
4e6b8dad
...
...
@@ -147,7 +147,9 @@ plt.show()
以上三种方法运行结果均为下图:
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/01.png
)
</fancybox>
## <font color=#FF0000>【02x00】cmap 与 colorbar</font>
...
...
@@ -155,7 +157,9 @@ plt.show()
官方文档:
[
https://matplotlib.org/tutorials/colors/colormaps.html
](
https://matplotlib.org/tutorials/colors/colormaps.html
)
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/02.png
)
</fancybox>
如果使用了 cmap 参数,则可以使用
`pyplot.colorbar()`
函数来绘制一个色条,即颜色对照条。
...
...
@@ -219,7 +223,9 @@ ax.legend()
plt
.
show
()
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/03.png
)
</fancybox>
## <font color=#FF0000>【04x00】3D 散点图:Axes3D.scatter</font>
...
...
@@ -271,7 +277,9 @@ ax.set_zlabel('z 轴', color='b')
plt
.
show
()
```
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/04.png
)
</fancybox>
## <font color=#FF0000>【05x00】3D 线框图:Axes3D.plot_wireframe</font>
...
...
@@ -319,7 +327,9 @@ ax.set_zlabel('z 轴')
plt
.
show
()
```
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/05.png
)
</fancybox>
## <font color=#FF0000>【06x00】3D 曲面图:Axes3D.plot_surface</font>
...
...
@@ -368,7 +378,9 @@ ax.set_zlim(-2, 2)
plt
.
show
()
```
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/06.png
)
</fancybox>
---
...
...
@@ -424,7 +436,9 @@ ax.set_yticks(yticks)
plt
.
show
()
```
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/07.png
)
</fancybox>
## <font color=#FF0000>【08x00】3D 箭头图:Axes3D.quiver</font>
...
...
@@ -475,7 +489,9 @@ ax.view_init(20)
plt
.
show
()
```
<fancybox>
![
08
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/08.png
)
</fancybox>
## <font color=#FF0000>【09x00】3D 等高线图:Axes3D.contour</font>
...
...
@@ -527,7 +543,9 @@ ax.set_zlabel('z 轴')
plt
.
show
()
```
<fancybox>
![
09
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/09.png
)
</fancybox>
## <font color=#FF0000>【10x00】3D 等高线填充图:Axes3D.contourf</font>
...
...
@@ -577,7 +595,9 @@ ax.set_zlabel('z 轴')
plt
.
show
()
```
<fancybox>
![
10
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/10.png
)
</fancybox>
## <font color=#FF0000>【11x00】3D 三角曲面图:Axes3D.plot_trisurf</font>
...
...
@@ -624,7 +644,9 @@ ax.set_zlabel('z 轴')
plt
.
show
()
```
<fancybox>
![
11
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/11.png
)
</fancybox>
```
python
import
numpy
as
np
...
...
@@ -693,7 +715,9 @@ ax.set_zlabel('z 轴')
plt
.
show
()
```
<fancybox>
![
12
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/12.png
)
</fancybox>
## <font color=#FF0000>【12x00】将 2D 图像聚合到 3D 图像中:Axes3D.add_collection3d</font>
...
...
@@ -741,7 +765,9 @@ ax.set_zlim3d(0, 300)
plt
.
show
()
```
<fancybox>
![
13
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/13.png
)
</fancybox>
此外,该方法也常被用于绘制 3D 多边形图,即多边体,示例如下:
...
...
@@ -780,7 +806,9 @@ ax.set_zlim3d(-0.5, 1.5)
plt
.
show
()
```
<fancybox>
![
14
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/14.png
)
</fancybox>
## <font color=#FF0000>【13x00】3D 图添加文本描述:Axes3D.text</font>
...
...
@@ -829,7 +857,9 @@ ax.set_zlabel('Z 轴')
plt
.
show
()
```
<fancybox>
![
15
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A77/15.png
)
</fancybox>
---
...
...
source/_posts/A78-Matplotlib-11.md
浏览文件 @
4e6b8dad
...
...
@@ -126,8 +126,8 @@ colors = [plt.cm.tab10(i/float(len(categories)-1)) for i in range(len(categories
plt
.
figure
(
figsize
=
(
16
,
10
),
dpi
=
80
,
facecolor
=
'w'
,
edgecolor
=
'k'
)
for
i
,
category
in
enumerate
(
categories
):
plt
.
scatter
(
'area'
,
'poptotal'
,
data
=
midwest
.
loc
[
midwest
.
category
==
category
,
:],
plt
.
scatter
(
'area'
,
'poptotal'
,
data
=
midwest
.
loc
[
midwest
.
category
==
category
,
:],
s
=
20
,
cmap
=
colors
[
i
],
label
=
str
(
category
))
# 原文 c=colors[i] 已修改为 cmap=colors[i]
...
...
@@ -137,11 +137,13 @@ plt.gca().set(xlim=(0.0, 0.1), ylim=(0, 90000),
plt
.
xticks
(
fontsize
=
12
);
plt
.
yticks
(
fontsize
=
12
)
plt
.
title
(
"Scatterplot of Midwest Area vs Population"
,
fontsize
=
22
)
plt
.
legend
(
fontsize
=
12
)
plt
.
show
()
plt
.
legend
(
fontsize
=
12
)
plt
.
show
()
```
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/01.png
)
</fancybox>
### <font color=##4876FF>【02】带边界的气泡图(Bubble plot with Encircling)</font>
...
...
@@ -193,7 +195,9 @@ plt.legend(fontsize=12)
plt
.
show
()
```
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/02.png
)
</fancybox>
### <font color=##4876FF>【03】带线性回归最佳拟合线的散点图(Scatter plot with linear regression line of best fit)</font>
...
...
@@ -216,7 +220,9 @@ plt.title("Scatterplot with line of best fit grouped by number of cylinders", fo
plt
.
show
()
```
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/03.png
)
</fancybox>
针对每一组数据绘制线性回归线(Each regression line in its own column),可以通过在
`sns.lmplot()`
中设置
`col=groupingcolumn`
参数来实现,如下:
...
...
@@ -240,7 +246,9 @@ gridobj.set(xlim=(0.5, 7.5), ylim=(0, 50))
plt
.
show
()
```
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/04.png
)
</fancybox>
### <font color=##4876FF>【04】抖动图(Jittering with stripplot)</font>
...
...
@@ -259,7 +267,9 @@ plt.title('Use jittered plots to avoid overlapping of points', fontsize=22)
plt
.
show
()
```
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/05.png
)
</fancybox>
### <font color=##4876FF>【05】计数图(Counts Plot)</font>
...
...
@@ -279,8 +289,9 @@ plt.title('Counts Plot - Size of circle is bigger as more points overlap', fonts
plt
.
show
()
```
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/06.png
)
</fancybox>
### <font color=##4876FF>【06】边缘直方图(Marginal Histogram)</font>
...
...
@@ -320,7 +331,9 @@ ax_main.set_xticklabels(xlabels)
plt
.
show
()
```
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/07.png
)
</fancybox>
### <font color=##4876FF>【07】边缘箱形图(Marginal Boxplot)</font>
...
...
@@ -362,7 +375,9 @@ for item in ([ax_main.xaxis.label, ax_main.yaxis.label] + ax_main.get_xticklabel
plt
.
show
()
```
<fancybox>
![
08
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/08.png
)
</fancybox>
### <font color=##4876FF>【08】相关图(Correllogram)</font>
...
...
@@ -383,7 +398,9 @@ plt.yticks(fontsize=12)
plt
.
show
()
```
<fancybox>
![
09
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/09.png
)
</fancybox>
### <font color=##4876FF>【09】成对图(Pairwise Plot)</font>
...
...
@@ -399,7 +416,9 @@ sns.pairplot(df, kind="scatter", hue="species", plot_kws=dict(s=80, edgecolor="w
plt
.
show
()
```
<fancybox>
![
10
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/10.png
)
</fancybox>
```
python
# Load Dataset
...
...
@@ -411,7 +430,9 @@ sns.pairplot(df, kind="reg", hue="species")
plt
.
show
()
```
<fancybox>
![
11
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/11.png
)
</fancybox>
## <font color=#FF0000>【4x00】偏差(Deviation)</font>
...
...
@@ -440,7 +461,9 @@ plt.grid(linestyle='--', alpha=0.5)
plt
.
show
()
```
<fancybox>
![
12
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/12.png
)
</fancybox>
### <font color=##4876FF>【11】发散型文本图(Diverging Texts)</font>
...
...
@@ -470,7 +493,9 @@ plt.xlim(-2.5, 2.5)
plt
.
show
()
```
<fancybox>
![
13
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/13.png
)
</fancybox>
### <font color=##4876FF>【12】发散型散点图(Diverging Dot Plot)</font>
...
...
@@ -507,7 +532,9 @@ plt.xlim(-2.5, 2.5)
plt
.
show
()
```
<fancybox>
![
14
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/14.png
)
</fancybox>
### <font color=##4876FF>【13】带标记的发散型棒棒糖图(Diverging Lollipop Chart with Markers)</font>
...
...
@@ -553,7 +580,9 @@ plt.grid(linestyle='--', alpha=0.5)
plt
.
show
()
```
<fancybox>
![
15
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/15.png
)
</fancybox>
### <font color=##4876FF>【14】面积图(Area Chart)</font>
...
...
@@ -591,7 +620,9 @@ plt.grid(alpha=0.5)
plt
.
show
()
```
<fancybox>
![
16
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/16.png
)
</fancybox>
## <font color=#FF0000>【5x00】排序(Ranking)</font>
...
...
@@ -630,7 +661,9 @@ fig.add_artist(p2)
plt
.
show
()
```
<fancybox>
![
17
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/17.png
)
</fancybox>
### <font color=##4876FF>【16】棒棒糖图(Lollipop Chart)</font>
...
...
@@ -662,7 +695,9 @@ for row in df.itertuples():
plt
.
show
()
```
<fancybox>
![
18
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/18.png
)
</fancybox>
### <font color=##4876FF>【17】点图(Dot Plot)</font>
...
...
@@ -689,7 +724,9 @@ ax.set_xlim(10, 27)
plt
.
show
()
```
<fancybox>
![
19
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/19.png
)
</fancybox>
### <font color=##4876FF>【18】坡度图(Slope Chart)</font>
...
...
@@ -755,7 +792,9 @@ plt.gca().spines["left"].set_alpha(.0)
plt
.
show
()
```
<fancybox>
![
20
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/20.png
)
</fancybox>
### <font color=##4876FF>【19】哑铃图(Dumbbell Plot)</font>
...
...
@@ -805,7 +844,9 @@ ax.set_xticklabels(['5%', '15%', '20%', '25%'])
plt
.
show
()
```
<fancybox>
![
21
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/21.png
)
</fancybox>
## <font color=#FF0000>【6x00】分布(Distribution)</font>
...
...
@@ -838,7 +879,9 @@ plt.xticks(ticks=bins[::3], labels=[round(b, 1) for b in bins[::3]])
plt
.
show
()
```
<fancybox>
![
22
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/22.png
)
</fancybox>
### <font color=##4876FF>【21】分类变量的直方图(Histogram for Categorical Variable)</font>
...
...
@@ -869,7 +912,9 @@ plt.xticks(ticks=bins, labels=np.unique(df[x_var]).tolist(), rotation=90, horizo
plt
.
show
()
```
<fancybox>
![
23
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/23.png
)
</fancybox>
### <font color=##4876FF>【22】密度图(Density Plot)</font>
...
...
@@ -892,7 +937,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
24
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/24.png
)
</fancybox>
### <font color=##4876FF>【23】直方图密度曲线(Density Curves with Histogram)</font>
...
...
@@ -918,7 +965,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
25
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/25.png
)
</fancybox>
### <font color=##4876FF>【24】山峰叠峦图 / 欢乐图(Joy Plot)</font>
...
...
@@ -943,7 +992,9 @@ plt.title('Joy Plot of City and Highway Mileage by Class', fontsize=22)
plt
.
show
()
```
<fancybox>
![
26
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/26.png
)
</fancybox>
### <font color=##4876FF>【25】分布式点图(Distributed Dot Plot)</font>
...
...
@@ -993,7 +1044,9 @@ plt.grid(axis='both', alpha=.4, linewidth=.1)
plt
.
show
()
```
<fancybox>
![
27
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/27.png
)
</fancybox>
### <font color=##4876FF>【26】箱形图(Box Plot)</font>
...
...
@@ -1028,7 +1081,9 @@ plt.ylim(10, 40)
plt
.
show
()
```
<fancybox>
![
28
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/28.png
)
</fancybox>
### <font color=##4876FF>【27】点 + 箱形图(Dot + Box Plot)</font>
...
...
@@ -1052,7 +1107,9 @@ plt.legend(title='Cylinders')
plt
.
show
()
```
<fancybox>
![
29
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/29.png
)
</fancybox>
### <font color=##4876FF>【28】小提琴图(Violin Plot)</font>
...
...
@@ -1071,7 +1128,9 @@ plt.title('Violin Plot of Highway Mileage by Vehicle Class', fontsize=22)
plt
.
show
()
```
<fancybox>
![
30
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/30.png
)
</fancybox>
### <font color=##4876FF>【29】人口金字塔图(Population Pyramid)</font>
...
...
@@ -1099,7 +1158,9 @@ plt.legend()
plt
.
show
()
```
<fancybox>
![
31
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/31.png
)
</fancybox>
### <font color=##4876FF>【30】分类图(Categorical Plots)</font>
...
...
@@ -1120,7 +1181,9 @@ g = sns.catplot("alive", col="deck", col_wrap=4,
plt
.
show
()
```
<fancybox>
![
32
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/32.png
)
</fancybox>
```
python
# Load Dataset
...
...
@@ -1137,7 +1200,9 @@ sns.catplot(x="age", y="embark_town",
plt
.
show
()
```
<fancybox>
![
33
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/33.png
)
</fancybox>
## <font color=#FF0000>【7x00】组成(Composition)</font>
...
...
@@ -1180,7 +1245,9 @@ fig = plt.figure(
plt
.
show
()
```
<fancybox>
![
34
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/34.png
)
</fancybox>
```
python
# ! pip install pywaffle
...
...
@@ -1240,7 +1307,9 @@ fig = plt.figure(
plt
.
show
()
```
<fancybox>
![
35
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/35.png
)
</fancybox>
### <font color=##4876FF>【32】饼图(Pie Chart)</font>
...
...
@@ -1264,7 +1333,9 @@ plt.ylabel("")
plt
.
show
()
```
<fancybox>
![
36
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/36.png
)
</fancybox>
```
python
# Import
...
...
@@ -1300,7 +1371,9 @@ ax.set_title("Class of Vehicles: Pie Chart")
plt
.
show
()
```
<fancybox>
![
37
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/37.png
)
</fancybox>
### <font color=##4876FF>【33】矩阵树形图(Treemap)</font>
...
...
@@ -1331,7 +1404,9 @@ plt.axis('off')
plt
.
show
()
```
<fancybox>
![
38
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/38.png
)
</fancybox>
### <font color=##4876FF>【34】条形图(Bar Chart)</font>
...
...
@@ -1364,7 +1439,9 @@ plt.ylim(0, 45)
plt
.
show
()
```
<fancybox>
![
39
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/39.png
)
</fancybox>
## <font color=#FF0000>【8x00】变化(Change)</font>
...
...
@@ -1397,7 +1474,9 @@ plt.gca().spines["left"].set_alpha(0.3)
plt
.
show
()
```
<fancybox>
![
40
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/40.png
)
</fancybox>
### <font color=##4876FF>【36】带波峰和波谷注释的时间序列图(Time Series with Peaks and Troughs Annotated)</font>
...
...
@@ -1447,7 +1526,9 @@ plt.grid(axis='y', alpha=.3)
plt
.
show
()
```
<fancybox>
![
41
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/41.png
)
</fancybox>
### <font color=##4876FF>【37】自相关 (ACF) 和部分自相关 (PACF) 图(Autocorrelation (ACF) and Partial Autocorrelation (PACF) Plot)</font>
...
...
@@ -1483,7 +1564,9 @@ ax2.tick_params(axis='both', labelsize=12)
plt
.
show
()
```
<fancybox>
![
42
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/42.png
)
</fancybox>
### <font color=##4876FF>【38】交叉相关图(Cross Correlation plot)</font>
...
...
@@ -1520,7 +1603,9 @@ plt.xlim(0, len(ccs))
plt
.
show
()
```
<fancybox>
![
43
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/43.png
)
</fancybox>
### <font color=##4876FF>【39】时间序列分解图(Time Series Decomposition Plot)</font>
...
...
@@ -1544,7 +1629,9 @@ result.plot().suptitle('Time Series Decomposition of Air Passengers')
plt
.
show
()
```
<fancybox>
![
44
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/44.png
)
</fancybox>
### <font color=##4876FF>【40】多重时间序列(Multiple Time Series)</font>
...
...
@@ -1590,7 +1677,9 @@ plt.xlim(-2, 80)
plt
.
show
()
```
<fancybox>
![
45
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/45.png
)
</fancybox>
### <font color=##4876FF>【41】使用次要的 Y 轴来绘制不同范围的图形(Plotting with different scales using secondary Y axis)</font>
...
...
@@ -1630,7 +1719,9 @@ fig.tight_layout()
plt
.
show
()
```
<fancybox>
![
46
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/46.png
)
</fancybox>
### <font color=##4876FF>【42】带误差带的时间序列(Time Series with Error Bands)</font>
...
...
@@ -1673,7 +1764,9 @@ for y in range(8, 20, 2):
plt
.
show
()
```
<fancybox>
![
47
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/47.png
)
</fancybox>
```
python
"Data Source: https://www.kaggle.com/olistbr/brazilian-ecommerce#olist_orders_dataset.csv"
...
...
@@ -1716,7 +1809,9 @@ for y in range(5, 10, 1):
plt
.
show
()
```
<fancybox>
![
48
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/48.png
)
</fancybox>
### <font color=##4876FF>【43】堆积面积图(Stacked Area Chart)</font>
...
...
@@ -1768,7 +1863,9 @@ plt.gca().spines["left"].set_alpha(.3)
plt
.
show
()
```
<fancybox>
![
49
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/49.png
)
</fancybox>
### <font color=##4876FF>【44】未堆积面积图(Area Chart UnStacked)</font>
...
...
@@ -1810,7 +1907,9 @@ plt.gca().spines["left"].set_alpha(.3)
plt
.
show
()
```
<fancybox>
![
50
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/50.png
)
</fancybox>
### <font color=##4876FF>【45】日历热力图(Calendar Heat Map)</font>
...
...
@@ -1833,8 +1932,9 @@ calmap.calendarplot(df['2014']['VIX.Close'], fig_kws={'figsize': (16, 10)},
plt
.
show
()
```
<fancybox>
![
51
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/51.png
)
</fancybox>
### <font color=##4876FF>【46】季节图(Seasonal Plot)</font>
...
...
@@ -1881,7 +1981,9 @@ plt.gca().spines["left"].set_alpha(0.5)
plt
.
show
()
```
<fancybox>
![
52
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/52.png
)
</fancybox>
## <font color=#FF0000>【9x00】分组( Groups)</font>
...
...
@@ -1904,7 +2006,9 @@ plt.xticks(fontsize=12)
plt
.
show
()
```
<fancybox>
![
53
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/53.png
)
</fancybox>
### <font color=##4876FF>【48】聚类图(Cluster Plot)</font>
...
...
@@ -1950,7 +2054,9 @@ plt.title('Agglomerative Clustering of USArrests (5 Groups)', fontsize=22)
plt
.
show
()
```
<fancybox>
![
54
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/54.png
)
</fancybox>
### <font color=##4876FF>【49】安德鲁斯曲线(Andrews Curve)</font>
...
...
@@ -1981,7 +2087,9 @@ plt.yticks(fontsize=12)
plt
.
show
()
```
<fancybox>
![
55
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/55.png
)
</fancybox>
### <font color=##4876FF>【50】平行坐标图(Parallel Coordinates)</font>
...
...
@@ -2010,7 +2118,9 @@ plt.yticks(fontsize=12)
plt
.
show
()
```
<fancybox>
![
56
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A78/56.png
)
</fancybox>
---
...
...
source/_posts/A79-Pandas-01.md
浏览文件 @
4e6b8dad
...
...
@@ -124,7 +124,9 @@ Series 是带标签的一维数组,可存储整数、浮点数、字符串、P
| name | str 类型,可选项,给 Series 命名 |
| copy | bool 类型,可选项,默认 False,是否复制输入数据 |
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A79/01.png
)
</fancybox>
### <font color=#4876FF>【03x01】通过 list 构建 Series</font>
...
...
@@ -390,7 +392,9 @@ DataFrame 是一个表格型的数据结构,它含有一组有序的列,每
| dtype | 输出系列的数据类型。可选项,如果未指定,则将从数据中推断,具体参考官网
[
dtypes
](
https://pandas.pydata.org/docs/getting_started/basics.html#dtypes
)
介绍 |
| copy | bool 类型,可选项,默认 False,是否复制输入数据,仅影响 DataFrame/2d ndarray 输入 |
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A79/02.png
)
</fancybox>
### <font color=#4876FF>【03x01】通过 ndarray 构建 DataFrame</font>
...
...
source/_posts/A84-Pandas-06.md
浏览文件 @
4e6b8dad
...
...
@@ -60,7 +60,9 @@ Pandas 系列文章:
官方介绍:
[
https://pandas.pydata.org/docs/user_guide/groupby.html
](
https://pandas.pydata.org/docs/user_guide/groupby.html
)
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A84/01.png
)
</fancybox>
## <font color=#FF0000>【02x00】GroupBy 对象</font>
...
...
source/_posts/A88-Pandas-10.md
浏览文件 @
4e6b8dad
...
...
@@ -106,7 +106,9 @@ read_table:[https://pandas.pydata.org/docs/reference/api/pandas.read_table.htm
首先创建一个 test1.csv 文件:
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/01.png
)
</fancybox>
使用 read_csv 方法将其读出为一个 DataFrame 对象:
...
...
@@ -139,7 +141,9 @@ read_table:[https://pandas.pydata.org/docs/reference/api/pandas.read_table.htm
以上示例中第一行为列标签,如果没有单独定义列标签,使用 read_csv 方法也会默认将第一行当作列标签:
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/02.png
)
</fancybox>
```
python
>>>
import
pandas
as
pd
...
...
@@ -176,7 +180,9 @@ read_table:[https://pandas.pydata.org/docs/reference/api/pandas.read_table.htm
`index_col`
参数可以指定某一列作为 DataFrame 的行索引,传递的参数是列名称,在以下示例中,会将列名为
`message`
的列作为 DataFrame 的行索引:
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/03.png
)
</fancybox>
```
python
>>>
pd
.
read_csv
(
r
'C:\Users\TanRe\Desktop\test2.csv'
,
...
...
@@ -191,7 +197,9 @@ python 9 10 11 12
如果需要构造多层索引的 DataFrame 对象,则只需传入由列编号或列名组成的列表即可:
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/04.png
)
</fancybox>
```
python
>>>
import
pandas
as
pd
...
...
@@ -212,7 +220,9 @@ two a 9 10
在 read_table 中,sep 参数用于接收分隔符,如果遇到不是用固定的分隔符去分隔字段的,也可以传递一个正则表达式作为 read_table 的分隔符,如下面的 txt 文件数据之间是由不同的空白字符间隔开的:
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/05.png
)
</fancybox>
```
python
>>>
import
pandas
as
pd
...
...
@@ -228,7 +238,9 @@ ddd -0.871858 -0.348382 1.100491
skiprows 参数可用于设置需要忽略的行数,或需要跳过的行号列表,在下面的示例中,读取文件时选择跳过第1、3、4行(索引值分别为0、2、3):
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/06.png
)
</fancybox>
```
python
>>>
import
pandas
as
pd
...
...
@@ -243,7 +255,9 @@ skiprows 参数可用于设置需要忽略的行数,或需要跳过的行号
当文件中出现了空字符串或者 NA 值,Pandas 会将其标记成 NaN(缺失值),同样也可以使用
`isnull`
方法来判断结果值是否为缺失值:
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/07.png
)
</fancybox>
```
python
>>>
import
pandas
as
pd
...
...
@@ -292,7 +306,9 @@ skiprows 参数可用于设置需要忽略的行数,或需要跳过的行号
以下 test6.csv 文件中包含 50 行数据:
<fancybox>
![
08
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/08.png
)
</fancybox>
可以设置
`pd.options.display.max_rows`
来紧凑地显示指定行数的数据:
...
...
@@ -347,7 +363,7 @@ skiprows 参数可用于设置需要忽略的行数,或需要跳过的行号
>>>
for
piece
in
chunker
:
tot
=
tot
.
add
(
piece
[
'key'
].
value_counts
(),
fill_value
=
0
)
>>>
tot
=
tot
.
sort_values
(
ascending
=
False
)
>>>
tot
[:
10
]
G
6.0
...
...
@@ -415,7 +431,9 @@ Pandas 提供了一些用于将表格型数据读取为 DataFrame 对象的函
>>>
data
.
to_csv
(
r
'C:\Users\TanRe\Desktop\out1.csv'
)
```
<fancybox>
![
09
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/09.png
)
</fancybox>
### <font color=#4876FF>【02x02】sep 指定分隔符</font>
...
...
@@ -433,7 +451,9 @@ sep 参数可用于其他分隔符:
>>>
data
.
to_csv
(
r
'C:\Users\TanRe\Desktop\out2.csv'
,
sep
=
'|'
)
```
<fancybox>
![
10
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/10.png
)
</fancybox>
### <font color=#4876FF>【02x03】na_rep 替换缺失值</font>
...
...
@@ -451,7 +471,9 @@ na_rep 参数可将缺失值(NaN)替换成其他字符串:
>>>
data
.
to_csv
(
r
'C:\Users\TanRe\Desktop\out3.csv'
,
na_rep
=
'X'
)
```
<fancybox>
![
11
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/11.png
)
</fancybox>
### <font color=#4876FF>【02x04】index / header 行与列标签</font>
...
...
@@ -469,7 +491,9 @@ na_rep 参数可将缺失值(NaN)替换成其他字符串:
>>>
data
.
to_csv
(
r
'C:\Users\TanRe\Desktop\out4.csv'
,
index
=
False
,
header
=
False
)
```
<fancybox>
![
12
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/12.png
)
</fancybox>
还可以传入列表来重新设置列标签:
...
...
@@ -485,7 +509,9 @@ na_rep 参数可将缺失值(NaN)替换成其他字符串:
>>>
data
.
to_csv
(
r
'C:\Users\TanRe\Desktop\out5.csv'
,
header
=
[
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
])
```
<fancybox>
![
13
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/13.png
)
</fancybox>
### <font color=#4876FF>【02x05】columns 指定列</font>
...
...
@@ -499,11 +525,13 @@ na_rep 参数可将缺失值(NaN)替换成其他字符串:
0
one
1
2
3.0
4
NaN
1
two
5
6
NaN
8
world
2
three
9
10
11.0
12
python
>>>
>>>
>>>
data
.
to_csv
(
r
'C:\Users\TanRe\Desktop\out6.csv'
,
columns
=
[
'c'
,
'b'
,
'a'
])
```
<fancybox>
![
14
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A88/14.png
)
</fancybox>
---
...
...
source/_posts/A89-COVID-19.md
浏览文件 @
4e6b8dad
...
...
@@ -44,13 +44,17 @@ description: COVID-19 肺炎疫情数据实时监控,基于 python 爬虫 + py
## <font color=#FF0000>【2x00】思维导图</font>
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A89/01.png
)
</fancybox>
## <font color=#FF0000>【3x00】数据结构分析</font>
通过查看百度的疫情数据页面,可以看到很多整齐的数据,猜测就是疫情相关的数据,保存该页面,对其进行格式化,很容易可以分析出所有的数据都在
`<script type="application/json" id="captain-config"></script>`
里面,其中 title 里面是一些 Unicode 编码,将其转为中文后更容易得到不同的分类数据。
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A89/02.png
)
</fancybox>
由于数据繁多,可以将数据主体部分提取出来,删除一些重复项和其他杂项,留下数据大体位置并分析数据结构,便于后期的数据提取,经过处理后的数据大致结构如下:
...
...
@@ -1038,19 +1042,29 @@ def foreign_daily_map():
### <font color="#4876FF">【8x01】数据储存 Excel</font>
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A89/03.png
)
</fancybox>
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A89/04.png
)
</fancybox>
### <font color="#4876FF">【8x02】词云图</font>
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A89/05.png
)
</fancybox>
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A89/06.png
)
</fancybox>
### <font color="#4876FF">【8x03】地图 + 折线图</font>
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A89/07.png
)
</fancybox>
## <font color=#FF0000>【9x00】完整代码</font>
...
...
source/_posts/A90-pyspider-51job.md
浏览文件 @
4e6b8dad
...
...
@@ -46,7 +46,9 @@ description: 利用 Python 根据用户输入的关键字爬取相关职位信
在页面的下方给出了该职位一共有多少页,使用 Xpath 和正则表达式提取里面的数字,方便后面翻页爬取使用,注意页面编码为
`gbk`
。
<fancybox>
![
01
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A90/01.png
)
</fancybox>
```
python
def
tatal_url
(
self
):
...
...
@@ -75,17 +77,25 @@ description: 利用 Python 根据用户输入的关键字爬取相关职位信
请求地址中的各参数值通过 js 加密:
[
https://js.51jobcdn.com/in/js/2018/coapi/coapi.min.js
](
https://js.51jobcdn.com/in/js/2018/coapi/coapi.min.js
)
<fancybox>
![
02
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A90/02.png
)
</fancybox>
<fancybox>
![
03
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A90/03.png
)
</fancybox>
**特殊情况二:**
部分公司有自己的专属页面,此类页面的结构也不同于普通页面
页面示例:
[
http://dali.51ideal.com/jobdetail.html?jobid=121746338
](
http://dali.51ideal.com/jobdetail.html?jobid=121746338
)
<fancybox>
![
04
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A90/04.png
)
</fancybox>
<fancybox>
![
05
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A90/05.png
)
</fancybox>
为了规范化,本次爬取将去掉这部分特殊页面,仅爬取 URL 带有
`jobs.51job.com`
的数据
...
...
@@ -352,21 +362,31 @@ def wages_education_chart(data):
MongoDB:
<fancybox>
![
06
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A90/06.png
)
</fancybox>
CSV 文件:
<fancybox>
![
07
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A90/07.png
)
</fancybox>
JSON 文件:
<fancybox>
![
08
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A90/08.png
)
</fancybox>
关系图:
<fancybox>
![
09
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A90/09.png
)
</fancybox>
<fancybox>
![
10
](
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-PIC/A90/10.png
)
</fancybox>
## <font color=#FF0000>【4x00】完整代码</font>
...
...
source/friends/index.md
浏览文件 @
4e6b8dad
...
...
@@ -90,22 +90,13 @@ links:
-
name
:
ZJohnson海马体
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/zjohnson.jpg
url
:
http://
www.
zjohnson.top/
url
:
http://zjohnson.top/
backgroundColor
:
'
#FBBC05'
textColor
:
'
#fff'
tags
:
-
生物信息
-
Python
-
name
:
Fangzh
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/fangzh.jpg
url
:
http://fangzh.top/
backgroundColor
:
'
#708090'
textColor
:
'
#fff'
tags
:
-
人工智能
-
人生感悟
-
name
:
一去二三遥
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/moonster.jpg
url
:
https://www.moonster.life/
...
...
@@ -115,9 +106,9 @@ links:
-
一个想当摄影师却被迫写代码的厨子
-
name
:
清酒踏月
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/lkxin.png
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/lkxin
blog
.png
url
:
https://www.lkxin.cn/
backgroundColor
:
'
#
E94335
'
backgroundColor
:
'
#
708090
'
textColor
:
'
#fff'
tags
:
-
网络技术
...
...
@@ -167,15 +158,6 @@ links:
-
前端
-
摄影
-
name
:
Tohot
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/tohot.jpg
url
:
https://tohot.top/
backgroundColor
:
'
#008B8B'
textColor
:
'
#fff'
tags
:
-
开发
-
分享
-
name
:
Wuyongzhi·Blog
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/wuyongzhi.jpg
url
:
https://wuyongzhi.top/
...
...
@@ -194,15 +176,6 @@ links:
-
Java
-
生活
-
name
:
喵喵喵~
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/giligili.jpg
url
:
https://giligili.top/
backgroundColor
:
'
#FBBC05'
textColor
:
'
#fff'
tags
:
-
前端
-
二次元
-
name
:
mjx's blog
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/mjx.jpg
url
:
https://mjx.js.org/
...
...
@@ -212,14 +185,6 @@ links:
-
JS
-
C++
-
name
:
人生地里的地瓜
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/l-zhe.jpg
url
:
http://www.l-zhe.com/
backgroundColor
:
'
#E94335'
textColor
:
'
#fff'
tags
:
-
机器学习
-
name
:
Mohen's blog
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/mcmohen.jpg
url
:
https://mcmohen.com/
...
...
@@ -256,14 +221,6 @@ links:
-
Web
-
嵌入式
-
name
:
Singularity
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/singularity2u.jpg
url
:
https://www.singularity2u.top/
backgroundColor
:
'
#008B8B'
textColor
:
'
#fff'
tags
:
-
ACM
-
name
:
暗影
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/anbujingying.jpg
url
:
https://dsanying.github.io/
...
...
@@ -284,16 +241,6 @@ links:
-
python
-
Linux
-
name
:
松林羊
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/andus.png
url
:
http://www.andus.top/
backgroundColor
:
'
#708090'
textColor
:
'
#fff'
tags
:
-
DevOps
-
Java
-
前端
-
name
:
小丁的个人博客
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/tding.jpg
url
:
https://tding.top/
...
...
@@ -304,7 +251,7 @@ links:
-
name
:
KAYGB
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/kaygb.png
url
:
https://kaygb.
top
/
url
:
https://kaygb.
com
/
backgroundColor
:
'
#34A853'
textColor
:
'
#fff'
tags
:
...
...
@@ -312,9 +259,9 @@ links:
-
PHP
-
name
:
黑猫
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/blackcat.png
url
:
https://
www.
blackcat.top/
backgroundColor
:
'
#
E94335
'
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/blackcat
top
.png
url
:
https://blackcat.top/
backgroundColor
:
'
#
187BC3
'
textColor
:
'
#fff'
tags
:
-
Java
...
...
@@ -325,7 +272,9 @@ links:
backgroundColor
:
'
#008B8B'
textColor
:
'
#fff'
tags
:
-
你现在的努力,是为了以后有更多的选择.
-
Web
-
Java
-
随笔
-
name
:
残梦
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/2662419405.jpg
...
...
@@ -378,9 +327,9 @@ links:
-
DEVOPS
-
技术交流
-
name
:
一觉睡到小时候
-
name
:
LeePandar
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/lida1024.jpg
url
:
https://li
da1024.top
/
url
:
https://li
keyou.cool
/
backgroundColor
:
'
#E94335'
textColor
:
'
#fff'
tags
:
...
...
@@ -388,15 +337,15 @@ links:
-
前端
-
name
:
优客-blog
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/youke
0.pn
g
url
:
http
://youke0.xyz
/
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/youke
blog.jpe
g
url
:
http
s://youkeblog.com
/
backgroundColor
:
'
#708090'
textColor
:
'
#fff'
tags
:
-
一定要比从前的自己更加优秀!
-
name
:
高高编程小屋
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/
frogfrog
.jpg
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/
littlewhale
.jpg
url
:
http://littlewhale.xyz/
backgroundColor
:
'
#967ADC'
textColor
:
'
#fff'
...
...
@@ -438,9 +387,9 @@ links:
tags
:
-
一个懒人的博客
-
name
:
ChrAlpha
的幻想乡
-
name
:
ChrAlpha
avatar
:
https://cdn.jsdelivr.net/gh/TRHX/ImageHosting/ITRHX-LINKS/chralpha.jpg
url
:
https://
chralpha.com
/
url
:
https://
ichr.me
/
backgroundColor
:
'
#34A853'
textColor
:
'
#fff'
tags
:
...
...
@@ -510,3 +459,4 @@ links:
> 简介:求知若饥,虚心若愚!
> **<font size=4px color=#FF0000>由于目前友链数过多,所以暂停交换友链,敬请见谅!</font>**
> **<font size=4px color=#FF0000>长期不能访问的站点将会被删除,若已恢复请留言告知!</font>**
themes/material-x-1.2.1/layout/_partial/scripts.ejs
浏览文件 @
4e6b8dad
...
...
@@ -136,7 +136,7 @@
<% } %>
<% if (enableGitalk) { %>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1
.5.2
/dist/gitalk.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>
<script type="text/javascript">
var gitalk = new Gitalk({
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录