我已经计算了两个GP回归模型,并希望将它们绘制在同一张图中。
模型1
kernel = GPy.kern.RBF(input_dim=1, variance=.1, lengthscale=1.)
m1 = GPy.models.GPRegression(xa, ya,kernel)
m1.optimize_restarts(num_restarts = 10)
m1.optimize(messages=True)
from IPython.display import display
display(m1)
fig1 = m1.plot(plot_density=True)
m1.plot(plot_density=True)
GPy.plotting.show(fig2, filename='2')
模型2
m2 = GPy.models.GPRegression(xe, ye,kernel)
m2.optimize_restarts(num_restarts = 10)
m2.optimize(messages=True)
from IPython.display import display
display(m2)
fig2 = m2.plot(plot_density=True,)
GPy.plotting.show(fig2, filename='2')
我希望在matplotlib或绘图(即GPy.plotting.show(fig, filename='filename')
)中以图形形式显示两个图。
谢谢
答案 0 :(得分:1)
使用matplotlib
,您可以定义一个子图,并使用相同的轴(特别是参数ax
)指定要使用的子图。
import matplotlib.plt as plt
fig, ax = plt.subplots()
m1.plot(plot_density=True, ax=ax)
m2.plot(plot_density=True, ax=ax)
我用一个测试数据集对此进行了测试:
# Random Test Data
import pods
data = pods.datasets.olympic_marathon_men()
# First X,Y Regression Model
kernel = GPy.kern.RBF(input_dim=1, variance=.1, lengthscale=1.)
m1 = GPy.models.GPRegression(data['X'], data['Y'], kernel)
m1.optimize_restarts(num_restarts = 10)
m1.optimize(messages=True)
# Second model; changed the X, Y slightly.
m2 = GPy.models.GPRegression(data['X'] + 5, data['Y'] + 3,kernel)
m2.optimize_restarts(num_restarts = 10)
m2.optimize(messages=True)
相关: What is the best way of combining two independent plots with matplotlib?