rnso
rnso

Reputation: 24613

Why a ggplot is not showing here?

I am using code from here trying to produce a simple plot:

from lets_plot import *
LetsPlot.setup_html()        

import numpy as np
np.random.seed(12)

data = dict(
    cond=np.repeat(['A','B'], 200),
    rating=np.concatenate((np.random.normal(0, 1, 200), np.random.normal(1, 1.5, 200)))
)

ggplot(data, aes(x='rating', fill='cond')) + ggsize(500, 250) \
+ geom_density(color='dark_green', alpha=.7) + scale_fill_brewer(type='seq') \
+ theme(axis_line_y='blank')

I am running this code from a standalone file using command line:

python3 mycode.py

It runs without any error but no plot shows up. I have also tried following but it does not work:

gg = ggplot(....
print(gg)

Above outputs data and layers on console but no plot is shown.

Adding following also does not help:

import matplotlib.pyplot as plt

Where is the problem and how can I get a plot to be displayed with above code?

Upvotes: 1

Views: 238

Answers (1)

sai
sai

Reputation: 1784

The package seems to depend on JavaScript(JS) for displaying visulisations and seems to be built to supprt online notebooks as it says on the github page - Lets-Plot meant for

However, there does seem to be a plugin available for pycharm and IntelliJ IDEA but the one on pycharm is available only in professional version.

So with this new information, I have tried running an instance of Jupyter notebook online and running the same piece of code produces the graph is expected.

Upvotes: 2

Related Questions