Skip to content
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

No display in Jupyter notebooks #3

Open
quantshah opened this issue Sep 24, 2020 · 6 comments
Open

No display in Jupyter notebooks #3

quantshah opened this issue Sep 24, 2020 · 6 comments

Comments

@quantshah
Copy link

I suppose this was not the original intention of the package - to support plotting inside a notebook. But if I do this in a Jupyter notebook, I cannot see any plots:

formatter = rsmf.setup(r"\documentclass[a4paper,12pt,noarxiv]{quantumarticle}")
fig = formatter.figure(aspect_ratio=1)
ax = fig.add_subplot(111)
ax.imshow(np.random.uniform(size=(5,5)))
plt.show()

However there are no issues if I save the plot, even in a notebook.

@johannesjmeyer
Copy link
Owner

Yes, this is an issue with the PGF backend in general. Actually, rsmf is based on a notebook I made to achieve the same functionality for Quantum alone. You find it here. In certain versions of Jupyter notebook it seems to work to have both PDF output with PGF and a display of the figure, but this involves some serious hackery as you can see in the notebook (i.e. using magic commands and switching between backends). And it's not even reproducible.

I guess the most reasonable way to do it would be to load the PDF file that is created into the notebook again, as proposed here. One could make an api for that like

rsmf.save_and_show("output.pdf")

What do you think @quantshah ?

@johannesjmeyer
Copy link
Owner

I think the best would be to dynamically detect if one can import IPython and then use the approach detailed here.

@quantshah
Copy link
Author

If I use your code in the way I proposed in #4 things work out of the box in Jupyter notebooks.

@quantshah
Copy link
Author

Yes, this is an issue with the PGF backend in general. Actually, rsmf is based on a notebook I made to achieve the same functionality for Quantum alone. You find it here. In certain versions of Jupyter notebook it seems to work to have both PDF output with PGF and a display of the figure, but this involves some serious hackery as you can see in the notebook (i.e. using magic commands and switching between backends). And it's not even reproducible.

I guess the most reasonable way to do it would be to load the PDF file that is created into the notebook again, as proposed here. One could make an api for that like

rsmf.save_and_show("output.pdf")

What do you think @quantshah ?

This looks interesting but I feel like the more we keep the rsmf code in the background and use matplotlib defaults, the better. So I could make the plots show on notebooks directly and save them like regular matplotlib figures using just the initialisation at the top.

@johannesjmeyer
Copy link
Owner

Now I think the best way forward is to just wrap the IPython IFrame explained here as rsmf.show("xyz.pdf").

@johannesjmeyer
Copy link
Owner

Okay, this doesn't work as expected, see PR #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants