python matplotlib 画图

来源:互联网 发布:如何使用spss分析数据 编辑:程序博客网 时间:2024/05/17 08:59

python matplotlib 画图


author@jason_ql(lql0716)
http://blog.csdn.net/lql0716


1、代码

# -*- coding: utf-8 -*-"""Created on Thu Jul 06 21:59:39 2017@author: lql0716"""import numpy as npimport matplotlib.pyplot as pltx = np.arange(-20,20)  #自变量xy = x**2  #变量yplt.figure(num = 3, figsize = (8, 12), dpi = 100) #设置画图的图片的大小,figsize大概为厘米尺寸,分辨率dpiplt.plot(x, y, 'r*', label = 'line', linewidth = 3)plt.title('Function')  # 标题plt.xlabel('x (cm)')  # x轴的名称plt.ylabel('y (cm)')  # y轴的名称xt = np.arange(-20,20, 10) #设置x轴刻度步长plt.xticks(xt)yt = np.arange(0, 400, 20) #设置y轴刻度步长plt.yticks(yt)plt.legend(loc = 0) #参数loc,设置label在图中的位置,含义如下#'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,plt.grid(True)  #True表示显示网格线,其它参数linestyle 设置线显示的类型(一共四种), color 设置网格的颜色, linewidth 设置网格的宽度#plt.grid(True, linestyle = "-.", color = "r", linewidth = "3")  plt.savefig("D:/photo/1-1.jpg")  #保存绘制的图片plt.show()    

2、效果图

这里写图片描述

原创粉丝点击