#%% md

### 图片灰度处理

#%% md

三种方法

#%%

import matplotlib.pyplot as plt
%matplotlib inline

#%%

import numpy as np

#%%

j.shape

#%%

j = plt.imread('./jizhengen.png')
plt.imshow(j)

#%%

# 彩色(ndarray3维)变黑白(ndarray2维)--->3维数组转换成2维数组
# 降维
# 聚合操作
# 2维降维成1维
nd =  np.array([[1,2,3],[3,1,7]])
nd.sum(axis = -1)
nd.mean(axis = -1)

#%%

j.shape

#%%

# 第一种方式
j_max = j.min(axis = -1)
plt.imshow(j_max,cmap = 'gray')

#%%

# 第一种方式
j_max = j.max(axis = -1)
plt.imshow(j_max,cmap = 'gray')

#%%

#第二种方式,平均值
j_mean = j.mean(axis = 2)
plt.imshow(j_mean,cmap = 'gray')

#%%

# 第三种 ,红绿蓝,肉眼三种颜色感知不同的,权重
# 加权(weights)平均法
# g>r>b
# 0.587,0.299,0.114
# 红绿蓝
w = np.array([0.299,0.587,0.114])

# 矩阵乘法
j_weights  = np.dot(j,w)
plt.imshow(j_weights,cmap = 'gray')

#%%

nd.shape

#%% md

# matplotlib

#%% md

## 目录
+ 一、【重点】Matplotlib基础知识

+ 二、设置plot的风格和样式
    + 1、【重点】点和线的样式
    + 2、X、Y轴坐标刻度

+ 三、2D图形
    + 1、示例
    + 2、【重点】直方图
    + 3、【重点】条形图
    + 4、【重点】饼图
    + 5、【重点】散点图
    
=============以上为重点=================

#### 下面的自学
+ 四、图形内的文字、注释、箭头
    + 1、图形内的文字
    + 2、注释
    + 3、箭头
    
+ 五、3D图
    + 1、曲面图

#%% md

## 一、Matplotlib基础知识

#%% md

Matplotlib中的基本图表包括的元素
+ x轴和y轴  
水平和垂直的轴线

+ x轴和y轴刻度  
刻度标示坐标轴的分隔,包括最小刻度和最大刻度

+ x轴和y轴刻度标签  
表示特定坐标轴的值

+ 绘图区域  
实际绘图的区域

#%%

import numpy as np

import matplotlib.pyplot as plt
%matplotlib inline

#%% md

### 只含单一曲线的图

#%%

# 函数关系
# y = x
x = np.arange(0,15)
y = x
plt.plot(x,y)

#%%

# y = x^2
# x = np.arange(-5,5)
x = np.linspace(-5,5,1000)
y = x**2
plt.plot(x,y)

#%%

y = np.random.randint(0,50,size = 10)
# 如果只有一个参数,参数就是y值,x自动填充:0~N-1
plt.plot(y)

#%% md

### 包含多个曲线的图

#%% md

1、可以使用多个plot函数(推荐),在一个图中绘制多个曲线

#%%

x = np.linspace(-5,5,1000)
y = x**2

plt.plot(x,y)

plt.plot(x,x*3)

# show(),显示之前的图形,创建一个新的图形,终结
# plt.show()

plt.plot(x,np.power(x,3))

#%% md

2、也可以在一个plot函数中传入多对X,Y值,在一个图中绘制多个曲线

#%%

x1 = x

#%%

# 返回值进行打印
line1,line2,line3 = plt.plot(x,y,x,x*4,x,np.power(x,3))
line1.set_linewidth(10)

#%%

# 对象
type(image)
# 该对象中包含figure:图片

#%%

j = plt.imread('./jizhengen.png')
image = plt.imshow(j)

# 从image中获取figure
figure = image.get_figure()

figure.set_size_inches((12,9))

#%% md

### 网格线
绘制正选余弦

#%%

x = np.linspace(-np.pi,np.pi,1000)

y = np.sin(x)

plt.plot(x,y)

