matplotlib在图像上方添加文字、标签--转载自 “呆萌的代Ma”

此为效果图
matplotlib在图像上方添加文字、标签--转载自 “呆萌的代Ma”_第1张图片

import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns

数据源:

data = pd.DataFrame(
    data=[[1,2.1],[2,3.2],[3,4.3],[4,5.4]],columns=['x','y'])

内容:

	x	y
0	1	2.1
1	2	3.2
2	3	4.3
3	4	5.4

绘图:

x = data['x']
y = data['y']
ax = sns.lineplot(x,y, marker='>')
for x, y in zip(x,y):
    plt.text(
        x = x-0.12, # x 相对于原先的数据点向左偏移0.12个单位
        y = y+0.05, # y 向上偏移0.05个单位
        s = '{:.2f}'.format(y), # 数据格式
        color ='r') # 颜色

生成的图片:
matplotlib在图像上方添加文字、标签--转载自 “呆萌的代Ma”_第2张图片

你可能感兴趣的:(Python,/,Pycharm,/,Matplotlib,pytorch,深度学习,python)