Plotnine plots not showing up

See original GitHub issue

I am running the example code from the plotnine website using a script. The plot shows up with the exact same code in Jupyter, but not in Spyder (neither inline, nor in the Plots window)

from plotnine import ggplot, geom_point, aes, stat_smooth, facet_wrap
from plotnine.data import mtcars

(ggplot(mtcars, aes('wt', 'mpg', color='factor(gear)'))
 + geom_point()
 + stat_smooth(method='lm')
 + facet_wrap('~gear'))

Found a workaround but hoping for a more practical solution. I slightly modify the ggplot code in the script to ss=(ggplot(mtcars, aes('wt', 'mpg', color='factor(gear)'))) and then type the following into the console: (ss+ geom_point() + stat_smooth(method='lm') + facet_wrap('~gear'))

Versions

  • Spyder version: 4.1.4
  • Python version: 3.7.6
  • Qt version: 5.9.6
  • PyQt5 version: 5.9.2
  • Operating System: Windows 10

Dependencies


# Mandatory:
atomicwrites >=1.2.0           :  1.4.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.5.0 (OK)
diff_match_patch >=20181111    :  20200713 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.16.1 (OK)
jedi =0.17.1                   :  0.17.1 (OK)
nbconvert >=4.0                :  5.6.1 (OK)
numpydoc >=0.6.0               :  1.1.0 (OK)
paramiko >=2.4.0               :  2.7.1 (OK)
parso =0.7.0                   :  0.7.0 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.7.0 (OK)
pygments >=2.0                 :  2.6.1 (OK)
pylint >=1.0                   :  2.5.3 (OK)
pyls >=0.34.0;<1.0.0           :  0.34.1 (OK)
qdarkstyle >=2.8               :  2.8.1 (OK)
qtawesome >=0.5.7              :  0.7.2 (OK)
qtconsole >=4.6.0              :  4.7.5 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.4 (OK)
sphinx >=0.6.6                 :  3.1.2 (OK)
spyder_kernels >=1.9.2;<1.10.0 :  1.9.2 (OK)
watchdog                       :  None (OK)
zmq >=17                       :  19.0.1 (OK)

# Optional:
cython >=0.21                  :  0.29.21 (OK)
matplotlib >=2.0.0             :  3.2.2 (OK)
numpy >=1.7                    :  1.18.5 (OK)
pandas >=0.13.1                :  1.0.5 (OK)
scipy >=0.17.0                 :  1.5.0 (OK)
sympy >=0.7.3                  :  1.6.1 (OK)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
impact27commented, Aug 13, 2020

So the answer is: you need to print the object:

from plotnine import ggplot, geom_point, aes, stat_smooth, facet_wrap
from plotnine.data import mtcars

a = (ggplot(mtcars, aes('wt', 'mpg', color='factor(gear)'))
 + geom_point()
 + stat_smooth(method='lm')
 + facet_wrap('~gear'))

print(a)
1reaction
SalenaAshtoncommented, May 20, 2022

This worked for me too, using vim on ubuntu. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Why is the plot generated from ggplot not showing up?
I am not sure about this but does ggplot have a show() method ? I have only used show() method from pyplot (matplotlib)....
Read more >
how to display plotnine plot? : r/Python - Reddit
When I run this a window with the plot is displayed. However this does not work: import sys sys.path.append('/home/mh/pymods') from plotnine ...
Read more >
Making Plots With plotnine - Data Carpentry
Objectives. Create a plotnine object. Set universal plot settings. Modify an existing plotnine object. Change the aesthetics of a plot such as color....
Read more >
A Grammar of Graphics for Python — plotnine 0.10.1 ...
The grammar allows users to compose plots by explicitly mapping data to the visual objects that make up the plot. Plotting with a...
Read more >
Plotting with ggplot for Python - Introduction to Python Workshop
Making Plots With plotnine (aka ggplot); Introduction ... Let's set up our working environment with necessary libraries and also load our csv file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found