My pandas DataFrame
results_print has 2-dim arrays that are images. I print them like so:
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')
Now I created a python ggplot image object:
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()
How can I add the gg
as an element to my matplotlib grid?
I think the solution would be to first draw the ggplot part. Then obtain the matplotlib figure object via
plt.gcf()
and the axes viaplt.gca()
. Resize the ggplot axes to fit into a grid and finally draw the rest of the matplotlib plots to that figure.