论文matplotlib作图

matplotlib绘制并列柱状图

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False

x = np.arange(3)
y = [67.73,67.76,68.09]
y1 = [67.93,67.83,68.12]
y2= [67.98,68.01,68.17]

bar_width = 0.25
tick_label = ["LSTUR", "NRMS", "HPHN"]

plt.bar(x, y, bar_width, align="center", color="c", label="glove", alpha=0.5)
plt.bar(x+bar_width, y1, bar_width, color="b", align="center", label="bert-base", alpha=0.5)
plt.bar(x+2*bar_width, y2, bar_width, color="'#FF6347'", align="center", label="robert-base", alpha=0.5)


plt.ylabel("AUC")
plt.ylim(67.5,68.3)

plt.xticks(x+bar_width/2, tick_label)
plt.legend()
plt.show()

绘制效果如下:

在这里插入图片描述

matplotlib绘制拟合曲线图

from matplotlib import pyplot as plt
import numpy as np
from scipy.interpolate import make_interp_spline

#   Instanciating my lists...
f = lambda x:x**2
x = [nb for nb in range(1, 129)]
y = [f(nb) for nb in x]

x1=np.array([0,8,16,32,64,128,256,512,1024,2048])
y1=np.array([67.81,65,65.2,65.3,65.8,66.1,66.3,67.6,68.09,68.1])

x2=np.array([1,16,32,64,128,256,512])
y2=np.array([65.2,65.7,66.3,67.8,68.09,67.92,67.96])

#   New values you want to plot, with linear spacing.
indexes_to_keep1 = [0,8,16,32,64,128,256,512,1024,2048]

#   First plot that shows the 128 points as a whole.
fig = plt.figure(figsize=(10, 5.4))
ax1 = fig.add_subplot(121)
#   my_ticks = [1, 2, 3, 4, 5, 6, 7]
#   meaning : my_ticks will be linear values.
my_ticks1 = [i for i in range(len(indexes_to_keep1))]
#   We set the ticks we want to show, meaning : all our list
#   instead of some linear spacing matplotlib will show by default
ax1.set_xticks(my_ticks1)
#   Then, we manually change the name of the X ticks.
ax1.set_xticklabels(indexes_to_keep1)
#   We will then, plot the LINEAR x axis,
#   but with respect to the y-axis values pre-processed.
ax1.plot(my_ticks1,y1,'o',markersize=5)
print(my_ticks1)
x1_smooth = np.linspace(0,9,50000) #300 represents number of points to make between x.min and x.max
y1_smooth = make_interp_spline(my_ticks1, y1)(x1_smooth)
plt.ylabel("AUC")
plt.plot(x1_smooth,y1_smooth,'r')
ax1.set_title('h-Number of Hash Buckets')




indexes_to_keep2 = [1,16,32,64,128,256,512]

#   Second plot that shows only the indexes you wish to keep.
ax2 = fig.add_subplot(122)
#   my_ticks = [1, 2, 3, 4, 5, 6, 7]
#   meaning : my_ticks will be linear values.
my_ticks2 = [i for i in range(len(indexes_to_keep2))]
#   We set the ticks we want to show, meaning : all our list
#   instead of some linear spacing matplotlib will show by default
ax2.set_xticks(my_ticks2)
#   Then, we manually change the name of the X ticks.
ax2.set_xticklabels(indexes_to_keep2)
#   We will then, plot the LINEAR x axis,
#   but with respect to the y-axis values pre-processed.
ax2.plot(my_ticks2,y2,'o',markersize=5)
print(my_ticks2)
x2_smooth = np.linspace(0,6,50000) #300 represents number of points to make between x.min and x.max
y2_smooth = make_interp_spline(my_ticks2, y2)(x2_smooth)
plt.ylabel("AUC")
plt.plot(x2_smooth,y2_smooth,'r')
ax2.set_title('K – Top Exploration Number')

plt.show()

作图说明:
由坐标轴上的散点图去拟合曲线,横坐标为 2 n 2^n 2n,不是均分分布,纵坐标为AUC的得分,绘制结果如下:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值