# 添加网格线
# grid
# axis :轴
# axes 轴面
# Turn the axes grids on or off.

# *axis* can be 'both' (default), 'x', or 'y' to control which
# set of gridlines are drawn.
plt.grid(b = True,axis = 'y')

#%% md

使用plt.grid(True)方法为图添加网格线

#%%

#%% md

设置grid参数(参数与plot函数相同),使用plt面向对象的方法,创建多个子图显示不同网格线
![](1.PNG)

- lw代表linewidth,线的粗细
- alpha表示线的明暗程度
- color代表颜色

#%%

# 面向对象
figure = plt.figure(figsize=(12,5))

# 向对象中添加子axes轴面
axes1 = figure.add_subplot(131)

# 向轴面1中绘制图形

# 180度== np.pi==3.14
# 90 = np.pi/2
x = np.linspace(-10,10,1000)

y = np.cos(x)

axes1.plot(x,y)
# 显示网格线
axes1.grid(b = True)

# 第二个子视图
axes2 = figure.add_subplot(1,3,2)
axes2.plot(x,y,color = 'green',linestyle = '-.')
axes2.grid(b = True,color = 'r',linestyle = '--')

# 第三个子视图
axes3 = figure.add_subplot(133)
axes3.plot(x,y,color = 'purple',linestyle = '-')
axes3.grid(b = True,color = 'blue',linestyle = ':')

#%% md

### 坐标轴界限

#%% md

#### axis方法
如果axis方法没有任何参数,则返回当前坐标轴的上下限axis(xmin =,ymax = )

#%%

plt.plot(x,y)
plt.axis([-15,8,-2,2])

#%% md

##### plt.axis('xxx') 'tight'、'off'、'equal'……

设置坐标轴类型  
关闭坐标轴
![](2.png)

#%%

plt.plot(x,y)
plt.axis('equal')

#%%

x = np.linspace(-1,1,100)

y = (1-x**2)**0.5

# plt.figure(figsize=(4,4))
plt.plot(x,y,x,-y)
plt.axis('equal')

#%% md

#### xlim方法和ylim方法

除了plt.axis方法,还可以通过xlim,ylim方法设置坐标轴范围

#%%

plt.plot(x,y)
plt.xlim(-1.5,2)
plt.ylim(-1,1)

#%% md

### 坐标轴标签
xlabel方法和ylabel方法  
plt.ylabel('y = x^2 + 5',rotation = 60)旋转

#%%

plt.plot(x,y)
plt.xlabel('half circle')
plt.ylabel("f(x) = (1-x^2)^0.5",rotation = 0,horizontalalignment = 'right')

#%% md

### 标题
title方法

#%%

plt.plot(x,y)
# 有的方法中,设置字体大小用的参数textsize,有的地方用size
text = plt.title('this is half circle',fontsize = 20,color = 'green')
text.set_fontstyle('italic')
text.set_alpha(0.2)
text.set_bbox(dict(facecolor='purple', alpha=0.5))
text.set_backgroundcolor(color = 'blue')
text.set_rotation(60)

#%% md

### 图例

#%% md

#### legend方法

两种传参方法:
- 【推荐使用】在plot函数中增加label参数
- 在legend方法中传入字符串列表
![](3.png)

#%%

plt.plot(x,y,x,np.sin(x),x,np.cos(x))
plt.axis('equal')
plt.legend(['half circle','sin(x)','cos(x)'])

#%%

#%% md

label参数为'_xxx',则图例中不显示  
plt.plot(x, x*1.5, label = '_xxx')

#%%

plt.plot(x,y,label = 'half circle')
plt.plot(x,np.sin(x),label = 'sin')
plt.plot(x,np.cos(x),label = 'cos')

# 图例标签可以放到plot函数中,!!!显示图例必须调用legend方法
plt.axis('equal')
plt.legend()

#%% md

### loc参数

#%% md

