Home  >  Article  >  Backend Development  >  Why Can't I Display Matplotlib Plots Inline in My IPython Notebook?

Why Can't I Display Matplotlib Plots Inline in My IPython Notebook?

DDD
DDDOriginal
2024-11-08 07:52:02923browse

Why Can't I Display Matplotlib Plots Inline in My IPython Notebook?

How to Display Matplotlib Plots Inline in IPython Notebook

Question:

When using IPython notebook on macOS with specific Python and IPython versions, matplotlib graphics fail to display inline. Commands such as %matplotlib inline, %pylab inline, and ipython command line arguments do not resolve the issue. Instead, numeric figures are displayed.

Answer:

To enable inline plotting, follow these steps:

  1. In the first cell of the IPython notebook, execute the command %matplotlib inline.
  2. Import necessary modules:
import matplotlib
import numpy as np
import matplotlib.pyplot as plt

Alternatively, you can set the following configuration options in your config files to always start IPython kernels in inline mode by default:

c.IPKernelApp.matplotlib = <CaselessStrEnum>
  Default: None
  Choices: ['auto', 'gtk', 'gtk3', 'inline', 'nbagg', 'notebook', 'osx', 'qt', 'qt4', 'qt5', 'tk', 'wx']
  Configure matplotlib for interactive use with the default matplotlib backend.

The above is the detailed content of Why Can't I Display Matplotlib Plots Inline in My IPython Notebook?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn