def pil2ipyimage(image, height=None, width=None): """ Convert PILLOW image to ipython Image Parameters ---------- image : pil.Image pillow image object height: int height to resize the returned image widget parameter will keep proportions width: int height to resize the returned image widget parameter will keep proportions """ b = BytesIO() image.save(b, format='png') data = b.getvalue() image_widget = display.Image(data, format='png', height=height, width=width) return image_widget
from rpy2.robjects.packages import importr grdevices = importr('grDevices') grdevices.png(file='Rpy2.png', width=800, height=400) ro.r('library("MASS"); library("nnet"); '+\ 'data(Boston); n<-dim(Boston)[1]') ro.r('model<-nnet(as.matrix(Boston[1:430,-14]),'+\ 'as.matrix(Boston[1:430,14]),'+\ 'size=52,trace=FALSE,maxit=10^3,linout=TRUE,decay=.1^5); '+\ 'predictions<-predict(model,'+\ 'as.matrix(Boston[431:n,-14]),type="raw")') ro.r('plot(as.matrix(Boston[431:n,14]),col="black",type="o",'+\ 'xlab="",ylab="",yaxt="n"); par(new=TRUE); '+\ 'plot(predictions,col="#348abd",type="o",'+\ 'cex=1.3,ylab="Targets & Predictions"); grid();') grdevices.dev_off() display.Image('Rpy2.png') """``` %%r library('MASS'); library('nnet') data(Boston); n<-dim(Boston)[1]; svg(filename='Rplots.svg',width=10,height=6,pointsize=12,onefile=TRUE, family='times',bg='white',antialias=c('default','none','gray','subpixel')) model<-nnet(as.matrix(Boston[1:430,-14]),as.matrix(Boston[1:430,14]), size=65,trace=FALSE,maxit=10^3,linout=TRUE,decay=.1^5) predictions<-predict(model,as.matrix(Boston[431:n,-14]),type='raw') plot(as.matrix(Boston[431:n,14]),col='black',type='o', xlab='',ylab='',yaxt='n'); par(new=TRUE) plot(predictions,col='#348abd',type='o', cex=1.3,ylab='Targets & Predictions') grid(); dev.off() ```
def _display_image(self): '''for testing ''' from IPython import display im_bytes = base64.b64decode(self._image_data) return display.Image(im_bytes)
def _display_image(self): '''for testing ''' from IPython import display return display.Image(self._image_data)