首先补充一下:两种体系7种颜色 r g b y m c k (红,绿,蓝,黄,品红,青,黑)

在科研的过程中,坐标系中的XY不一定就是等尺度的。例如在声波中对Y轴取对数。肆意我们也必须知道这种坐标系如何画出来的。

 1:对数坐标图

有3个函数可以实现这种功能,分别是:semilogx(),semilogy(),loglog()。它们分别表示对X轴,Y轴,XY轴取对数。下面在一个2*2的figure里面来比较这四个子图(还有plot())。

[python] 
  1. <span style="font-size:14px;">  1 import numpy as np
  2. 2 import matplotlib.pyplot as plt
  3. 3 w=np.linspace(0.1,1000,1000)
  4. 4 p=np.abs(1/(1+0.1j*w))
  5. 5
  6. 6 plt.subplot(221)
  7. 7 plt.plot(w,p,lw=2)
  8. 8 plt.xlabel('X')
  9. 9 plt.ylabel('y')
  10. 10
  11. 11
  12. 12 plt.subplot(222)
  13. 13 plt.semilogx(w,p,lw=2)
  14. 14 plt.ylim(0,1.5)
  15. 15 plt.xlabel('log(X)')
  16. 16 plt.ylabel('y')
  17. 17
  18. 18 plt.subplot(223)
  19. 19 plt.semilogy(w,p,lw=2)
  20. 20 plt.ylim(0,1.5)
  21. 21 plt.xlabel('x')
  22. 22 plt.xlabel('log(y)')
  23. 23
  24. 24 plt.subplot(224)
  25. 25 plt.loglog(w,p,lw=2)
  26. 26 plt.ylim(0,1.5)
  27. 27 plt.xlabel('log(x)')
  28. 28 plt.xlabel('log(y)')
  29. 29 plt.show()
  30. </span>

如上面的代码所示,对一个低通滤波器函数绘图。得到四个不同坐标尺度的图像。如下图所示:

2,极坐标图像
    极坐标系中的点由一个夹角和一段相对于中心位置的距离来表示。其实在plot()函数里面本来就有一个polar的属性,让他为True就行了。下面绘制一个极坐标图像:

[python] view plaincopy
  1. 1 import numpy as np
  2. 2 import matplotlib.pyplot as plt
  3. 3
  4. 4 theta=np.arange(0,2*np.pi,0.02)
  5. 5
  6. 6 plt.subplot(121,polar=True)
  7. 7 plt.plot(theta,2*np.ones_like(theta),lw=2)
  8. 8 plt.plot(theta,theta/6,'--',lw=2)
  9. 9
  10. 10 plt.subplot(122,polar=True)
  11. 11 plt.plot(theta,np.cos(5*theta),'--',lw=2)
  12. 12 plt.plot(theta,2*np.cos(4*theta),lw=2)
  13. 13 plt.rgrids(np.arange(0.5,2,0.5),angle=45)
  14. 14 plt.thetagrids([0,45,90])
  15. 15
  16. 16 plt.show()
  17. ~

整个代码很好理解,在后面的13,14行没见过。第一个plt.rgrids(np.arange(0.5,2,0.5),angle=45) 表示绘制半径为0.5 1.0 1.5的三个同心圆,同时将这些半径的值标记在45度位置的那个直径上面。plt.thetagrids([0,45,90]) 表示的是在theta为0,45,90度的位置上标记上度数。得到的图像是:



3,柱状图:

核心代码matplotlib.pyplot.bar(left, height, width=0.8, bottom=None, hold=None, **kwargs)里面重要的参数是左边起点,高度,宽度。下面例子:

[python] view plaincopy
  1. 1 import numpy as np
  2. 2 import matplotlib.pyplot as plt
  3. 3
  4. 4
  5. 5 n_groups = 5
  6. 6
  7. 7 means_men = (20, 35, 30, 35, 27)
  8. 8 means_women = (25, 32, 34, 20, 25)
  9. 9
  10. 10 fig, ax = plt.subplots()
  11. 11 index = np.arange(n_groups)
  12. 12 bar_width = 0.35
  13. 13
  14. 14 opacity = 0.4
  15. 15 rects1 = plt.bar(index, means_men, bar_width,alpha=opacity, color='b',label=    'Men')
  16. 16 rects2 = plt.bar(index + bar_width, means_women, bar_width,alpha=opacity,col    or='r',label='Women')
  17. 17
  18. 18 plt.xlabel('Group')
  19. 19 plt.ylabel('Scores')
  20. 20 plt.title('Scores by group and gender')
  21. 21 plt.xticks(index + bar_width, ('A', 'B', 'C', 'D', 'E'))
  22. 22 plt.ylim(0,40)
  23. 23 plt.legend()
  24. 24
  25. 25 plt.tight_layout()
  26. 26 plt.show()

