(一)1.如何绘制散点图
可以看到类似于正弦曲线一样的点
(一)2.如何给散点图加上样式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
(二)1.如何绘制折线图
(二)2.如何给折线图加上样式
(三)1.如何绘制条形图
(三)2.如何给条形图加上样式
(三)3.如何绘制横向的条形图
(四)1.如何绘制直方图
(四)2.如何绘制双变量直方图
(五)1.如何绘制饼图
细心地哲学♂家可能回好奇,为什么是一个椭圆,这是因为我们这里少了一句话
而且每一块上面光秃秃的,每个部分都贴在了一块,也不好看,我们也可以设置一些参数,让其变得好看一些
(六)1.如何绘制箱形图
(七)颜色和样式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
蓝色
-
‘b‘
绿色
-
‘g‘
红色
-
‘r‘
青色
-
‘c‘
品红
-
‘m‘
黄色
-
‘y‘
黑色
-
‘k‘
白色
-
‘w‘
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
‘.‘
point marker
‘,‘
pixel marker
‘o‘
circle marker
‘v‘
triangle_down marker
‘^‘
triangle_up marker
‘<‘
triangle_left marker
‘>‘
triangle_right marker
‘1‘
tri_down marker
‘2‘
tri_up marker
‘3‘
tri_left marker
‘4‘
tri_right marker
‘s‘
square marker
‘p‘
pentagon marker
‘*‘
star marker
‘h‘
hexagon1 marker
‘H‘
hexagon2 marker
‘+‘
plus marker
‘x‘
x marker
‘D‘
diamond marker
‘d‘
thin_diamond marker
‘|‘
vline marker
‘_‘
hline marker
|
1
2
3
4
|
输入样式的时候还有一个简便的方法,cx--,c是青色,x是点的样式,--是线的样式
(八)1.如何绘制子图
(八)2.如何绘制子图
(九)如何绘制网格
(十)如何给图像带上标记
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-1,1,100)
y1 = np.sin(x)
y2 = np.cos(x)
y3 = np.tan(x)
# 加上需要的标签label
plt.plot(x,label="np.sin")
plt.plot(x,label="np.cos")
plt.plot(x,label="np.tan")
# 必须加上这句话,否则标签不显示
# legend里面还有一个location参数,可以指定位置
# 以及ncol可以指定要标签分几列显示
plt.legend()
plt.show()
(十一)调整坐标轴范围
1
2
3
4
5
6
7
8
9
10
|
(十二)调整坐标轴刻度
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import
numpy as np
import
matplotlib.pyplot as plt
import
matplotlib as mpl
import
datetime
start
=
datetime.date(
2016
,
1
)
end
=
datetime.date(
2017
,
1
)
y
=
np.random.rand(
len
(date))
plt.plot_date(date,y)
# 设置时间格式
date_format
=
mpl.dates.DateFormatter(
"%Y-%m-%d"
)
# 将格式应用到x轴上
ax.xaxis.set_major_formatter(date_format)
plt.show()
|
(十三)如何添加坐标轴
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
(十四)添加注释
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
(十五)如何绘制3D图形
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import
matplotlib.pyplot as plt
import
numpy as np
from
mpl_toolkits.mplot3d
import
Axes3D as A3
x,y
=
np.meshgrid(x,y)
z
=
np.power(x,
2
)
+
np.power(y,
2
)
# rstride,cstride表示行列每隔多少个点建一个面,cmap表示颜色
ax.plot_surface(x,rstride
=
1
,
cstride
=
1
,
alpha
=
0.4
)
ax.set_xlabel(
‘x_label‘
,color
=
‘r‘
)
ax.set_ylabel(
‘y_label‘
,color
=
‘g‘
)
ax.set_zlabel(
‘z_label‘
,color
=
‘b‘
)
plt.show()
|
如何解决中文乱码问题
解决子图重合问题
plt.tight_layout()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。