| 字符串       | 数值      | 字符串   |  数值 |
| :-------------: |:-----------:| :-----:|  :-----:|
| best        |  0        | center left   |   6 |
| upper right    | 1        | center right  |   7  |
| upper left    |  2        | lower center  |   8  |
| lower left    |  3        | upper center  |   9 |
| lower right   |  4        | center      |   10 |
| right       |  5        |

#%%

plt.plot(x,y,label = 'half circle')
plt.plot(x,np.sin(x),label = 'sin')
plt.plot(x,np.cos(x),label = 'cos')

# 图例标签可以放到plot函数中,!!!显示图例必须调用legend方法
plt.axis('equal')
plt.legend(loc = 'upper left')

#%% md

loc参数可以是2元素的元组,表示图例左下角的坐标

#%%

plt.plot(x,y,label = 'half circle')
plt.plot(x,np.sin(x),label = 'sin')
plt.plot(x,np.cos(x),label = 'cos')

# 图例标签可以放到plot函数中,!!!显示图例必须调用legend方法
plt.axis('equal')
# 相对值,loc = (x坐标,y坐标相对值)
plt.legend(loc = (1,-0.3))

#%% md

图例也可以超过图的界限loc = (-0.1,0.9)

#%% md

### ncol参数
ncol控制图例中有几列

#%%

plt.plot(x,y,label = 'half circle')
plt.plot(x,np.sin(x),label = 'sin')
plt.plot(x,np.cos(x),label = 'cos')

# 图例标签可以放到plot函数中,!!!显示图例必须调用legend方法
plt.axis('equal')
# col = columns
# loc = location
plt.legend(loc = 'upper left',ncol = 3)

#%% md

### linestyle、color、marker
修改线条样式  
![](4.png)

#%%

y1 = np.random.normal(loc = 0,scale= 1,size = 10)*10

y2 = np.random.normal(loc= 10,scale=5,size = 10)*10

y3 = np.random.normal(loc= - 10 ,scale= 2,size = 10)*10

plt.plot(y1,ls = '--',marker = 'o')
plt.plot(y2,linestyle = '-.',marker = '*')
plt.plot(y3,ls = ':',marker = '>')

# bbox_to_anchor 前两个坐标点,第三个参数宽度,第四个,和第二个作用类似,距离y轴的距离
plt.legend(['line1','line2','line3'],ncol = 3,mode = 'expand',bbox_to_anchor = [0,1,1,0.001],facecolor = 'red' )

#%% md

### 保存图片

#%% md

figure.savefig的选项
+ filename  
含有文件路径的字符串或Python的文件型对象。图像格式由文件扩展名推断得出,例如,.pdf推断出PDF,.png推断出PNG
(“png”、“pdf”、“svg”、“ps”、“eps”……)
+ dpi  
图像分辨率(每英寸点数),默认为100
+ facecolor  
图像的背景色,默认为“w”(白色)

#%%

!mkdir './save'

#%%

y1 = np.random.normal(loc = 0,scale= 1,size = 10)*10

y2 = np.random.normal(loc= 10,scale=5,size = 10)*10

y3 = np.random.normal(loc= - 10 ,scale= 2,size = 10)*10

plt.plot(y1,ls = '--',marker = 'o')
plt.plot(y2,linestyle = '-.',marker = '*')
plt.plot(y3,ls = ':',marker = '>')

# bbox_to_anchor 前两个坐标点,第三个参数宽度,第四个,和第二个作用类似,距离y轴的距离
plt.legend(['line1','line2','line3'],ncol = 3,mode = 'expand',bbox_to_anchor = [0,1,1,0.001],facecolor = 'red' )

# 保存图片
'''
  savefig(fname, dpi=None, facecolor='w', edgecolor='w',
          orientation='portrait', papertype=None, format=None,
          transparent=False, bbox_inches=None, pad_inches=0.1,
          frameon=None)
'''

''' *papertype*:
    One of 'letter', 'legal', 'executive', 'ledger', 'a0' through
    'a10', 'b0' through 'b10'. Only supported for postscript
    output.'''

plt.savefig('./save/pic5.jpg',dpi = 500,facecolor = 'purple',
            papertype = 'letter',pad_inches = 0,bbox_inches = 'tight')

