借助Jupyter Notebook在线绘图,生成带有标记点的折线图

from matplotlib import pyplot as plt
import numpy as np

import matplotlib.pyplot as plt

plt.xlim(20,55)#设置x轴的刻度线为20-50
plt.xticks([25,30,35,40,45,50,55]) #显示x轴里只出现6个数字
plt.xlabel('xlabel')#x轴标签

#同理 设置y轴
plt.ylim(0,0.02)
plt.yticks([0,0.005,0.01,0.015,0.02])
plt.ylabel('ylable')

#传入x轴、y轴数据集
x_values = [25,30,35,40,45,50]
y_values = [0.01650632911392405,0.0158999192897498,0.015419501133786848,0.014144736842105264,0.013155737704918033,0.012155737704918033]

#绘图,r--是以红色虚线绘制,其中在相关点出以圆圈形式进行标注,并且在图上方注释这条线代表的含义
plt.plot(x_values,y_values,'r--', marker = 'o',label = 'OMR')

#要加这一条语句标签注释才能显示出来
plt.legend()


#查看图片
plt.show()

#保存图片并裁减空白区域(注意,下条语句和plt.show不能同时出现,否则保存后图片会显示空白)
plt.savefig('test.png',bbox_inches = 'tight')

借助Jupyter Notebook在线绘图,生成带有标记点的折线图_第1张图片

你可能感兴趣的:(python)