对Python中plt的画图函数详解

yipeiwu_com6年前Python基础

1、plt.legend

plt.legend(loc=0)#显示图例的位置,自适应方式
说明:

'best'   : 0, (only implemented for axes legends)(自适应方式)
'upper right' : 1,
'upper left' : 2,
'lower left' : 3,
'lower right' : 4,
'right'  : 5,
'center left' : 6,
'center right' : 7,
'lower center' : 8,
'upper center' : 9,
'center'  : 10,

2、plt.figure

plt.figure(figsize=(14, 6), dpi=80)#设置绘图区域的大小和像素

3、plt.xticks

plt.xticks(new_year)#设置x轴的刻度线为new_year,new_year可以为数组

4、plt.xlabel

plt.xlabel('year')#x轴标签

5、plt.plot

plt.plot(number, color='blue', label="actual value")#将实际值的折线设置为蓝色

6、两个图分开

fig, axes = plt.subplots(2, 1, sharex=True,figsize=(10,10))
axes[0].plot(range (len(data20)),data20,'r')
axes[1].plot(range (len(data40)),data40,'b') 

7、画竖直线

plt.axvline(99, linestyle="dotted", linewidth=4, color='r')#99表示横坐标

8、图片保存

plt.savefig('timeseries_y.jpg')

以上这篇对Python中plt的画图函数详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

pandas中的series数据类型详解

本文介绍了pandas中的series数据类型详解,分享给大家,具体如下: import pandas as pd import numpy as np import names...

Python3.5以上版本lxml导入etree报错的解决方案

Python3.5以上版本lxml导入etree报错的解决方案

在python中安装了lxml-4.2.1,在使用时发现导入etree时IDE中报错Unresolved reference 其实发现,不影响使用,可以正常运行,对于我这种要刨根问底的...

python 测试实现方法

 1)doctest 使用doctest是一种类似于命令行尝试的方式,用法很简单,如下 复制代码 代码如下:def f(n): """ >>> f(1) 1...

windows下cx_Freeze生成Python可执行程序的详细步骤

windows下cx_Freeze生成Python可执行程序的详细步骤

目前网上能获取的免费的python打包工具主要有三种:py2exe、PyInstaller和cx_Freeze。 下面简单介绍windows7下cx_Freeze打包python生成可执...

学习python分支结构

分支结构的应用场景 迄今为止,我们写的Python代码都是一条一条语句顺序执行,这种结构的代码我们称之为顺序结构。然而仅有顺序结构并不能解决所有的问题,比如我们设计一个游戏,游戏第一关...