如何添加python';是否将ggplot对象添加到matplot网格?

如何添加python';是否将ggplot对象添加到matplot网格?,python,matplotlib,python-ggplot,Python,Matplotlib,Python Ggplot,My pandasDataFrameresults\u print具有2维图像阵列。我这样打印: n_rows = results_print.shape[0] n_cols = results_print.shape[1] f, a = plt.subplots(n_cols, n_rows, figsize=(n_rows, n_cols)) methods = ['img', 'sm', 'rbd', 'ft', 'mbd', 'binary_sal', 'sal'] for r in r

My pandas
DataFrame
results\u print具有2维图像阵列。我这样打印:

n_rows = results_print.shape[0]
n_cols = results_print.shape[1]
f, a = plt.subplots(n_cols, n_rows, figsize=(n_rows, n_cols))
methods = ['img', 'sm', 'rbd', 'ft', 'mbd', 'binary_sal', 'sal']
for r in range(n_rows):
    for c, cn in zip(range(len(methods)), methods):
        a[c][r].imshow(results_print.at[r,cn], cmap='gray')
现在,我创建了一个python ggplot图像对象:

gg = ggplot(aes(x='pixels'), data=DataFrame({'pixels': results_print.at[6,'mbd'].flatten()})) + \
    geom_density(position='identity', stat='density') + \
    xlab('pixels') + \
    ylab('') + \
    ggtitle('Density of pixels') + \
    scale_y_log()

如何将
gg
作为元素添加到matplotlib网格中?

我认为解决方案是首先绘制ggplot部分。然后通过
plt.gcf()
获取matplotlib地物对象,并通过
plt.gca()
获取轴。调整ggplot轴的大小以适合网格,并最终将其余matplotlib绘图绘制到该图形

import ggplot as gp
import matplotlib.pyplot as plt
import numpy as np
# make ggplot
g = gp.ggplot(gp.aes(x='carat', y='price'), data=gp.diamonds)
g = g + gp.geom_point()
g = g + gp.ylab(' ')+ gp.xlab(' ')
g.make()
# obtain figure from ggplot
fig = plt.gcf()
ax = plt.gca()
# adjust some of the ggplot axes' parameters
ax.set_title("ggplot plot")
ax.set_xlabel("Some x label")
ax.set_position([0.1, 0.55, 0.4, 0.4])

#plot the rest of the maplotlib plots
for i in [2,3,4]:
    ax2 = fig.add_subplot(2,2,i)
    ax2.imshow(np.random.rand(23,23))
    ax2.set_title("matplotlib plot")
plt.show()