Showing preview only (955K chars total). Download the full file or copy to clipboard to get everything.
Repository: LiuQixuan/PythonLearningNote
Branch: master
Commit: 0277bbe83313
Files: 8
Total size: 868.4 KB
Directory structure:
gitextract_fpt6cfde/
├── Matplotlib 学习笔记.md
├── NumPy 高维数组降维方法详细分析.md
├── Python 科学计算.md
├── Python 进阶笔记.md
├── README.md
├── SVM 原理详解.md
├── TensorFlow 安装总结.md
└── 数据预处理之One-Hot(独热编码)编码.md
================================================
FILE CONTENTS
================================================
================================================
FILE: Matplotlib 学习笔记.md
================================================
---
title: Matplotlib 学习笔记
date: 2019-03-13 21:23:56
tags:
- python
- Matplotlib
- noteBook
toc: true
---
## Matplotlib
Matplotlib 是Python2D绘图领域使用最广泛的套件。能导出多种格式的图片。
### Matplotlib中文显示
Matplotlib默认是不支持中文的,如果出现中文会以方框代替。

但是经过测试国外字体中部分可以支持。
```python
goodfont=[
'Adobe Heiti Std',
'Arial Unicode MS',
'DengXian',
'SimHei',
'STKaiti',
'STXihei',
]
```
<!-- more -->
使用fontproperties指定字体
```python
import numpy as np
from matplotlib import pyplot as plt
import matplotlib
zh_cn_font = matplotlib.font_manager.FontProperties(fname="F:\ProjectFiles\SimHei.ttf")
#第七行的作用是为了消除更换为unicode字体之后0、负数之类的显示异常。之后所有使用中文字体的地方只字符串都以u""的形式出现,并指定fontproperties属性为我们的指定的myfont就行了
matplotlib.rcParams['axes.unicode_minus'] = False
#matplotlib.rcParams['font.sans-serif'] = ['SimHei']
x = np.arange(0,9)
y = 2*x+1
plt.title(u"Matplotlib 标题",fontproperties = zh_cn_font)
plt.xlabel(u"x 轴:",fontproperties = zh_cn_font)
plt.ylabel(u"y 轴:",fontproperties = zh_cn_font)
plt.plot(x,y)
plt.show()
```
一劳永逸法
1. 找到matplotlib 配置文件:
```python
import matplotlib
print(matplotlib.matplotlib_fname())
#我自己的输出结果如下:
#%Python_Home%\Lib\site-packages\matplotlib\mpl-data
```
2. 编辑器打开此文件 matplotlibrc删除font.family和font.sans-serif两行前的#,并在font.sans-serif后添加微软雅黑字体Microsoft YaHei
3. 下载字体:msyh.ttf (微软雅黑)放在matplotlib 字体文件夹下:# %Python_Home%\Lib\site-packages\matplotlib\mpl-data\fonts\ttf
4. 删除.matplotlib/cache里面的两个缓存字体文件C:\Users\你的用户名\\.matplotlib

5. 重启Python

### 绘制一次方程
使用matplotlib中的pylot包进行简单绘图。
```python
import numpy as np
from matplotlib import pyplot as plt
x = np.arange(0,9)
y = 2*x+1
plt.title("Matplotlib Demo1")
plt.xlabel("x axis:")
plt.ylabel("y axis:")
plt.plot(x,y)
plt.show()
```

### 绘制离散图
向pyplot的plot()函数添加特殊的格式化字符串可以显示离散值。
| 字符 | 描述 |
| :--------- | :----------- |
| `'-'` | 实线样式 |
| `'--'` | 短横线样式 |
| `'-.'` | 点划线样式 |
| `':'` | 虚线样式 |
| `'.'` | 点标记 |
| `','` | 像素标记 |
| `'o'` | 圆标记 |
| `'v'` | 倒三角标记 |
| `'^'` | 正三角标记 |
| `'<'` | 左三角标记 |
| `'>'` | 右三角标记 |
| `'1'` | 下箭头标记 |
| `'2'` | 上箭头标记 |
| `'3'` | 左箭头标记 |
| `'4'` | 右箭头标记 |
| `'s'` | 正方形标记 |
| `'p'` | 五边形标记 |
| `'*'` | 星形标记 |
| `'h'` | 六边形标记 1 |
| `'H'` | 六边形标记 2 |
| `'+'` | 加号标记 |
| `'x'` | X 标记 |
| `'D'` | 菱形标记 |
| `'d'` | 窄菱形标记 |
| `'|'` | 竖直线标记 |
| `'_'` | 水平线标记 |
以下是颜色的缩写:
| 字符 | 颜色 |
| :---- | :----- |
| `'b'` | 蓝色 |
| `'g'` | 绿色 |
| `'r'` | 红色 |
| `'c'` | 青色 |
| `'m'` | 品红色 |
| `'y'` | 黄色 |
| `'k'` | 黑色 |
| `'w'` | 白色 |
例如:要显示圆来代表点,而不是上面示例中的线,请使用 ob 作为 plot() 函数中的格式字符串。
### 绘制正弦函数
```python
import numpy as np
from matplotlib import pyplot as plt
import matplotlib
m = np.arange(0,4,0.1)
n = np.sin(m*np.pi)
plt.title(u"Matplotlib 正弦函数")
plt.xlabel(u"x 轴:")
plt.ylabel(u"y 轴:")
plt.plot(m,n,'-')
plt.show()
```

