python matplotlib
2017-11-09 16:30
351 查看
____tz_zs笔记
https://matplotlib.org
Matplotlib 是一个 Python 2D 绘图库,可以在各种平台上以各种硬拷贝格式和交互式环境生成出版质量数据,专为轻松生成简单而强大的可视化而量身定制。
"""
@author: tz_zs
图片读取、显示与保存
使用matplotlib
"""
import matplotlib.pyplot as plt
img = plt.imread('53788-106.jpg')
print(type(img)) # <class 'numpy.ndarray'>
print(img)
'''''
[[[255 255 255]
[255 255 255]
[255 255 255]
...,
...,
[163 138 108]
[156 131 101]
[153 128 98]]]
'''
plt.imshow(img)
plt.show()
plt.imsave('./1.jpg', img)
·
"""
@author: tz_zs
"""
import matplotlib.pyplot as plt
# x, y分别是x坐标和y坐标的列表
x = [1, 2, 3, 4]
y = [2, 3, 4, 5]
plt.scatter(x, y)
plt.show()·
·# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import matplotlib.pyplot as plt
import numpy as np
y = np.random.standard_normal((600, 2))
print(y.shape)
plt.figure(figsize=(7, 7)) # 绘制图形的画板尺寸(约为700像素×700像素)
plt.scatter(y[:, 0], y[:, 1], marker='o') # marker是指定点标记的形状,marker='o'表示圈
plt.grid(True) # 表示图形添加网格
plt.xlabel("1st") # X轴加标签‘1st’
plt.ylabel("2nd") # 表示给Y轴加标签‘2nd’
plt.title("Scatter Plot") # 图形加标题‘Scatter Plot’
plt.show()·
·
scatter函数参数详解
需要对数据进行分组,然后统计每个分组内数据的数量。
# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import numpy as np
import matplotlib.pyplot as plt
x = np.random.randint(0, 100, 50) # 数据列表
print(x)
"""
[68 67 16 92 68 26 68 87 60 21 63 29 18 73 49 65 44 19 22 73 12 76 93 35 39
69 0 18 34 31 29 31 51 32 25 44 32 8 83 93 24 15 78 83 15 25 36 53 24 80]
"""
bins = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100] # 分组边界
plt.hist(x=x, bins=bins)
plt.xlabel('x')
plt.ylabel('y')
plt.title('title')
plt.show()
https://blog.csdn.net/gatieme/article/details/61416645
https://blog.csdn.net/you_are_my_dream/article/details/53439518
子图:就是在一张figure里面生成多张子图。
Matplotlib对象简介
FigureCanvas 画布
Figure 图
Axes 坐标轴(实际画图的地方)
·# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import numpy as np
import matplotlib.pyplot as plt
square = np.zeros((32, 32))
square[5:10, 5:10] = 1
plt.subplot(221)
plt.imshow(square)
square[15:20, 5:10] = 1
plt.subplot(222)
plt.imshow(square)
square[5:10, 15:20] = 1
plt.subplot(223)
plt.imshow(square)
square[15:20, 15:20] = 1
plt.subplot(224)
plt.imshow(square)
plt.show()
·
·
其他:
【Matplotlib】详解图像各个部分
https://matplotlib.org
Matplotlib 是一个 Python 2D 绘图库,可以在各种平台上以各种硬拷贝格式和交互式环境生成出版质量数据,专为轻松生成简单而强大的可视化而量身定制。
图片读取、显示与保存
·# -*- coding: utf-8 -*-"""
@author: tz_zs
图片读取、显示与保存
使用matplotlib
"""
import matplotlib.pyplot as plt
img = plt.imread('53788-106.jpg')
print(type(img)) # <class 'numpy.ndarray'>
print(img)
'''''
[[[255 255 255]
[255 255 255]
[255 255 255]
...,
...,
[163 138 108]
[156 131 101]
[153 128 98]]]
'''
plt.imshow(img)
plt.show()
plt.imsave('./1.jpg', img)
·
散点图绘制
# -*- coding: utf-8 -*-"""
@author: tz_zs
"""
import matplotlib.pyplot as plt
# x, y分别是x坐标和y坐标的列表
x = [1, 2, 3, 4]
y = [2, 3, 4, 5]
plt.scatter(x, y)
plt.show()·
·# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import matplotlib.pyplot as plt
import numpy as np
y = np.random.standard_normal((600, 2))
print(y.shape)
plt.figure(figsize=(7, 7)) # 绘制图形的画板尺寸(约为700像素×700像素)
plt.scatter(y[:, 0], y[:, 1], marker='o') # marker是指定点标记的形状,marker='o'表示圈
plt.grid(True) # 表示图形添加网格
plt.xlabel("1st") # X轴加标签‘1st’
plt.ylabel("2nd") # 表示给Y轴加标签‘2nd’
plt.title("Scatter Plot") # 图形加标题‘Scatter Plot’
plt.show()·
·
scatter函数参数详解
直方图
直方图是一种对数据分布情况的图形表示,显示各分组频率或数量分布的情况,易于显示各组之间频率或数量的差别。需要对数据进行分组,然后统计每个分组内数据的数量。
# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import numpy as np
import matplotlib.pyplot as plt
x = np.random.randint(0, 100, 50) # 数据列表
print(x)
"""
[68 67 16 92 68 26 68 87 60 21 63 29 18 73 49 65 44 19 22 73 12 76 93 35 39
69 0 18 34 31 29 31 51 32 25 44 32 8 83 93 24 15 78 83 15 25 36 53 24 80]
"""
bins = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100] # 分组边界
plt.hist(x=x, bins=bins)
plt.xlabel('x')
plt.ylabel('y')
plt.title('title')
plt.show()
subplot绘制多个子图
参考文章:https://blog.csdn.net/gatieme/article/details/61416645
https://blog.csdn.net/you_are_my_dream/article/details/53439518
子图:就是在一张figure里面生成多张子图。
Matplotlib对象简介
FigureCanvas 画布
Figure 图
Axes 坐标轴(实际画图的地方)
·# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import numpy as np
import matplotlib.pyplot as plt
square = np.zeros((32, 32))
square[5:10, 5:10] = 1
plt.subplot(221)
plt.imshow(square)
square[15:20, 5:10] = 1
plt.subplot(222)
plt.imshow(square)
square[5:10, 15:20] = 1
plt.subplot(223)
plt.imshow(square)
square[15:20, 15:20] = 1
plt.subplot(224)
plt.imshow(square)
plt.show()
·
·
其他:
【Matplotlib】详解图像各个部分
相关文章推荐
- python 使用numpy matplotlib绘制图表
- Python图表绘制:matplotlib绘图库入门
- python3.6安装matplotlib、numpy时报错ImportError
- Python模块简介及安装 [numpy,pandas,matplotlib,scipy,statsmodels,Gensim,sklearn,keras]
- python_matplotlib
- python 下 tinker、matplotlib 混合编程示例一个
- python—matplotlib数据可视化实例注解系列-----之横条图
- 使用python中的matplotlib进行绘图分析数据
- python中scatter()函数用法,matplotlib画图
- Python第三方库——Matplotlib_在同个figure中绘制多个图并给出legend
- python matplotlib.subplot绘制子图
- Python中的Numpy、SciPy、MatPlotLib安装与配置
- Python数据可视化matplotlib(一)—— 图表的基本元素
- Windows下怎么配置python的matplotlib环境
- windows下python的第三方包 numpy scipy matplotlib 简便安装
- Python matplotlib生成图片背景透明
- python matplotlib绘图时图例显示问题
- python:matplotlib及pandas绘图(2)
- python matplotlib绘图时图例显示问题
- ubuntu16.04安装python3下安装matplotlib