-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add _repr_html_ for inline backend to eliminate need for %matplotlib inline #16782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Adding a |
What does this mean for this ticket? Would we change the behavior of inline wrt. life cycle management? If not is there a benefit of |
I think that we need someone with good understanding of jupyter and its repr model to answer that. I could see a path where having a |
Jupyter internals info from https://news.ycombinator.com/item?id=25923123 re: xeus-cling (c++ kernel) and widgets:
IPython and Jupyter Notebook and JupyterLab call ipympl https://github.com/matplotlib/ipympl/blob/master/ipympl/backend_nbagg.py is built atop ipywidgets: https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
I believe
but that's basically equivalent to a
Thus, closing as not planned. |
This has always been confusing to me; fig = plt.figure
[...] # plot code
display(fig)
import pandas as pd
import matplotlib.pyplot as plt
def test_example():
data = list(range(10))
df = pd.DataFrame(dict(x=data))
print(1, data)
display(2, 'two')
df.plot(legend=True)
#plt.show()
##display(plt) # -> plt._repr_html_()
display(4, data)
test_example()
|
@westurner https://github.com/matplotlib/mpl-gui may also be of interest to you as might matplotlib/ipympl#171 |
|
There could also or instead be a per-cell That's how ipytest works. An example use case with %%ipytest
from matplotlib.pyplot import plt
def test_thing1():
data = range(10)
df = pd.DataFrame(dict(x=data))
print(1, data)
display(2, 'two')
display(3)
df.plot(legend=True)
# plt.show()
# display(plt)
# -> cell_output[n]['text/html'] = plt._repr_html_()
display(4, data)
assert bool(plt)
#test_thing1() # ipytest automatically calls this (after preprocessing lines with assert keywords) because it starts with test_ But then there would need to be multiple IPython cell magics though; What people typically do, FWIU: %matplotlib inline
# import matplotlib.pyplot as plt df = pd.DataFrame(dict(x=[1,2,3])
df.plot(legend=True)
#%pip install -q ipytest
#%%ipytest
def test_thing1():
df = pd.DataFrame(dict(x=list(range(10)))
df.plot(legend=True)
_ = df.plot(legend=True, kind='scatter')
assert isinstance(_, bool)
test_thing1() |
When launching a jupyter notebook, the environment variable
MPLBACKEND
is set to inline, but figures will still not be displayed in the output unless%matplotlib inline
orimport matplotlib.pyplot
is run. Both of these commands hook IPython to a function that gets triggered whenever a Figure is the output from a cell. This function is responsible for printing the figure to the screen.Proposed solution:
A
_repr_html_
method exists for figures, but is only implemented for webagg backends. Something like the following could be added to_repr_html_
.This is @tacaswell's idea. I previously created an issue with IPython - ipython/ipython#12190 (comment)
The text was updated successfully, but these errors were encountered: