(学术论文版)Python绘制双曲线图(以RMSE/MSE为例)

1. 导入相关的包

import pandas as pd
from random import random
from pylab import *
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
mpl.rcParams['font.sans-serif'] = ['Times New Roman']
import matplotlib.ticker as mticker  
import matplotlib
matplotlib.rcParams['font.family'] = 'sans-serif'  
matplotlib.rcParams['font.sans-serif'] = 'NSimSun,Times New Roman'# 中文设置成宋体,除此之外的字体设置成New Roman 

2. 声明双曲线函数

def draw(lx, dy):
    fyt = list(dy.keys())[0]
    syt = list(dy.keys())[1]
    plt.figure(figsize=(2.5, 3), dpi=120)
    plt.plot(lx, dy.get(fyt), label=fyt, linewidth=0.8, color='b',marker='s')
    plt.grid(linestyle="--", alpha=0.3)
    plt.xticks(fontproperties='Times New Roman', fontweight='bold')
    # 调整y轴的刻度
    plt.yticks([0.2,0.4,0.6,0.8],fontproperties='Times New Roman', fontweight='bold')
    plt.ylabel(fyt, fontsize=10,fontproperties='Times New Roman', fontweight='bold')
    plt.legend(loc='upper left') # 
    plt.twinx()
    plt.plot(lx, dy.get(syt), label=syt, linewidth=0.8, color='r',marker='o')
    plt.ylabel(syt, fontsize=10,fontproperties='Times New Roman', fontweight='bold')
    # 调整y轴的刻度
    plt.yticks([0.2,0.4,0.6,0.8],fontproperties='Times New Roman', fontweight='bold')
    plt.legend(loc='upper right')#
    ax = plt.gca()
    ax.xaxis.set_major_locator(MultipleLocator(10))
    plt.show()

3. 调用函数,输入参数

"""主函数"""
lx = [10, 20, 30, 40, 50]
y1 = [0.1,0.2,0.3,0.4,0.6]
y2 = [0.6,0.4,0.3,0.3,0.1]
dy = {"Number for ST":y1, 'MAE': y2}
lxx = [str(i) for i in list(lx)]
draw(lx, dy)
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值