#%%

#%% md

## 二、设置plot的风格和样式
plot语句中支持除X,Y以外的参数,以字符串形式存在,来控制颜色、线型、点型等要素,语法形式为:  
plt.plot(X, Y, 'format', ...)

#%% md

### 点和线的样式

#%% md

#### 颜色
参数color或c

#%%

plt.plot(x,y,color = 'red')

#%%

plt.plot(x,y,c = 'r')

#%%

#%% md

##### 颜色值的方式
+ 别名
    + color='r'
    
    
    
+ 合法的HTML颜色名
    + color = 'red'

| 颜色       | 别名      | HTML颜色名  | 颜色   |  别名 |HTML颜色名|
| :-------------: |:---------:|:-----------:| :------:|  :-----:| :-----:|
| 蓝色        | b       | blue      | 绿色   |  g   |  green  |
| 红色        | r       | red      | 黄色    |  y   |  yellow |
| 青色        | c       | cyan      | 黑色   |  k   |  black  |
| 洋红色      | m        | magenta    | 白色   |  w   |  white  |

+ HTML十六进制字符串
    + color = '#eeefff'

+ 归一化到[0, 1]的RGB元组
    + color = (0.3, 0.3, 0.4)

#%%

plt.plot(x,y,color = '#880000')

#%%

plt.plot(x,y,color = (0,1,1))

#%% md

##### 透明度
alpha参数

#%%

plt.plot(x,y,color = 'purple')

#%%

# alpha : 0~1 效果
plt.plot(x,y,color = 'purple',alpha = 0.8)

#%%

#%% md

##### 背景色
设置背景色,通过plt.subplot()方法传入facecolor参数,来设置坐标轴的背景色

#%%

plt.subplot(facecolor = 'red',alpha = 100000)
plt.plot(x,y)

#%%

type(figure)

#%%

type(axes)

#%%

figure = plt.figure(facecolor='green')
axes = figure.add_subplot(121)
axes.plot(x,y)
axes = figure.add_subplot(122)
axes.plot(x,y)
# figure包含咱们的axes轴面

#%% md

#### 线型
参数linestyle或ls

#%% md

| 线条风格     | 描述      | 线条风格 |  描述 |
| :-------------: |:------------:| :----:|  :-----:|
| '-'        | 实线     | ':'     |  虚线 |
| '--'       | 破折线    | 'steps'  |  阶梯线 |
| '-.'       | 点划线    | 'None' / ',' |  什么都不画 |

#%%

plt.plot(x,y,ls = '-.')

#%%

#%% md

##### 线宽
linewidth或lw参数

#%%

plt.plot(x,y,ls = '-.',lw = 5)

#%% md

##### 不同宽度的破折线
dashes参数  
设置破折号序列各段的宽度  
![](5.png)

#%%

# dashes: sequence of on/off ink in points
plt.plot(x,y,dashes = [5,20,10,5,1,2])

#%%

#%% md

#### 点型
marker参数

#%% md

| 标记        | 描述       | 标记   |  描述 |
| :-------------: |:-----------:| :----:|  :-----:|
| '1'         | 一角朝下的三脚架      | '3'     |  一角朝左的三脚架 |
| '2'         | 一角朝上的三脚架      | '4'     |  一角朝右的三脚架 |

#%%

x = np.linspace(-np.pi,np.pi,20)
y = np.sin(x)
plt.figure(figsize=(12,9))
plt.plot(x,y,marker = 4)

#%% md

| 标记        | 描述       | 标记   |  描述 |
| :-------------: |:-----------:| :----:|  :-----:|
| 's'         | 正方形   | 'p'   | 五边形     |
| 'h'         | 六边形1    | 'H'     | 六边形2    |
| '8'         | 八边形     |

#%%

x = np.linspace(-np.pi,np.pi,20)
y = np.sin(x)
plt.figure(figsize=(12,9))
plt.plot(x,y,marker = 'h',markersize = 10)

#%% md

