使用 python matplotlib 做简单的曲线图

1、软件版本

  • anaconda python3.7.3
  • pycharm 2019.2.3 学生教育版

2、python环境

3、代码示例说明

#导入需要使用的库
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.font_manager as fm
from matplotlib.ticker import FuncFormatter
#全局字体设置
#myfont = fm.FontProperties(fname=r'C:\Users\Hxc84\Desktop\R\font\simsun.ttf') #导入自定义字体(这里不做使用)
plt.rcParams['font.sans-serif'] = ['Simsun'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
#变量设置
snr = np.array([-3, -1, 1, 3, 5, 7, 9, 11])
timing1 = np.array([98.66, 99.49, 99.84, 99.97, 99.97, 99.98, 100, 100])/100
timing2 = np.array([99.62, 99.82, 99.97, 100, 99.99, 100, 100, 100])/100
timing3 = np.array([99.62, 99.87, 99.95, 99.98, 100, 100, 100, 100])/100
timing4 = np.array([99.61, 99.88, 99.92, 99.98, 100, 100, 100, 100])/100
timing5 = np.array([99.61, 99.88, 99.92, 99.98, 100, 100, 100, 100])/100
#绘图设置
plt.plot(snr, timing1, 'rs-', snr, timing2, 'kx-', snr, timing3, 'k+-', /
snr, timing4, 'ko-', snr, timing5, 'k*-')    #曲线设局设置,颜色+点型+线型设置
plt.xlabel('SNR/dB', fontproperties='times new roman', size=12)    #横坐标标题设置,字体、字号设置
plt.ylabel('定时正确率', size=12)    #纵坐标标题设置,字号设置
plt.xlim(-3, 11)    #横坐标轴显示范围设置(纵坐标类似)
plt.xticks(snr, fontproperties='times new roman', size=10)    #横坐标轴输出图片中显示的横坐标设置,字体、字号设置
plt.yticks(fontproperties='times new roman', size=10)    #纵坐标轴字体、字号设置

def to_percent(temp, position):
    return '%1.2f'%(100*temp) + '%'
plt.gca().yaxis.set_major_formatter(FuncFormatter(to_percent))    #纵坐标轴显示百分数

plt.legend(labels=['浮点', '定点二十', '定点廿四', '定点廿八', '定点卅二'])    #图例设置
plt.grid(True)    #网格显示控制
plt.savefig('timing', dpi=96)    #图片保存(默认png),dpi(每英寸像素点数设置)
plt.show()    #图片显示(重置画布为全白)

在这里插入图片描述

4、参考内容

微信公众号:通信随笔XIDIAN

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xidian_hxc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值