首页 > 解决方案 > Plotnine:绘制图形时如何删除 ggplot:(xxx) 类型烦人的文本输出

问题描述

有任何想法吗 ?

标签: pythonggplot2jupyter-notebookplotnine

解决方案


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();

推荐阅读