| 标记        | 描述       | 标记   |  描述 |
| :-------------: |:-----------:| :----:|  :-----:|
| '.'     |  点 | 'x'   | X   |
| '\*'    |  星号  | '+'         | 加号       |
| ','         | 像素       |

#%%

x = np.linspace(-np.pi,np.pi,20)
y = np.sin(x)
plt.figure(figsize=(12,9))
plt.plot(x,y,marker = '*',markersize = 10)

#%% md

| 标记        | 描述       | 标记   |  描述 |
| :-------------: |:-----------:| :----:|  :-----:|
| 'o'         | 圆圈      | 'D'         | 菱形      |
| 'd'    |  小菱形  |'','None',' ',None| 无       |

#%%

x = np.linspace(-np.pi,np.pi,20)
y = np.sin(x)
plt.figure(figsize=(12,9))
plt.plot(x,y,marker = 'd',markersize = 10)

#%% md

| 标记     | 描述     | 标记   |  描述 |
| :--------: |:----------:| :------:| :----:|
| '\_'     |  水平线    | '|'     |  水平线   
![](6.png)

#%%

x = np.linspace(-np.pi,np.pi,20)
y = np.sin(x)
plt.figure(figsize=(12,9))
# 水平线,英文状态下下划线
plt.plot(x,y,marker = '_',markersize = 10)

#%% md

| 标记        | 描述       | 标记   |  描述 |
| :-------------: |:-----------:| :----:|  :-----:|
| 'v'         | 一角朝下的三角形 | '<'     |  一角朝左的三角形 |
| '^'         | 一角朝上的三角形 | '>'     |  一角朝右的三角形 |

#%%

#%% md

#### 多参数连用
颜色、点型、线型

#%%

x = np.linspace(-np.pi,np.pi,20)
y = np.sin(x)
plt.figure(figsize=(12,9))
plt.plot(x,y,'r*--')

#%% md

#### 更多点和线的设置

#%% md

| 参数        | 描述       | 参数       |  描述   |
| :-------------: |:-----------:| :-------------:|  :------:|
| color或c      | 线的颜色   | linestyle或ls  |  线型   |
| linewidth或lw   | 线宽     | marker       |  点型  |
| markeredgecolor  | 点边缘的颜色 | markeredgewidth | 点边缘的宽度 |
| markerfacecolor  | 点内部的颜色 | markersize    |  点的大小    |  
![](7.png)

#%%

plt.plot(x,y,marker = 'o',markersize = 10,markerfacecolor = 'green',markeredgecolor = 'red',markeredgewidth = 3)

#%% md

#### 在一条语句中为多个曲线进行设置

#%% md

##### 多个曲线同一设置
属性名声明

plt.plot(x1, y1, x2, y2, fmt, ...)

#%%

plt.plot(x,y,x,x*2,color = 'red',marker = 'o')

#%% md

##### 多个曲线不同设置
多个都进行设置时,无需声明属性
plt.plot(x1, y1, fmt1, x2, y2, fmt2, ...)

#%%

plt.plot(x,y,'ro--',x,x*2,'g*-.')

#%%

# 语法错误
plt.plot(x,y,color = 'red',marker = 'o',x,x*2,color = 'red',marker = 'o')

#%% md

#### 三种设置方式

#%% md

##### 向方法传入关键字参数

#%%

plt.plot(x,y,color = 'r')

#%% md

##### 对实例使用一系列的setter方法

#%%

line

#%%

# 实例 == line
line = plt.plot(x,y,x,np.power(x,2))
# 'list' object has no attribute 'set_color'
line[0].set_color('red')
line[1].set_marker('*')
# 对象,对象获取它方法和属性
line2 = line[1]
line2.set_alpha(0.3)
line2.set_lw(3)

#%%

line1,line2, = plt.plot(x,y,x,x*2)
line1.set_color('purple')

#%% md

##### 使用setp()方法

#%%

line1, = plt.plot(x,y)
# setp:set_properties
# setp(参数一设置的对象,……属性)
plt.setp(line1,color = 'red',marker = '*',ls = '--')