得到的图像是:

再贴一图:

这是我关于pose识别率的实验结果,感觉结果真是令人不可思议!(非博主原文!)

[python] view plaincopy
  1. def drawBarChartPoseRatio():
  2. n_groups = 5
  3. means_VotexF36 = (0.84472049689441, 0.972477064220183, 1.0, 0.9655172413793104, 0.970970970970971)
  4. means_VotexF50 = (1.0,              0.992992992992993, 1.0, 0.9992348890589136, 0.9717125382262997)
  5. means_VFH36    = (0.70853858784893, 0.569731081926204, 0.8902900378310215, 0.8638638638638638, 0.5803008248423096)
  6. means_VFH50    = (0.90786948176583, 0.796122576610381, 0.8475120385232745, 0.8873762376237624, 0.5803008248423096)
  7. fig, ax = plt.subplots()
  8. index = np.arange(n_groups)
  9. bar_width = 0.3
  10. opacity   = 0.4
  11. rects1 = plt.bar(index,             means_VFH36,    bar_width/2, alpha=opacity, color='r', label='VFH36'   )
  12. rects2 = plt.bar(index+ bar_width/2,  means_VFH50,  bar_width/2, alpha=opacity, color='g', label='VFH50'   )
  13. rects3 = plt.bar(index+bar_width, means_VotexF36,     bar_width/2, alpha=opacity, color='c', label='VotexF36')
  14. rects4 = plt.bar(index+1.5*bar_width, means_VotexF50, bar_width/2, alpha=opacity, color='m', label='VotexF50')
  15. plt.xlabel('Category')
  16. plt.ylabel('Scores')
  17. plt.title('Scores by group and Category')
  18. #plt.xticks(index - 0.2+ 2*bar_width, ('balde', 'bunny', 'dragon', 'happy', 'pillow'))
  19. plt.xticks(index - 0.2+ 2*bar_width, ('balde', 'bunny', 'dragon', 'happy', 'pillow'),fontsize =18)
  20. plt.yticks(fontsize =18)  #change the num axis size
  21. plt.ylim(0,1.5)  #The ceil
  22. plt.legend()
  23. plt.tight_layout()
  24. plt.show()

柱状图显示:

4:散列图,由离散的点构成的。

函数是:

matplotlib.pyplot.scatter(x, y, s=20, c='b', marker='o', cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, hold=None,**kwargs),其中,xy是点的坐标,s点的大小,maker是形状可以maker=(5,1)5表示形状是5边型,1表示是星型(0表示多边形,2放射型,3圆形);alpha表示透明度;facecolor=‘none’表示不填充。例子如下:

[python] view plaincopy
  1. 1 import numpy as np
  2. 2 import matplotlib.pyplot as plt
  3. 3
  4. 4 plt.figure(figsize=(8,4))
  5. 5 x=np.random.random(100)
  6. 6 y=np.random.random(100)
  7. 7 plt.scatter(x,y,s=x*1000,c='y',marker=(5,1),alpha=0.5,lw=2,facecolors='none')
  8. 8 plt.xlim(0,1)
  9. 9 plt.ylim(0,1)
  10. 10
  11. 11 plt.show()

上面代码的facecolors参数使得前面的c=‘y’不起作用了。图像:

5,3D图像,主要是调用3D图像库。看下面的例子:

[python] view plaincopy
  1. 1 import numpy as np
  2. 2 import matplotlib.pyplot as plt
  3. 3 import mpl_toolkits.mplot3d
  4. 4
  5. 5 x,y=np.mgrid[-2:2:20j,-2:2:20j]
  6. 6 z=x*np.exp(-x**2-y**2)
  7. 7
  8. 8 ax=plt.subplot(111,projection='3d')
  9. 9 ax.plot_surface(x,y,z,rstride=2,cstride=1,cmap=plt.cm.coolwarm,alpha=0.8)
  10. 10 ax.set_xlabel('x')
  11. 11 ax.set_ylabel('y')
  12. 12 ax.set_zlabel('z')
  13. 13
  14. 14 plt.show()

得到的图像如下图所示:

到此,matplotlib基本操作的学习结束了,相信大家也可以基本完成自己的科研任务了。

Python:Matplotlib 画图相关推荐

  1. python画图中文显示_解决Linux系统中python matplotlib画图的中文显示问题

    最近想学习一些python数据分析的内容,就弄了个爬虫爬取了一些数据,并打算用Anaconda一套的工具(pandas, numpy, scipy, matplotlib, jupyter)等进行一些 ...

  2. python matplotlib画图产生的Type 3 fonts字体没有嵌入问题

    ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...

  3. Python matplotlib画图出现No handles with labels found to put in legend

    1.在使用Python matplotlib画图出现No handles with labels found to put in legend ,在本地调试时并不会出现这个错误,而部署到线上服务器之后 ...

  4. 解决Linux系统中python matplotlib画图的中文显示问题

    解决Linux系统中python matplotlib画图的中文显示问题 参考文章: (1)解决Linux系统中python matplotlib画图的中文显示问题 (2)https://www.cn ...

  5. python word保存图_使用python matplotlib 画图导入到word中如何保证分辨率

    在写论文时,如果是菜鸟级别,可能不会花太多时间去学latex,直接用word去写,但是这有一个问题,当我们用其他工具画完实验彩色图时,放到word中会有比较模糊,这有两个原因导致的. 原因一:图片导入 ...

  6. python画图模糊_使用python matplotlib 画图导入到word中如何保证分辨率

    在写论文时,如果是菜鸟级别,可能不会花太多时间去学latex,直接用word去写,但是这有一个问题,当我们用其他工具画完实验彩色图时,放到word中会有比较模糊,这有两个原因导致的. 原因一:图片导入 ...

  7. python matplotlib 画图 不显示中文 中文乱码 设置中文字体

    在使用python matplotlib 画图时,由于matplotlib 默认是使用DejaVu Sans这种字体,不支持中文,所以我们在使用matplotlib画图包含中文内容要显示时就会变成方框 ...

  8. Python matplotlib 画图 显示中文 中文乱码 无法显示负号

    Python matplotlib 画图 显示中文 中文乱码 无法显示负号 import matplotlib.pyplot as pltplt.rcParams["font.sans-se ...

  9. 环境搭建:使用python matplotlib画图不显示中文问题解决

    1.背景 python matplotlib.plt 使用 plt.title 写标题时,标题显示为方框,无法正常显示中文,而且基本上在一台新的服务器上配置python开发环境都会遇到这种问题,因此写 ...

  10. python matplotlib画图的几个实例--latex,坐标系等

    文章目录 实例1 学会使用tex/latex 实例2 学会画坐标轴 2.1过程 2.2 典型例子 2.2.1 一条带箭头的竖线 2.2.2 坐标系 2.2.3 坐标系上画三角函数 实例1 学会使用te ...

最新文章

  1. html 资源缓存,解决index.html缓存问题
  2. 图像处理和模式识别等技术的快速发展大大地推动了机器视觉的发展
  3. [密码学基础][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第2篇]多核处理器和向量处理器的区别
  4. python读取doc文件_Linux 下Python 读取Word文档内容的方法
  5. pandas数据处理实践五(透视表pivot_table、分组和透视表实战Grouper和pivot_table)
  6. MATLAB与word的交互
  7. 规模再创新高!新能源汽车蓝海谁主沉浮
  8. 《鬼谷子》捭阖第一(翻译)
  9. Win10禁用缩略图解决资源管理器老是重启
  10. 计算机的记事本和写字板的功能,写字板和记事本的异同
  11. Python——时间与时间戳之间的转换
  12. 电脑视频加水印怎么加?
  13. access设计视图打不开_15、ACCESS总计查询(分组查询)设计(ACCESS图解操作系列)...
  14. 揭秘IPHONE X刷脸认证的技术奥秘
  15. nodejs学习五:sequelize数据库查询的Op方法
  16. 【3】IMU模块:PA-IMU-460 ROS驱动 + 与GNSS时间同步
  17. vue + elemen可远程搜索select选择器的封装(思路及源码分享)
  18. 小飞鱼通达二开 解决通达OA数据库服务不能启动的问题(图文)
  19. fcpx插件:童年印象回忆复古视觉特效和转场Stupid Raisins Slide Pop
  20. 阅读text2sql论文《RAT-SQL: Relation-Aware Schema Encoding and Linking for Text-to-SQL Parsers》

热门文章

  1. H5JS二维动画制作!two.js的基本操作class2
  2. 《CCNA学习指南:Cisco网络设备互连(ICND1)(第4版)》——2.11节生产网络模拟问题2-1...
  3. oracle_dblink配置
  4. 使用GDB进行系统调用过程简析
  5. 应用:Xbox 360无线大屏幕控制器“WP 7”
  6. 利用PyInstaller打包exe文件
  7. 使用ServletContextListener关闭Redisson连接
  8. 如何离线下载Chrome的安装包
  9. 提高性能及操作硬件的能力
  10. 使用ExtJs实现文件下载