{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "interactive:plotting",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "One of the main feature of IPython when used as a kernel is its ability to show rich output. This means that object that can be representing as image, sounds, animation, (etc...) can be shown this way if the frontend support it."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In order for this to be possible, you need to use the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "display()"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " function, which you can import with "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "from IPython.display import display"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Then use "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "display(<your object>)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " instead of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "print()"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and if possible your object will be displayed with a richer representation. In the terminal of course, there won't be much difference as objects are most of the time represented by text, but in notebook and similar interface you will get richer outputs."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Rich Outputs"
        }
      ],
      "level": 0,
      "target": "plotting"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "You can avoid the use of IPython's specific magic and use "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "matplotlib.pyplot.ion()"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "/"
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "matplotlib.pyplot.ioff()"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " which have the advantages of working outside of IPython as well."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "One major feature of the IPython kernel is the ability to display plots that are the output of running code cells. The IPython kernel is designed to work seamlessly with the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "matplotlib_",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " plotting library to provide this functionality."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To set this up, before any plotting or import of matplotlib is performed you may execute the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "%matplotlib"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "magic command",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "interactive:tutorial"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". This performs the necessary behind-the-scenes setup for IPython to work correctly hand in hand with "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "matplotlib"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "; it does "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "not"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", however, actually execute any Python "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "import"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " commands, that is, no names are added to the namespace."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If you do not use the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "%matplotlib"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " magic or you call it without an argument, the output of a plotting command is displayed using the default "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "matplotlib"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " backend, which may be different depending on Operating System and whether running within Jupyter or not."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Alternatively, the backend can be explicitly requested using, for example    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "%matplotlib gtk",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The argument passed to the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "%matplotlib"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " magic command may be the name of any backend understood by "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "matplotlib"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or it may the name of a GUI loop such as "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "qt"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "osx"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", in which case an appropriate backend supporting that GUI loop will be selected. To obtain a full list of all backends and GUI loops understood by "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "matplotlib"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " use "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "%matplotlib --list"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are some specific backends that are used in the Jupyter ecosystem:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "inline"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " backend is provided by IPython and can be used in Jupyter Lab,   Notebook and QtConsole; it is the default backend when using Jupyter. The   outputs of plotting commands are displayed "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "inline"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " within frontends like   Jupyter Notebook, directly below the code cells that produced them.   The resulting plots will then also be stored in the notebook document."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "notebook"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nbagg"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " backend is built into "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "matplotlib"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and can be   used with Jupyter "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "notebook <7"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "nbclassic"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Plots are interactive so   they can be zoomed and panned."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "ipympl"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "widget"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " backend is for use with Jupyter "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "lab"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "notebook >=7"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". It is in a separate "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "ipympl"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " module that must be   installed using "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "pip"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "conda"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " in the usual manner. Plots are   interactive so they can be zoomed and panned."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "seealso",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "seealso "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "Plotting with Matplotlib",
                  "domain": null,
                  "role": null,
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "  example notebook"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "See the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "matplotlib_",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " documentation for more information, in particular the section on backends."
            }
          ]
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "ipython",
          "url": "https://ipython.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "ipython manual",
          "url": "https://ipython.org/documentation.html"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "ipython_github",
          "url": "https://github.com/ipython/ipython/"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "nbviewer",
          "url": "https://nbviewer.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "ZeroMQ",
          "url": "https://zeromq.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "graphviz",
          "url": "https://www.graphviz.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Sphinx",
          "url": "https://www.sphinx-doc.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Sphinx reST",
          "url": "https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "sampledoc",
          "url": "https://matplotlib.org/sampledoc"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "reST",
          "url": "https://docutils.sourceforge.io/rst.html"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "docutils",
          "url": "https://docutils.sourceforge.io"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "lyx",
          "url": "https://www.lyx.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "pep8",
          "url": "https://peps.python.org/pep-0008/"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "GPL",
          "url": "https://www.gnu.org/licenses/gpl.html"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "BSD",
          "url": "https://opensource.org/licenses/BSD-3-Clause"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "LGPL",
          "url": "https://www.gnu.org/copyleft/lesser.html"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "numpy",
          "url": "https://numpy.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "scipy",
          "url": "https://www.scipy.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "scipy_conference",
          "url": "https://conference.scipy.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "matplotlib",
          "url": "https://matplotlib.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "pythonxy",
          "url": "https://python-xy.github.io/"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "ETS",
          "url": "https://docs.enthought.com/ets/"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "EPD",
          "url": "https://www.enthought.com/products/epd/"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "python",
          "url": "https://www.python.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "mayavi",
          "url": "https://docs.enthought.com/mayavi/mayavi/"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "sympy",
          "url": "https://www.sympy.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "sage",
          "url": "https://www.sagemath.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "pydy",
          "url": "https://www.pydy.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "vpython",
          "url": "https://vpython.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "cython",
          "url": "https://cython.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "software carpentry",
          "url": "https://software-carpentry.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "matlab",
          "url": "https://www.mathworks.com"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "VTK",
          "url": "https://vtk.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "enthought",
          "url": "https://www.enthought.com"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "kitware",
          "url": "https://www.kitware.com"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "netlib",
          "url": "https://netlib.org"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "indefero",
          "url": "https://www.indefero.net"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "git",
          "url": "https://git-scm.com"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "github",
          "url": "https://github.com"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Markdown",
          "url": "https://daringfireball.net/projects/markdown/syntax"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Running Code in the IPython Notebook",
          "url": "notebook_p1_"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_p1",
          "url": "https://nbviewer.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Part%25201%2520-%2520Running%2520Code.ipynb"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Basic Output",
          "url": "notebook_p2_"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_p2",
          "url": "https://nbviewer.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Part%202%20-%20Basic%20Output.ipynb"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Plotting with Matplotlib",
          "url": "notebook_p3_"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_p3",
          "url": "https://nbviewer.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Part%203%20-%20Plotting%20with%20Matplotlib.ipynb"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Markdown Cells",
          "url": "notebook_p4_"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_p4",
          "url": "https://nbviewer.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Part%204%20-%20Markdown%20Cells.ipynb"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Rich Display System",
          "url": "notebook_p5_"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_p5",
          "url": "https://nbviewer.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Part%205%20-%20Rich%20Display%20System.ipynb"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_custom_display",
          "url": "https://nbviewer.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Custom%20Display%20Logic.ipynb"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Frontend/Kernel Model",
          "url": "notebook_two_proc_"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_two_proc",
          "url": "https://nbviewer.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Frontend-Kernel%20Model.ipynb"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Cell magics",
          "url": "notebook_cell_magics_"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_cell_magics",
          "url": "https://nbviewer.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Cell%20Magics.ipynb"
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Plotting"
        }
      ],
      "level": 0,
      "target": "matplotlib_magic"
    }
  ],
  "local_refs": []
}