#%%

#%% md

### X、Y轴坐标刻度
xticks()和yticks()方法  
![](8.png)

#%%

plt.plot(x,y,color = 'red')
plt.xticks(np.linspace(-np.pi,np.pi,5),(2001,2002,2003,'h-max','max'),size = 20,rotation = 60)
plt.yticks([-1,0,1],['min',0,'max'])

#%%

#%% md

#### 面向对象方法
set_xticks、set_yticks、set_xticklabels、set_yticklabels方法

#%%

figure = plt.figure()
axes = figure.add_subplot(111)
axes.plot(x,y)
# 调用对象的方法,进行设置
axes.set_xticks(np.linspace(-np.pi,np.pi,5))
axes.set_xticklabels(['-pi','-pi/2',0,'pi/2','pi'],size = 20,rotation = 60)

#%%

#%% md

#### 正弦余弦
LaTex语法,用$\pi$等表达式在图表上写上希腊字母  
![](9.png)

#%%

# $\pi$

plt.plot(x,y,x,np.cos(x))

plt.xticks(np.linspace(-np.pi,np.pi,5),['-$\psi$','-$\pi$/2',0,'$\pi$/2','$\pi$'],size = 20)
plt.yticks([-1,0,1],['min',0,'max'])

#%%

#%% md

## 三、2D图形

#%% md

### 直方图

【直方图的参数只有一个x!!!不像条形图需要传入x,y】

hist()的参数
+ bins  
可以是一个bin数量的整数值,也可以是表示bin的一个序列。默认值为10
+ normed  
如果值为True,直方图的值将进行归一化处理,形成概率密度,默认值为False
+ color  
指定直方图的颜色。可以是单一颜色值或颜色的序列。如果指定了多个数据集合,颜色序列将会设置为相同的顺序。如果未指定,将会使用一个默认的线条颜色
+ orientation  
通过设置orientation为horizontal创建水平直方图。默认值为vertical

#%%

x = np.random.randint(0,10,size = 10)
print(x)
plt.hist(x,bins = 10,color = 'g',normed=True)

# 0.3 + 0.69999

#%%

#%% md

### 条形图

【条形图有两个参数x,y!】

bar()、barh()

#%%

plt.bar(x,x*2,color = 'red',width = 0.8)

#%%

#%% md

#### 水平条形图
barh()

#%%

#%% md

### 饼图

【饼图也只有一个参数x!】

pie()  
饼图适合展示各部分占总体的比例,条形图适合比较各部分的大小

#%% md

普通各部分占满饼图

#%%

# x = [0.2,0.3,0.4]
# 数字,按照比例进行划分
x = [3,3,3]
plt.pie(x,labels=['dog','pig','dragon'])
plt.axis('equal')

#%% md

普通未占满饼图

#%%

#%% md

饼图阴影、分裂等属性设置
#labels参数设置每一块的标签;labeldistance参数设置标签距离圆心的距离(比例值)
#autopct参数设置比例值的显示格式(%1.1f%%);pctdistance参数设置比例值文字距离圆心的距离
#explode参数设置每一块顶点距圆形的长度(比例值);colors参数设置每一块的颜色;
#shadow参数为布尔值,设置是否绘制阴影

#%%

labels = ['China','USA','EU','Japan','UK','France','Austrilia','Others']
data = np.array([0.12,0.18,0.15,0.06,0.03,0.025,0.015,0.42])

plt.figure(figsize=(8,8))
pie = plt.pie(data,labels=labels,labeldistance = 1.2,
              explode=[0.2,0,0.1,0,0.2,0,0.1,0],autopct = '%0.2f%%',
             pctdistance = 0.6,shadow = True,startangle = 90)

#%% md

startangle设置旋转角度

#%% md

### 散点图

【散点图需要两个参数x,y,但此时x不是表示x轴的刻度,而是每个点的横坐标!】

scatter()  
x![](10.png)

#%%

x = np.random.randn(1000)
y = np.random.randn(1000)

size = np.random.randint(1,100,size = 1000)

