详细内容参看:官网


测试数据:

# 传入的参数
x=[1,2,3,4,5]
squares=[1,4,9,16,25]

简单的绘图

import matplotlib.pyplot as plt

def plot1(x,squares):
"""plot simple pic""" plt.plot(x,squares,linewidth=1)
# or plt.plot(squares) plt.show()
  • plt.plot(x,y)
  • plt.show()

改变文字、字体、线宽

def plot2(x,squares):
"""change literature and line width"""
plt.plot(x,squares,linewidth=2) plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14) # set labelsize of x, y
plt.tick_params(axis='both',labelsize=14) plt.show()
  • plt.title("title")
  • plt.xlabel('xlabel')
  • plt.ylabel('ylabel')
  • plt.tick_params(axis,labelsize)

自动生成数据

def plot3():
"""automatically compute the data"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val] plt.scatter(x_val,y_val,s=5) plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14) # set labelsize of x, y
plt.tick_params(axis='both',labelsize=14) plt.axis([0,1100,0,1100000]) plt.show()
  • plt.axis([0,1100,0,110000])
  • plt.scatter(x,y,s)

颜色改变(很漂亮)

def plot4():
"""change the color"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val] # delete the default edgecolor(black)
# change color by adjusting c
plt.scatter(x_val,y_val,edgecolor='none',c=(0.5,0.6,0.3),s=5) plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14) # set labelsize of x, y
plt.tick_params(axis='both',labelsize=14) plt.axis([0,1100,0,1100000]) plt.show()
  • plt.scatter(x,y,edgecolor='none',c,s)

    • c用来调节颜色
    • s代表size
def plot5():
"""using colormap"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val] # delete the default edgecolor(black)
# using cmap to make gradient
plt.scatter(x_val,y_val,edgecolor='none',c=y_val,s=5,cmap=plt.cm.Blues) plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14) # set labelsize of x, y
plt.tick_params(axis='both',labelsize=14) plt.axis([0,1100,0,1100000]) plt.show()
  • plt.scatter(x,y,edgecolor,c,s,cmap)

    • cmap颜色映射

      • plt.cm.Blues
      • plt.cm.Reds
      • plt.cm.Greens
      • plt.cm.Paired
      • plt.cm.binary
      • plt.cm.seismic

保存图片

def plot6():
"""using colormap"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val] # delete the default edgecolor(black)
# using cmap to make gradient
# cmap(plt.cm.*) Blues Reds Greens Paired binary seismic
plt.scatter(x_val,y_val,edgecolor='none',c=y_val,s=5,cmap=plt.cm.seismic) plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14) # set labelsize of x, y
plt.tick_params(axis='both',labelsize=14) plt.axis([0,1100,0,1100000]) # do not show, save it
plt.savefig('save.png',bbox_inches='tight')
  • plt.savefig('name.jpg',bbox_inches)

    • 一般bbox_inches='tight'比较好

python应用-matplotlib绘图的更多相关文章

  1. python 中matplotlib 绘图

    python 中matplotlib 绘图 数学建模需要,对于绘图进行简单学习 matpoltlib之类的包安装建议之间用anaconda 绘制一条y=x^2的曲线 #比如我们要绘制一条y=x^2的曲 ...

  2. python之matplotlib绘图基础

    Python之matplotlib基础 matplotlib是Python优秀的数据可视化第三方库 matplotlib库的效果可参考 http://matplotlib.org/gallery.ht ...

  3. python基于matplotlib绘图

    import math import numpy as np import matplotlib.pyplot as plt from matplotlib.font_manager import F ...

  4. python中matplotlib绘图封装类之折线图、条状图、圆饼图

    DrawHelper.py封装类源码: import matplotlib import matplotlib.pyplot as plt import numpy as np class DrawH ...

  5. Python用matplotlib绘图网格线的设置

    一.X轴网格线的设置 import matplotlib.pyplot as plt import numpy as np from pylab import mpl mpl.rcParams['fo ...

  6. python中利用matplotlib绘图可视化知识归纳

    python中利用matplotlib绘图可视化知识归纳: (1)matplotlib图标正常显示中文 import matplotlib.pyplot as plt plt.rcParams['fo ...

  7. python 利用matplotlib中imshow()函数绘图

    matplotlib 是python最著名的2D绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中.通过简单的绘图语 ...

  8. python实战学习之matplotlib绘图

    matplotlib 是最流行的Python底层绘图库,主要做数据可视化图表 可以将数据可视化,能够更直观的呈现数据 matplotlib绘图基本要点 首先实现一个简单的绘图 # 导入pyplot f ...

  9. python强大的绘图模块matplotlib示例讲解

    Matplotlib 是 Python 的绘图库.作为程序员,经常需要进行绘图,在我自己的工作中,如果需要绘图,一般都是将数据导入到excel中,然后通过excel生成图表,这样操作起来还是比较繁琐的 ...

随机推荐

  1. Minix2.0内核源代码的组织结构

    Minix2.0操作系统的源代码由两个目录组成:include/目录和src/目录 include/目录包含了操作系统所有的头文件(即.h文件) src/目录下包含了操作系统所有的源文件(.c或.s文 ...

  2. springMVC各个包下的作用

    spring的jar各包作用spring.jar是包含有完整发布的单个jar包,spring.jar中包含除了spring-mock.jar里所包含的内容外其它所有jar包的内容,因为只有在开发环境下 ...

  3. goole进不去?

    1.把hosts文件放到C:\Windows\System32\drivers\etc目录下就可以上了.hosts文件自己下载 2. 上vpn ,注册个账号,每个账号500M的FQ流量也可以

  4. U盘安装Win7系统,遇到硬盘鼠标键盘失灵等情况,如何安装U盘中加入USB3.0驱动的支持

    U盘安装系统出现鼠标键盘不能使用,在intel六代处理器平台,安装过程中会出现安装原生镜像不能识别或者鼠标键盘不能使用等情况,可以参考以下方法进行. 风险提示:重装或升级系统会导致系统盘数据丢失,建议 ...

  5. vue监听滚动事件

    vue中监听滚动事件,然后对其进行事件处理,一般有:1. 滚动到顶部吸附: 2. 根据滚动的位置激活对应的tab键(锚链接tab键) 这两种方式的处理都是可通过监听scroll来实现 mounted( ...

  6. Shell--基础知识

    变量的定义: a=1 b=hello c="hello world !" d='hello "反启" !' e=`ls`  (注意:这是反引号) 备注:=号左右 ...

  7. Oracle之catalog恢复目录的创建于维护(51CTO风哥rman课程)

    catalog恢复目录配置过程 1,创建一个表空间 2,创建rman用户并授权 3,创建恢复目录 4,配置TNS 5,注册数据库 6,检查 创建ramn表空间 首先查看一下其他表空间位置 create ...

  8. CSU 1808 地铁 (Dijkstra)

    Description Bobo 居住在大城市 ICPCCamp. ICPCCamp 有 n 个地铁站,用 1,2,-,n 编号. m 段双向的地铁线路连接 n 个地铁站,其中第 i 段地铁属于 ci ...

  9. 2017ACM-ICPC沈阳区域赛

    I-Little Boxes[大数] hdu6225  http://acm.hdu.edu.cn/showproblem.php?pid=6225 题意: 就是给四个大数,输出和. 思路: java ...

  10. JSON_CONTAINS

    select * from tb    where info->'$.name' = '特价促销'  or JSON_CONTAINS(info->'$[*].name', '" ...