Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotnine: How remove the ggplot:(xxx) type annoying text output when plotting a graph

  • Running jupyter notebook (python)
  • Plotting using Python Plotnine library
  • I plot and below the output graphic is annoying "ggplot2: (number)" output
  • Normally you would put a ; at the end of your notebook cell, but it doesn't seem to supress the annoying output text when i use Plotnine (but it does obviously work for matplotlib, etc)

Any ideas ?

like image 854
TexasTom Avatar asked Nov 29 '18 16:11

TexasTom


1 Answers

The point is in calling draw() method with semicolon at the end.

Fully working example:

import pandas
from plotnine import *
from random import randint

# 100 random numbers
random_numbers = [randint(1, 100) for p in range(0, 100)]

# Create DataFrame
df = pd.DataFrame({'number': random_numbers})

# Draw plot
(
    ggplot(df, aes(x='number')) + 
    geom_histogram(bins=20, na_rm=True) +
    ggtitle('Histogram of random numbers') +
    theme_light()
).draw();
like image 76
Stefan Simik Avatar answered Oct 10 '22 23:10

Stefan Simik