Ipython fails to display matplotlib fig directly

See my following example:

In [8]: %matplotlib inline
   ...: 
   ...: import matplotlib.pyplot as plt
   ...: import matplotlib.ticker as ticker
   ...: 
   ...: # Create a simple plot
   ...: fig, ax = plt.subplots()
   ...: ax.plot([1, 2, 3, 4], [10, 20, 15, 25])
   ...: 
   ...: # Use AutoLocator to dynamically determine tick positions
   ...: ax.xaxis.set_major_locator(ticker.AutoLocator())
   ...: 
   ...: plt.show()
Shell is already running a gui event loop for tk. Call with no arguments to disable the current loop.
<Figure size 640x480 with 1 Axes>

How can I let ipython display the matplotlib fig directly?

See here for the related discussion.

Regards,
Zhao

Have you tried putting %matplotlib inline in a separate cell?

See below, but I’m not sure if I understand you correctly:

Installed gtk4 event loop hook.

This happens immediately on start, so you must have some configuration picking it. I don’t know where to find that, but I’m sure it’s somewhere in the IPython docs.

However, the inline backend doesn’t display in the IPython console. That’s for inline in the notebook. I’m not aware of a method of displaying figures in the console directly.

This happens immediately on start, so you must have some configuration picking it. I don’t know where to find that, but I’m sure it’s somewhere in the IPython docs.

According to the description here, it’s controlled by c.InteractiveShellApp.gui, but I don’t set this option at all:

(datasci) werner@X10DAi:~/.ipython/profile_default$ ug c.InteractiveShellApp
ipython_config.py:c.InteractiveShellApp.matplotlib = 'inline'

See below for the configurations done before:

(datasci) werner@X10DAi:~/.ipython/profile_default$ cat ipython_config.py
#https://github.com/astoff/comint-mime/issues/2#issuecomment-922462074
#$ ipython -h|egrep -B5 'InteractiveShellApp.matplotlib|InteractiveShellApp.pylab'
#--pylab
#    Pre-load matplotlib and numpy for interactive use with
#    the default matplotlib backend.
#    Equivalent to: [--InteractiveShellApp.pylab=auto]
#--matplotlib
#    Configure matplotlib for interactive use with
#    the default matplotlib backend.
#    Equivalent to: [--InteractiveShellApp.matplotlib=auto]
#--
#--pylab=<CaselessStrEnum>
#    Pre-load matplotlib and numpy for interactive use, selecting a particular
#    matplotlib backend and loop integration.
#    Choices: any of ['auto', 'agg', 'gtk', 'gtk3', 'inline', 'ipympl', 'nbagg', 'notebook', 'osx', 'pdf', 'ps', 'qt', 'qt4', 'qt5', 'svg', 'tk', 'widget', 'wx'] (case-insensitive) or None
#    Default: None
#    Equivalent to: [--InteractiveShellApp.pylab]
#--matplotlib=<CaselessStrEnum>
#    Configure matplotlib for interactive use with the default matplotlib
#    backend.
#    Choices: any of ['auto', 'agg', 'gtk', 'gtk3', 'inline', 'ipympl', 'nbagg', 'notebook', 'osx', 'pdf', 'ps', 'qt', 'qt4', 'qt5', 'svg', 'tk', 'widget', 'wx'] (case-insensitive) or None
#    Default: None
#    Equivalent to: [--InteractiveShellApp.matplotlib]
c.InteractiveShellApp.matplotlib = 'inline'

#$ ipython --help | grep -A2 -- --pdb
#--pdb
#    Enable auto calling the pdb debugger after every exception.
#    Equivalent to: [--InteractiveShell.pdb=True]


#$ ipython -h | grep -A3 -- -automagic
#--automagic
#    Turn on the auto calling of magic commands. Type %%magic at the
#    IPython  prompt  for  more information.
#    Equivalent to: [--InteractiveShell.automagic=True]
#--no-automagic
#    Turn off the auto calling of magic commands.
#    Equivalent to: [--InteractiveShell.automagic=False]