基本作图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fig=plt.figure(num=1,figsize=(4,4))
ax1=fig.add_subplot(221)#221表示画布的行、列以及你要在哪个画布作画
ax1.plot([1,2,3,4],[1,2,3,4])
ax2=fig.add_subplot(222)
ax2.plot([1,2,3,4],[2,2,3,4])
ax3=fig.add_subplot(223)
ax3.plot([1,2,3,4],[1,2,2,4])
ax4=fig.add_subplot(224)
ax4.plot([1,2,3,4],[1,2,3,3])

plt.show()

or

fig=plt.figure(num=1,figsize=(6,4))
ax=fig.add_subplot(111)

plt.show()

添加点和线的风格的三种方法

1
2
3
4
5
6
7
8
9
ax.plot(r, SL1, color='red', ls='-', marker = 'o', lw=1.25, label="SL1")

or

ax.plot(r, SL1, color='red', linestyle='-', marker = 'o', linewidth=1.25, label="SL1")

or

ax.plot(r, SL1, 'r-o', linewidth=1.25, label="SL1")

x, y 坐标范围标签的设置

1
2
3
4
5
ax.set_xlim(0.8,3)#x的坐标范围
ax.set_ylim(0.6,1.25)#y的坐标范围

plt.ylabel('Pair correlation')
plt.xlabel('Separation distance')

显示legend

1
plt.legend()

在原来的基础上添加对比线

1
2
ax.plot(x,SL1,"r-o",label="SL1")
ax.plot(x,SL2,"r-o",label="SL2")

在图中指定位置添加标签

1
ax.text(7,97,"max:96",fontsize=14,color="g",alpha=1,rotation=10)#x值,y值,标签值,字体大小,颜色,透明度,标签旋转多少度
数据线风格
说明
-
实线
破折线
点划线
:
虚线
数据点标记风格
说明
.
点标记
o
实心圈标记
s
实心方形标记
p
实心五角标记
*
星形标记
D
菱形标记

更多的数据点标记风格

颜色标记风格
说明
b
蓝色
g
绿色
r
红色
c
青绿色(cyan)
m
品(洋)红色(magenta)
y
黄色
k
黑色
w
白色

Ref:

matplotlib.pyplot的使用总结大全(入门加进阶)