
使用 matplotlib 通过 Python 从文件中读取并绘制 x, y 坐标的方法
5星
- 浏览量: 0
- 大小:None
- 文件类型:PDF
简介:
本教程介绍如何利用Python中的matplotlib库,从文件中读取数据,并将x,y坐标绘制成图表,适合初学者学习实践。
1. `test.txt` 文件中的数据以逗号分隔:第一列是 x 坐标,第二列是 y 坐标。文件内容如下:
```
1.1,2
2.1,2
3.1,3
4.1,5
40,38
42,41
43,42
```
2. Python 部分代码:
```python
#!/usr/bin/python
# coding: utf-8
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
mpl.rcParams[font.family] = sans-serif
mpl.rcParams[font.sans-serif] = [NSimSun, T]
```
请注意,`mpl.rcParams[font.family]` 和 `mpl.rcParams[font.sans-serif]` 的语法需要更正为 `font.family` 和 `font.sans-serif`。
全部评论 (0)
还没有任何评论哟~