colors = np.random.rand(3000).reshape((1000,3))

plt.figure(figsize=(12,9))

plt.scatter(x,y,color = colors,marker = 'd',s = size)

#%%

#%% md

## <font color = red>四、图形内的文字、注释、箭头(自学)</font>

#%% md

控制文字属性的方法:

| Pyplot函数     | API方法                | 描述                     |
| :-------------: |:------------------------------:| :---------------------------------:|
| text()       |  mpl.axes.Axes.text()       | 在Axes对象的任意位置添加文字     |
| xlabel()      |  mpl.axes.Axes.set_xlabel()   | 为X轴添加标签               |
| ylabel()      |  mpl.axes.Axes.set_ylabel()   | 为Y轴添加标签               |
| title()       | mpl.axes.Axes.set_title()   |  为Axes对象添加标题            |
| legend()      | mpl.axes.Axes.legend()      |  为Axes对象添加图例            |
| figtext()     |  mpl.figure.Figure.text()    |  在Figure对象的任意位置添加文字    |
| suptitle()     | mpl.figure.Figure.suptitle() |  为Figure对象添加中心化的标题     |
| annnotate()    |  mpl.axes.Axes.annotate()    |  为Axes对象添加注释(箭头可选)    |

所有的方法会返回一个matplotlib.text.Text对象

#%% md

### 图形内的文字
text()  
![](14.png)

#%% md

使用figtext()

#%%

#%% md

### 注释
annotate()  
xy参数设置箭头指示的位置,xytext参数设置注释文字的位置  
arrowprops参数以字典的形式设置箭头的样式  
width参数设置箭头长方形部分的宽度,headlength参数设置箭头尖端的长度,  
headwidth参数设置箭头尖端底部的宽度,  
facecolor设置箭头颜色  
shrink参数设置箭头顶点、尾部与指示点、注释文字的距离(比例值)  
![](15.png)

#%%

#%%

#%% md

练习  
三个随机正太分布数据
![](16.png)  
设置图例  
bbox_to_anchor,ncol mode,borderaxespad  
设置注解 arrowstyle

#%%

#%%

#%% md

### 箭头
箭头的样式,没必要记

#%%

plt.figure(figsize=(12,9))
plt.axis([0, 10, 0, 20]);
arrstyles = ['-', '->', '-[', '<-', '<->', 'fancy', 'simple', 'wedge']
for i, style in enumerate(arrstyles):
    plt.annotate(style, xytext=(1, 2+2*i), xy=(4, 1+2*i), arrowprops=dict(arrowstyle=style));

connstyles=["arc", "arc,angleA=10,armA=30,rad=30", "arc3,rad=.2", "arc3,rad=-.2", "angle", "angle3"]
for i, style in enumerate(connstyles):
    plt.annotate(style, xytext=(6, 2+2*i), xy=(8, 1+2*i), arrowprops=dict(arrowstyle='->', connectionstyle=style));
plt.show()

#%% md

## <font color = red>五、3D图(自学)</font>

#%% md

#### 曲面图  
![](11.png)

#%% md

导包  
from mpl_toolkits.mplot3d.axes3d import Axes3D

#%%

#%% md

生成数据

#%%

#%% md

绘制图形

#%%

#%% md

## <font color = red>玫瑰图/极坐标条形图(自学)</font>

柱状图

![](13.png)

#%% md

创建极坐标条形图

#%%

#%% md

使用np.histogram计算一组数据的直方图

#%%

