matplotlib plot( ) 绘制简单折线图
2017-11-22 20:44
776 查看
matplotlib plot 绘制简单折线图
1. example 1import matplotlib.pyplot as plt squares = [1, 4, 9, 16, 25] plt.plot(squares) plt.show()
2. example 2
# example 2 import matplotlib.pyplot as plt squares = [1, 4, 9, 16, 25] plt.plot(squares, linewidth=5) plt.title("Square Numbers", fontsize=24) plt.xlabel("Value", fontsize=14) plt.ylabel("Square of Value", fontsize=14) plt.tick_params(axis='both', labelsize=14) plt.show()
参数 linewidth 决定了 plot( ) 绘制的线条的粗细。函数 title( ) 给图表指定标题。在上述代码中,出现了多次的参数 fontsize 指定了图表中文字的大小。
函数 xlabel( ) 和 ylabel( ) 让你能够为每条轴设置标题;而函数 tick_params( ) 设置刻度的样式,其中指定的实参将影响 x 轴和 y 轴上的刻度 (axes='both'),并将刻度标记的字号设置为14 (labelsize=14)。
3. example 3
当你向 plot( ) 提供一系列数字时,它假设第一个数据点对应的 x 坐标值为0,但我们的第一个点对应的 x 值为1。为改变这种默认行为,我们可以给plot( ) 同时提供输入值和输出值。
import matplotlib.pyplot as plt input_values = [1, 2, 3, 4, 5] squares = [1, 4, 9, 16, 25] plt.plot(input_values, squares, linewidth=5) plt.title("Square Numbers", fontsize=24) plt.xlabel("Value", fontsize=14) plt.ylabel("Square of Value", fontsize=14) plt.tick_params(axis='both', labelsize=14) plt.show()
4. example 4
5. example 5
相关文章推荐
- python 数据可视化 matplotlib学习一:绘制简单的折线图
- matplotlib入门-绘制简单折线图
- 使用matplotlib绘制简单的折线图
- matplotlib绘制折线图与散点图
- python+matplotlib绘制简单的海豚(顶点和节点的操作)
- 画图工具matplotlib简单实用--绘制散点图
- matplotlib入门——绘制简单图形
- wxPython+Matplotlib绘制折线图表
- Python通过matplotlib绘制动画简单实例
- Python开发【模块】:matplotlib 绘制折线图
- matplotlib学习—绘制简单自定义曲线
- 练习: bs4 简单爬取 + matplotlib 折线图显示 (关键词,职位数量、起薪)
- python使用matplotlib绘制折线图教程
- Python-Matplotlib绘制简单图像
- matplotlib绘制简单图
- 使用python matplotlib绘制简单图形
- python使用matplotlib绘制折线图教程
- python实战二:使用CSV数据绘制带数据标志的折线图(matplotlib)
- 【Python】matplotlib绘制折线图
- 【Python-3.5】matplotlib做简单折线图