{
  "__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
        },
        {
          "__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"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "ipython manual"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "ipython_github"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "nbviewer"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "ZeroMQ"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "graphviz"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Sphinx"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Sphinx reST"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "sampledoc"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "reST"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "docutils"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "lyx"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "pep8"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "GPL"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "BSD"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "LGPL"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "numpy"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "scipy"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "scipy_conference"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "matplotlib"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "pythonxy"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "ETS"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "EPD"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "python"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "mayavi"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "sympy"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "sage"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "pydy"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "vpython"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "cython"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "software carpentry"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "matlab"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "VTK"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "enthought"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "kitware"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "netlib"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "indefero"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "git"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "github"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Markdown"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Running Code in the IPython Notebook"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_p1"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Basic Output"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_p2"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Plotting with Matplotlib"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_p3"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Markdown Cells"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_p4"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Rich Display System"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_p5"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_custom_display"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Frontend/Kernel Model"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_two_proc"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Cell magics"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "notebook_cell_magics"
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Plotting"
        }
      ],
      "level": 0,
      "target": "matplotlib_magic"
    }
  ],
  "local_refs": []
}