I use below org code to draw a graph, but the graph not show on results block:

#+BEGIN_SRC ipython :results drawer :session py2session
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

plt.hist(np.random.randn(500000), bins=100);

<matplotlib.figure.Figure at 0x112819f90>

How can I draw the output graph from ipython to results block?


Your example works perfectly in my setup.

First make sure ipython-ob is included in the babel-languages: in my case:

 '((python . t)
   (ipython . t)
   (ledger . t)
   (latex . t)
   (clojure .t)
   (shell .t)

THEN display images online added to your init file:

(add-hook 'org-babel-after-execute-hook 'org-display-inline-images 'append)

The plot as it should be]

  • Thanks, I use minimal config just the same as yours but it still doesn't work! I am using MacOsx and emacs version is 25.2, Not sure if any other config impact on this case!
    – lucky1928
    Sep 5 '18 at 16:42
  • Just to confirm... You aren't trying this in terminal, right? Sep 5 '18 at 21:26
  • Right, I run it in GUI, try it with -nw option also, behavior the same.
    – lucky1928
    Sep 6 '18 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.