对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设计】。

相关文章

Python将主机名转换为IP地址的方法

关于主机名转IP地址只记住两点即可: 1、英特网协议一直都是用4字节的IP将包转发给目的地; 2、至于主机名是如何转换成IP地址的,这是操作系统关心的事情; import socke...

使用Python操作FTP实现上传和下载的方法

搭建ftp服务器server端 # -*- coding:utf-8 -*- from pyftpdlib.authorizers import DummyAuthorizer fr...

用python实现的可以拷贝或剪切一个文件列表中的所有文件

复制代码 代码如下:# coding:utf-8 import os import sys def cut_and_paste_file(source, destination): &n...

python保存log日志,实现用log日志画图

在神经网络训练中,我们常常需要画出loss function的变化图,log日志里会显示每一次迭代的loss function的值,于是我们先把log日志保存为log.txt文档,再利用...

Python计算开方、立方、圆周率,精确到小数点后任意位的方法

Python计算开方、立方、圆周率,精确到小数点后任意位的方法

Python计算的位数 在电脑上做了一个实验,看看python能计算到多少位,一下是结果。 x = math.sqrt((3)) print ("%.53f"%(x)) print...