How to export an jupyter interactive output within vsc as pdf - python

I am using visual studio code and I am using the python extension to run jupyter notebooks. A "python interactive" window is opened within vsc and displays the jupyter Notebook. I am wondering how do easily export this as pdf?
It is possible to export an ipython notebook, from there I can create an pdf … but these very unhandy ….
Code:
%%
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
%%
x = np.linspace(0,20, 100)
plt.plot(x, np.sin(x))
#plt.show()
%%
Screenshot:

You could log a suggestion on our github issues list:
https://github.com/Microsoft/vscode-python/issues/new.
Otherwise we don't currently support exporting to PDF. Just ipynb.

Related

matplotlib doesn't plot in terminal

I am trying to plot some scientific data by using Matplotlib in terminal.
here is my simple code :
import matplotlib.pyplot as plt
plt.plot([1,2,3],[3,2,5])
plt.show(block=True)
But I can't see any graph on my linux.
I am using wsl on windows for linux.
debian is my linux.
The link below doesn't help my problem:
Matplotlib plots aren't shown when running file from bash terminal
as you see I set block to True and nothing! for now I am using plt.savefig() function to see my result in windows.
may be I need to install some software in my Linux for image viewer , no?
thank you

Does %matplotlib qt works in google colab?

I was using matplotlib and found out that there is something as interactive plots in matplotlib via which we can rotate the graph via mouse cursor
%matplotlib qt is used to enable the interactive plots.Works fine in jupyter notebook but google colab shows error enter image description here
Is there any chance it works in google colab also?
No. There is no chance. %matplotlib qtworks only if you have notebook executed on same machine as you use it. Colab is executed on remote server. You may try %matplotlib notebook This create interactive plot inside notebook.

Jupyter not displaying matplotlib graphs

NOT DUPLICATE OF How to make IPython notebook matplotlib plot inline
I tried restarting kernel, using both %matplotlib inline twice/once ,and %matplotlib notebook twice/once, no change.
Reinstalled anaconda, tried plt.show(); (; at end) as well, no change.
plt.savefig("test.png")
saves graph picture beautifully, so it works in the backend.
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.show()
With %matplotlib notebook it displays a big blank, but hovering my mouse over displays the coordinates in the bottom right corner.
I have Windows 10, Python is 3.7.3, matplotlib 3.1.0, ipykernel 5.1.1, ipython 6.5.0, Jupyter Notebook server 6.0.0.
I was using Internet Explorer. Opened same Jupyter workbook in Edge, and it works!

Cannot get matplotlib graphics to show up inline

I would like to load automatically the command lines with Jupyter in Ubuntu 16.10 :
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
With Ubuntu, we could normally use configuration files as .vimrc, .bashrc and so on to automate some command lines. I know we could create the config file jupyter_notebook_config.py with jupyter notebook --generate-config. How could we implement that in python in that .py file?
Thanks!
You can't have graphics inline in a regular terminal because regular terminals don't have graphics capabilities. However, if you would be willing to use an alternative console, Jupyter Qtconsole, may be suitable for you.
EDIT: okay, I've had a look and you need to look at this, specifically the parts about running files/lines of code at startup. (like c.InteractiveShellApp.exec_lines or c.InteractiveShellApp.exec_files

Can %matplotlib notebook only be bused in Jupyter?

I have this and it works in jupyter in browser:
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import scipy as sp
However, after I copied it to a python file in the PyDev IDE editor, it always complains the first line:
%matplotlib notebook
Error message:
Encountered "%" at line 1, column 1. Was expecting one of: <EOF> <NEWLINE> ... "(" ... "{" ...
Does this mean the magic method can only be used in jupyter notebook?
Yes, It's a jupyter notebook command.
Well, you can't use it in a file (as that's not valid Python syntax), but you can use it in the PyDev interactive console: http://www.pydev.org/manual_adv_interactive_console.html if you have IPython properly installed.
The command in question, %matplotlib notebook, can be used to specify how to display graphs in a Jupyter notebook. If you use %matplotlib inline, the graphs will be displayed as a part of the Jupyter notebook. Using the form of the command that you asked about will display the graph in an interactive form within the Jupyter notebook. Or using %matplotlib gtk will open another program to display each individual graph, which is how Python would display the graphs in any other situation. So the command does not have any use or meaning outside of a Jupyter notebook.

Categories

Resources