对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中迭代器(iterator)用法实例分析

本文实例讲述了python中迭代器(iterator)用法。分享给大家供大家参考。具体如下: #--------------------------------------- #...

python tensorflow基于cnn实现手写数字识别

一份基于cnn的手写数字自识别的代码,供大家参考,具体内容如下 # -*- coding: utf-8 -*- import tensorflow as tf from tenso...

不知道这5种下划线的含义,你就不算真的会Python!

不知道这5种下划线的含义,你就不算真的会Python!

什么是 Python? Python 之父 Guido van Rossum 说:Python是一种高级程序语言,其核心设计哲学是代码可读性和语法,能够让程序员用很少的代码来表达自己的想...

django的csrf实现过程详解

django的csrf实现过程详解

如果是ajax提交,可以按照下面的方式处理 <script src="/static/jq/jquery-3.3.1.js"></script> <s...

ipython和python区别详解

ipython和python区别详解

ipython介绍 IPython 是一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell命令,内...