Closed lucazav closed 10 months ago
I found that a simple print(p)
works fine. So the complete working code is as follows:
import matplotlib.pyplot as plt
import pandas as pd
from plotnine import (
options, theme_tufte, ggplot, aes, geom_bar,
geom_text, after_stat, labs
)
dataset_url = 'http://bit.ly/titanic-dataset-csv'
df = pd.read_csv(dataset_url)
p = (
ggplot(df)
+ aes(x='Pclass', fill="factor(Pclass)")
+ geom_bar()
+ geom_text(
aes(label = after_stat('count')),
stat = 'count',
nudge_x = -0.14,
nudge_y = 0.125,
va = 'bottom',
size = 8
)
+ geom_text(
aes(label = after_stat('prop*100'), group=1),
stat = 'count',
nudge_x = 0.14,
nudge_y = 0.125,
va = 'bottom',
format_string = '({:.1f}%)',
size = 8
)
+ labs(title='Passenger Count by Class',
x='Class', y='Count', fill='Class')
+ theme_tufte()
)
print(p)
I'm trying to inject the plot returned by the
draw()
method into the default Matplotlib device displayed usingplt.show()
. I need to do this because Power BI only uses the default device to display plots in Python. The code I'm using is as follows:Unfortunately I get an empty plot:
Am I doing something wrong?