{"id":16567906,"url":"https://github.com/drorata/org-babel-matplotlib-integration","last_synced_at":"2026-03-07T17:34:01.809Z","repository":{"id":32264950,"uuid":"35839472","full_name":"drorata/org-babel-matplotlib-integration","owner":"drorata","description":null,"archived":false,"fork":false,"pushed_at":"2015-05-26T11:45:15.000Z","size":128,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T10:46:36.717Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drorata.png","metadata":{"files":{"readme":"readme.org","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-18T20:00:02.000Z","updated_at":"2015-05-18T20:00:02.000Z","dependencies_parsed_at":"2022-09-23T02:00:48.378Z","dependency_job_id":null,"html_url":"https://github.com/drorata/org-babel-matplotlib-integration","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drorata/org-babel-matplotlib-integration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Forg-babel-matplotlib-integration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Forg-babel-matplotlib-integration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Forg-babel-matplotlib-integration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Forg-babel-matplotlib-integration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drorata","download_url":"https://codeload.github.com/drorata/org-babel-matplotlib-integration/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Forg-babel-matplotlib-integration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30223448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T17:00:40.062Z","status":"ssl_error","status_checked_at":"2026-03-07T17:00:39.026Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T21:07:46.194Z","updated_at":"2026-03-07T17:34:01.769Z","avatar_url":"https://github.com/drorata.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"#+TITLE: Integrate matplotlib figures in an org mode buffer\n* Goal\nThe ultimate goal is to use org-babel as a replacement of IPython. The\nfirst motivation is to enable an easier version controling of the\ndocument. The first challenge I faced is integration of plots returned\nby ~matplotlib~ in the org buffer.\n* Capturing filename\n\nI would like to use (babel) orgmode as an interactive python\nnotebook. Therefore, in order to allow the various code blocks to\n\"know\" each other, it is important to use the ~:session~ option for\nall relevant code blocks. However, once ~:session~ is used, together\nwith ~matplotlib~ the desired behavior is no longer in place under Mac\nOS X.\n\n* Clean testing, no Matplotlib\nFor the sake of testing, the following merely suppose to return the\nfilename in an orgmode'ish link format:\n\n#+BEGIN_SRC python :session no_matplotlib :results file :exports both\nx = 'hello '\ny = 'world'\nz = x + y\n'foo.bar'\n#+END_SRC\n\n#+RESULTS:\n[[file:foo.bar]]\n\n*Passed* Indeed, the ~RESULTS~ block contains a link to the filename\nindicated by the last string.\n\n* Importing Matplotlib\n\nThe following minimal example should generate a simple figure,\n~myfig.png~, and orgmode should capture it and interpret it as a\nfilename to be used by the following ~RESULTS~ block.\n\n#+BEGIN_SRC python :session with_matplotlib :results file :exports both\nimport matplotlib\nmatplotlib.use('Agg')\nimport matplotlib.pyplot as plt\nfig=plt.figure(figsize=(3,2))\nplt.plot([1,3,2])\nplt.savefig('myfig.png')\n'myfig.png'\n#+END_SRC\n\n#+RESULTS:\n[[file:]]\n\n*Failed!* This time, it doesn't work anymore. The file ~myfig.png~ is\n properly generated, but the last string is not captured by\n ~matplotlib~. Following is the content of the corresponding\n interactive python session:\n\n#+BEGIN_SRC\nProcess with_matplotlib finished\nPython 3.4.3 (default, Mar 10 2015, 14:53:35)\n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\u003e\u003e\u003e \u003e\u003e\u003e \u003e\u003e\u003e , '''/var/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/py44814koH''', 'exec'));\nimport matplotlib\n\u003e\u003e\u003e import matplotlib\nmatplotlib.use('Agg')\nmatplotlib.use('Agg')\nimport matplotlib.pyplot as plt\nimport matplotlib.pyplot as plt\nfig=plt.figure(figsize=(3,2))\nfig=plt.figure(figsize=(3,2))\nplt.plot([1,3,2])\nplt.plot([1,3,2])\nplt.savefig('myfig.png')\nplt.savefig('myfig.png')\n'myfig.png'\n'myfig.png'\n\n\nopen('/var/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/babel-44814cA3/python-44814xyN', 'w').write(str(_))\nopen('/var/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/babel-44814cA3/python-44814xyN', 'w').write(str(_))\n\n\n\n\n'org_babel_python_eoe'\n'org_babel_python_eoe'\n\u003e\u003e\u003e \u003e\u003e\u003e \u003e\u003e\u003e \u003e\u003e\u003e [\u003cmatplotlib.lines.Line2D object at 0x10cf21828\u003e]\n\u003e\u003e\u003e 'myfig.png'\n\u003e\u003e\u003e \u003e\u003e\u003e 9\n\u003e\u003e\u003e \u003e\u003e\u003e \u003e\u003e\u003e 'org_babel_python_eoe'\n\u003e\u003e\u003e\n#+END_SRC\n\nIt seems like ~ob-python.el~ manages to create the correct temp file,\nbut somehow it is not capturing the filename and doesn't plug it into\nthe right place in the results block.\n\n* Some background\n\n** Python Version\n#+BEGIN_SRC python :session background :results raw\nimport sys\nsys.version\n#+END_SRC\n\n#+RESULTS:\n3.4.3 (default, Mar 10 2015, 14:53:35)\n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)]\n\n** Matplotlib version\n#+BEGIN_SRC python :session background :results raw\nimport matplotlib\nmatplotlib.__version__\n#+END_SRC\n\n#+RESULTS:\n1.4.3\n\n** System\nI am running Emacs version ~GNU Emacs 24.5.1 (x86_64-apple-darwin14.1.0, NS apple-appkit-1344.72) of 2015-04-19 on tenten-slave.macports.org~\n\nThe orgmode version is: ~Org-mode version 8.2.10 (8.2.10-40-gc763fa-elpaplus @ /Users/drorata/.emacs.d/elpa/org-plus-contrib-20150518/)~\n\n** Stackoverflow reference\nI also posted a question in the SE network:\n[[http://emacs.stackexchange.com/questions/11075/org-mode-python-session-does-not-return-a-file-name]]\n\n* Question\nSo, my question is how to tackle/debug this issue? Can someone give me\na hand here? That would be really great! Thanks!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrorata%2Forg-babel-matplotlib-integration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrorata%2Forg-babel-matplotlib-integration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrorata%2Forg-babel-matplotlib-integration/lists"}