ipython / ipykernel

IPython Kernel for Jupyter
https://ipykernel.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
646 stars 365 forks source link

activate_matplotlib() is not called. #247

Open iktakahiro opened 7 years ago

iktakahiro commented 7 years ago

Summary

Unless you intentionally omitted it, It seems to need to call IPython.core.pylabtools.activate_matplotlib() function in _enable_matplotlib_integration().

Details

Since version 4.4.0, the default backend has been changed to inline (module://ipykernel.pylab.backend_inline). In this issue, it's called default inline mode.

Consequently, we no longer need to specify inline mode using %matplotlib inline with Jupyter Notebook. The mode when using the magic command is called explicit inline mode.

However, I've realized that the behavior of default inline mode and that of explicit inline mode are different.

  1. the behavior of default inline mode
from matplotlib import pyplot as plt

x = [1, 2, 3]
y = [3, 6, 9]

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title('Sample Bar Chart')

default-inline

The figure is not rendered when a code-cell is executed. To render a graph, I have to callplt.show().

  1. In the case of explicitly inline mode.
from matplotlib import pyplot as plt
%matplotlib inline

x = [1, 2, 3]
y = [3, 6, 9]

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title('Sample Bar Chart')

explicityly-inilne

The figure is rendered even if plot.show() is not executed.

I don't know whether these behaviors are correct or not. On the other hand, I think that users are confused by it.

Proposals

When %matplotlib inline is called, configure_inline_support() function and activate_matplotlib() are executed ^1 . But in _enable_matplotlib_integration(), activate_matplotlib() is not called.

Therefor, maybe simply it should be called in the Initialization process.

Could you tell me your opinion?

minrk commented 7 years ago

closed by #264

darthoctopus commented 6 years ago

I would prefer a configuration option for this please. With the old behaviour one could choose between the two modes, but as of now I cannot opt out of explicit inline mode (leading to loss of functionality).