python:matplotlib基础(3)相关推荐

  1. python绘图实例-Python matplotlib基础绘图函数示例

    原标题:Python matplotlib基础绘图函数示例 Pyplot基础图标函数: 函数 说明 plt.plot(x,y,fmt,-) 绘制一个坐标图 plt.boxplot(data,notch ...

  2. python绘图实例-Python——matplotlib基础绘图函数示例

    1. 2.饼图 (1) import matplotlib.pyplot as plt labels='frogs','hogs','dogs','logs'% sizes=[15,30,45,10] ...

  3. python可视化添加文本_python Matplotlib基础--如何添加文本和标注

    创建一个优秀的可视化图表的关键在于引导读者,让他们能理解图表所讲述的故事.在一些情况下,这个故事可以通过纯图像的方式表达,不需要额外添加文字,但是在另外一些情况中,图表需要文字的提示和标签才能将故事讲 ...

  4. Python绘图之matplotlib基础教程:matplotlib库图表绘制中常规设置大全(交互模式、清除原有图像、设置横坐标显示文字/旋转角度、添加图例、绘图布局自动调整、图像显示、图像暂停)

    Python绘图之matplotlib基础教程:matplotlib库图表绘制中常规设置大全(交互模式.清除原有图像.设置横坐标显示文字/旋转角度.添加图例.绘图布局自动调整.图像显示.图像暂停) 目 ...

  5. python:matplotlib基础(2)

    #%% md ### 图片灰度处理 #%% import numpy as np import pandas as pd import matplotlib.pyplot as plt %matplo ...

  6. python:matplotlib基础(1)

    Matplotlib中的基本图表包括的元素 + x轴和y轴   水平和垂直的轴线 + x轴和y轴刻度   刻度标示坐标轴的分隔,包括最小刻度和最大刻度 + x轴和y轴刻度标签   表示特定坐标轴的值 ...

  7. Python机器学习基础之Matplotlib库的使用

    声明:代码的运行环境为Python3.Python3与Python2在一些细节上会有所不同,希望广大读者注意.本博客以代码为主,代码中会有详细的注释.相关文章将会发布在我的个人博客专栏<Pyth ...

  8. python Numpy 的基础用法以及 matplotlib 基础图形绘制

    python Numpy 的基础用法以及 matplotlib 基础图形绘制 1. 环境搭建 1.1 Anaconda ​ anaconda 集成了数据分析,科学计算相关的所有常用安装包,比如Numo ...

  9. 【Python】matplotlib基础:数据可视化

    matplotlib基础:绘图和可视化 目录: 文章目录 @[toc] 一 绘图的可用性 一 绘图的可用性

最新文章

  1. SDUT 2860-生日Party(BFS)
  2. nyoj239月老的难题
  3. 解决:Unknown custom element: <myData> - did you register the component correctly? For recursive compon
  4. 用filter求素数
  5. 滴滴披露女司机数据:80后女性过半 24%全年零违章
  6. php大文件读,PHP读取大文件
  7. 归并排序法计算逆序对数
  8. php微信个性化菜单,微信公众平台开发:个性化菜单接口说明
  9. Python爬虫【urllib3模块】和【requests模块】
  10. LCD液晶屏驱动芯片分类百科
  11. CADD课程学习(13)-- 研究蛋白小分子动态相互作用-III(蛋白配体复合物 GROMACS)
  12. 银行的压力测试如何进行?
  13. JVMTM Tool Interface:JVM源码分析之javaagent原理完全解读
  14. TIA博途S7-1200学习笔记——数据类型
  15. 【学习笔记·2】FOC
  16. 超级计算机 任务提交,超算任务提交系统slurm用法
  17. UniMSE: Towards Unified Multimodal Sentiment Analysisand Emotion Recognition
  18. Vue项目创建(2.x/3.x 自动/手动)及问题记录(路由注册不上)
  19. @RequiredArgsConstructor 代替@AutoWired注解
  20. 用C语言设计简易银行系统

热门文章

  1. 使用JSONObject 读取 jason对象中的key
  2. 一阶广义差分模型_广义差分法的eviews软件实现
  3. Oracle碎片整理问题
  4. shell脚本case传递参数
  5. CTR --- NFM论文阅读笔记,及tf2复现
  6. python用双重循环输出菱形图案_使用循环创建菱形图案
  7. PySpark | RDD
  8. 戴尔服务器R200安装 centos7(U盘安装)
  9. 亚马逊封号,新规则来了,你知道了吗?
  10. 【跨境电商平台规则与合规研讨会】在跨境驿站顺利召开