参考链接:https://www.jianshu.com/p/da385a35f68d
画点图、线图
import numpy
as np
import pandas
as pd
import matplotlib
.pyplot
as plt
from matplotlib
.ticker
import MultipleLocator
x
= np
.arange
(6, 100, 0.5)
y
= x
* 2
x2
= np
.arange
(0, 10, 0.1)
y2
= np
.sin
(x2
)
plt
.rcParams
['font.family'] = ['sans-serif']
plt
.rcParams
['font.sans-serif'] = ['SimHei']
plt
.rcParams
['axes.unicode_minus'] = False
fig
= plt
.figure
(num
=1, figsize
=(15, 10), dpi
=100, facecolor
="#BBFFFF", edgecolor
='#0000CD')
ax1
= fig
.add_subplot
(2, 1, 1)
ax2
= fig
.add_subplot
(2, 1, 2)
ax1
.set_title
("mingyu")
ax1
.set_xlabel
("age", fontdict
={'color': 'r', 'fontsize': '30'})
ax1
.set_ylabel
("money(万元)", fontdict
={'color': 'r', 'fontsize': '30'})
ax1
.set_xlim
(0, 100)
ax1
.set_ylim
(0, 250)
ax1
.xaxis
.set_major_locator
(MultipleLocator
(5))
ax1
.yaxis
.set_major_locator
(MultipleLocator
(15))
ax1
.set_facecolor
('#FFEC8B')
ax1
.text
(80, 200, r
'y=x*2', fontdict
={'color': '#CD5C5C', 'fontsize': '20'})
ax1
.annotate
('这里是甲子', xy
=(60, 120), xytext
=(63, 90),
arrowprops
=dict(facecolor
='black', shrink
=0.02),
)
ax1
.grid
(b
=True, which
='major', axis
='both', alpha
=0.7, color
='#FF6A6A', linestyle
='-', linewidth
=0.5)
ax1
.plot
(x
, y
, marker
='.', color
='#6E8B3D', label
='第一个子图的操作')
ax2
.set_xlim
(0, 10)
ax2
.set_ylim
(-1.1, 1.1)
ax2
.text
(0, 0.00, '_' * 92, fontdict
={'color': '#000000', 'fontsize': '20'})
ax2
.plot
(x2
, y2
, linestyle
='--', color
='#FFD39B', label
='第二个子图的操作')
plt
.show
()
标记maker | 描述
‘o’ | 圆圈 ‘.’ | 点 ‘D’ | 菱形 ‘s’ | 正方形 ‘h’ | 六边形1 ‘*’ | 星号 ‘H’ | 六边形2 ‘d’ | 小菱形 ‘_’ | 水平线 ‘v’ | 一角朝下的三角形 ‘8’ | 八边形 ‘<’ | 一角朝左的三角形 ‘p’ | 五边形 ‘>’ | 一角朝右的三角形 ‘,’ | 像素 ‘^’ | 一角朝上的三角形 ‘+’ | 加号 ‘\ ‘ | 竖线 ‘x’ | X
画条形图、散点图、三维图
import numpy
as np
import matplotlib
.pyplot
as plt
plt
.rcParams
['font.family'] = ['sans-serif']
plt
.rcParams
['font.sans-serif'] = ['SimHei']
plt
.rcParams
['axes.unicode_minus'] = False
fig
= plt
.figure
(5)
ax
= fig
.add_subplot
(1, 1, 1, projection
='3d')
x
, y
= np
.mgrid
[-2:2:20j, -2:2:20j]
z
= x
* np
.exp
(-x
** 2 - y
** 2)
ax
.plot_surface
(x
, y
, z
, rstride
=2, cstride
=1, cmap
=plt
.cm
.coolwarm
, alpha
=0.8)
ax
.set_xlabel
('x 轴')
ax
.set_ylabel
('y 轴')
ax
.set_zlabel
('z 轴')
plt
.show
()