python学习(17)--Matplotlib
来源:互联网 发布:金融行业数据服务企业 编辑:程序博客网 时间:2024/06/12 01:34
Matplotlib是一个画图库,这一节我们提供了简明的教程,使用类似于MATLAB.
画图
matplotlib最重要的函数就是plot,可以让你画出2D的图。例如:
import numpy as npimport matplotlib.pyplot as plt# Compute the x and y coordinates for points on a sine curvex = np.arange(0, 3 * np.pi, 0.1)y = np.sin(x)# Plot the points using matplotlibplt.plot(x, y)plt.show() # You must call plt.show() to make graphics appear.
运行后得到如下图:
我们还可以添加标题,轴坐标等:
import numpy as npimport matplotlib.pyplot as plt# Compute the x and y coordinates for points on sine and cosine curvesx = np.arange(0, 3 * np.pi, 0.1)y_sin = np.sin(x)y_cos = np.cos(x)# Plot the points using matplotlibplt.plot(x, y_sin)plt.plot(x, y_cos)plt.xlabel('x axis label')plt.ylabel('y axis label')plt.title('Sine and Cosine')plt.legend(['Sine', 'Cosine'])plt.show()
得到如下图:
更多信息可以查看此文档
子图
你也可以画不同类型的子图,例如:
import numpy as npimport matplotlib.pyplot as plt# Compute the x and y coordinates for points on sine and cosine curvesx = np.arange(0, 3 * np.pi, 0.1)y_sin = np.sin(x)y_cos = np.cos(x)# Set up a subplot grid that has height 2 and width 1,# and set the first such subplot as active.plt.subplot(2, 1, 1)# Make the first plotplt.plot(x, y_sin)plt.title('Sine')# Set the second subplot as active, and make the second plot.plt.subplot(2, 1, 2)plt.plot(x, y_cos)plt.title('Cosine')# Show the figure.plt.show()
得到如下图:
更多信息请查看此文档
图片
可以使用imshow函数来展示图片。例如:
import numpy as npfrom scipy.misc import imread, imresizeimport matplotlib.pyplot as pltimg = imread('assets/cat.jpg')img_tinted = img * [1, 0.95, 0.9]# Show the original imageplt.subplot(1, 2, 1)plt.imshow(img)# Show the tinted imageplt.subplot(1, 2, 2)# A slight gotcha with imshow is that it might give strange results# if presented with data that is not uint8. To work around this, we# explicitly cast the image to uint8 before displaying it.plt.imshow(np.uint8(img_tinted))plt.show()
结果如图:
阅读全文
1 0
- python学习(17)--Matplotlib
- python学习(三):matplotlib学习
- python学习(三):matplotlib学习
- Python学习笔记(一)--- Matplotlib
- Python模块学习系列(4)----matplotlib
- python之matplotlib学习
- Python--Matplotlib学习1
- python可视化-matplotlib学习
- Python-matplotlib学习
- python之matplotlib学习(一)
- python机器学习库 :matplotlib
- 《python科学计算》matplotlib学习
- python-matplotlib学习笔记37
- [python]matplotlib的快速学习
- 机器学习九 python matplotlib
- python Matplotlib 学习笔记(1)
- python Matplotlib 学习笔记(2)
- python可视化-matplotlib学习2
- 2440裸机编程之 触摸屏
- ADC&触摸屏
- miniui(nui)进度条
- keil MDK编译器警告和错误详解
- S3c2440ALCD控制器配置实例
- python学习(17)--Matplotlib
- 不同的LCD之间程序移植时配置参考
- RealView MDK在链接时提示空间不够的解决方案总结
- mini2440裸机之PWM
- s3c2440的pwm输出
- EMC磁珠到底是什么特性?
- 对增益大于等于10时保持稳定的放大器进行补偿以在较低增益下工作
- 电子技术的老生常谈——接地
- msp430f149单片机控制步进电机C语言程序