### 绘制子图
`pyplot.subplot(nrows,ncols,index)`可以在一个figure中添加多个子图像。
使用`plt.subtiltle('')`给整个figure添加标题,使用plt.title('')给每个subplot添加子标题,修改x轴范围使用plt.xlim(min,max),修改x轴刻度使用plt.xticks([numlist],[textlist])。
```python
import numpy as np
from matplotlib import pyplot as plt
import matplotlib
x = np.arange(0,3,0.05)
n = np.linspace(-np.pi/2,np.pi/2,50)
y = np.sin(x*np.pi)
z = np.cos(x*np.pi)
p = np.tan(n)
q = np.tan(np.pi/2-n)
plt.figure(figsize = (16,9),dpi = 80)
plt.suptitle('Matplotlib 绘制多图',fontsize = 40,weight = 40)
plt.subplot(2,2,1)
plt.title(u"正弦函数")
plt.xlabel(u"x 轴:")
plt.ylabel(u"y 轴:")
plt.plot(x,y,'-',label = 'sine')
plt.subplot(2, 2, 2)
plt.title(u"余弦函数")
plt.xlabel(u"x 轴:")
plt.ylabel(u"y 轴:")
plt.plot(x,z,'-',label = 'cosine')
plt.subplot(2, 2, 3)
plt.xlim(n.min()*1.1,n.max()*1.1)
plt.xticks([-np.pi/2,-np.pi/4,0,np.pi/4,np.pi/2],[r'$-\pi/2$',r'$-\pi/4$',r'$0$',r'$\pi/4$',r'$\pi/2$'])
plt.ylim(-10,10)
plt.title(u"正切函数")
plt.xlabel(u"x 轴:")
plt.ylabel(u"y 轴:")
plt.plot(n,p,'-',label = 'tan')
plt.subplot(2, 2, 4)
plt.xlim(n.min()*1.1,n.max()*1.1)
plt.xticks([-np.pi/2,-np.pi/4,0,np.pi/4,np.pi/2],[r'$-\pi/2$',r'$-\pi/4$',r'$0$',r'$\pi/4$',r'$\pi/2$'])
plt.ylim(-10,10)
plt.title(u"余弦函数")
plt.xlabel(u"x 轴:")
plt.ylabel(u"y 轴:")
plt.plot(n,q,'-',label = 'cotan')
plt.show()
```
编码.md
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (959K chars).
[
{
"path": "Matplotlib 学习笔记.md",
"chars": 796203,
"preview": "---\ntitle: Matplotlib 学习笔记\ndate: 2019-03-13 21:23:56\ntags:\n - python\n - Matplotlib\n - noteBook\ntoc: true\n---\n\n#"
},
{
"path": "NumPy 高维数组降维方法详细分析.md",
"chars": 3298,
"preview": "---\ntitle: NumPy 降维方法深度解析\ndate: 2019-03-13 12:23:56\ntags:\n - python\n - NumPy\ntoc: true\n---\n\n\n\n## numpy的flat、flatte"
},
{
"path": "Python 科学计算.md",
"chars": 36230,
"preview": "---\ntitle: Python科学计算\ndate: 2019-03-09 21:23:56\ntags:\n\n\t- python\n\t- science conputing\ntoc: true\n---\n# Python 科学计算\n\n---\n["
},
{
"path": "Python 进阶笔记.md",
"chars": 14396,
"preview": "```php\r\ntitle: Python进阶笔记\r\ndate: 2019-03-06 21:23:56\r\ntags:\r\n - Python\r\n - advancement\r\n - noteBook\r\ntoc: true\r"
},
{
"path": "README.md",
"chars": 367,
"preview": "# PythonLearningNote\n#Python 进阶学习笔记\n当年学了点Python2 ,那时候听说什么Python3 失去了Python的灵魂,就没管Python3 。\n最近因为项目需要使用Python3,又把当年的那份热血花在"
},
{
"path": "SVM 原理详解.md",
"chars": 24344,
"preview": "---\ntitle: SVM原理详解\ndate: 2019-3-19 17:57:14\ntags: \n\t- python\n\t- MachineLearning\ntoc:\n\tture\n---\n\n\n\n\n\n# SVM 原理详解\n\n<div sty"
},
{
"path": "TensorFlow 安装总结.md",
"chars": 12638,
"preview": "---\ntitle: TensorFlow 安装总结\ndate: 2019-3-22 12:30:24\ntags: \n\t- python\n\t- TensorFlow\n\t- MachineLearning\ntoc:\n\tture\n---\n\n\n#"
},
{
"path": "数据预处理之One-Hot(独热编码)编码.md",
"chars": 1810,
"preview": "---\ntitle: 数据预处理之One-Hot(独热编码)编码\ndate: 2019-03-18 17:36:48\ntags:\n\t- python\n\t- MachineLearning\ntoc:\n\ttrue\n---\n\n# 数据预处理之On"
}
]
About this extraction
This page contains the full source code of the LiuQixuan/PythonLearningNote GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (868.4 KB), approximately 571.7k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.