Jupyter QtConsole – Multiline Editing ”; Previous Next Multiline editing is one of the features which is not available in IPython terminal. In order to enter more than one statements in a single input cell, press ctrl+enter after the first line. Subsequently, just pressing enter will go on adding new line in the same cell. To stop entering new lines and running cell, press enter key one more time at the end. The cell will run and output will be displayed in next out[] cell. Print Page Previous Next Advertisements ”;
Category: jupyter
Using github and nbviewer
Using github and nbviewer ”; Previous Next Sharing Jupyter notebook – Using github and nbviewer Jupyter Notebook files with .ipynb extension in a GitHub repository will be rendered as static HTML files when they are opened. The interactive features of the notebook, such as custom JavaScript plots, will not work in your repository on GitHub. To share notebook file using github, login to https://github.comand create a public repository. Then upload your files using upload file button as shown below − This will give you an option to commit the changes made to the repository. Then, the repository will show uploaded file as below − Click on the uploaded file to view inside github viewer. You can share the highlighted URL to others. Another way to view the notebook file online is by using nbviewer utility of Project Jupyter. Open https://nbviewer.jupyter.org/ and put URL of file in your repository in the textfield as shown. Press Go button to view the notebook. Both these methods display notebook file as static html. To be able to execute code in the notebook, open it using Binder application of Jupyter project. In the nbviewer window you will see ‘Execute on Binder’ button. Click on it and you will see the notebook file opened exactly like you open it from local dashboard of notebook server on your local machine. You can perform all actions like add/edit cells, run the cells etc. Print Page Previous Next Advertisements ”;
Jupyter QtConsole – Multiple Consoles ”; Previous Next You can open more than one tabs in Jupyter console application. Three options in File menu are provided for this purpose. New Tab with New kernel − You can load a new kernel with this file menu. New Tab with Existing kernel − Using this option, you can choose from additional kernels apart from IPython kernel. New Tab with Same Kernel − This creates a slave of kernel loaded on a particular tab. As a result, object initialized on master tab will be accessible in slave and vice versa. Print Page Previous Next Advertisements ”;
Jupyter Notebook – Plotting
Jupyter Notebook – Plotting ”; Previous Next IPython kernel of Jupyter notebook is able to display plots of code in input cells. It works seamlessly with matplotlib library. The inline option with the %matplotlib magic function renders the plot out cell even if show() function of plot object is not called. The show() function causes the figure to be displayed below in[] cell without out[] with number. Now, add plt.show() at the end and run the cell again to see the difference. Note that the %matplotlib notebook magic renders interactive plot. Just below the figure, you can find a tool bar to switch views, pan, zoom and download options. Importantly, if you modify the data underneath the plot, the display changes dynamically without drawing another plot. In the above example, change the data sets of x and y in the cell below and plot the figure again, the figure above will get dynamically refreshed. Print Page Previous Next Advertisements ”;
QtConsole – Getting Started
Jupyter QtConsole – Getting Started ”; Previous Next In this chapter, let us understand how to get started with QtConsole. This chapter will give you an overview about this software and explains its installation steps. Overview The Qt console is a GUI application similar to IPython terminal. However, it provides a number of enhancements which are not available in text based IPython terminal. The enhance features are inline figures, multi-line editing with syntax highlighting, graphical calltips, etc. The Qt console can use any Jupyter kernel, default being IPython kernel. Installation Jupyter QtConsole is a part of Project Jupyter. Anaconda distribution is already having QTconsole application in it. In order to install it individually, use pip command as shown below − pip3 install qtconsole You can also use the conda command for this purpose − conda install qtconsole You can start Jupyter console from Anaconda navigator. To start it from the command line, you should use the following command, either from the Windows command prompt or Anaconda prompt − jupyter qtonsole You get a terminal similar to IPython terminal with first In[] prompt. You can now execute any Python expression exactly like we do in IPython terminal or Jupyter notebook Print Page Previous Next Advertisements ”;
Converting Notebooks
Jupyter – Converting Notebooks ”; Previous Next Jupyter notebook files have .ipynb extension. Notebook is rendered in web browser by the notebook app. It can be exported to various file formats by using download as an option in the file menu. Jupyter also has a command line interface in the form of nbconvert option. By default, nbconvert exports the notebook to HTML format. You can use the following command for tis purpose − jupyter nbconvert mynotebook.ipynb This will convert mynotebook.ipynb to the mynotebook.html. Other export format is specified with `–to` clause. Note that other options include [”asciidoc”, ”custom”, ”html”, ”latex”, ”markdown”, ”notebook”, ”pdf”, ”python”, ”rst”, ”script”, ”slides”] HTML includes ”basic” and ”full” templates. You can specify that in the command line as shown below − jupyter nbconvert –to html –template basic mynotebook.ipynb LaTex is a document preparation format used specially in scientific typesetting. Jupyter includes ”base”, ”article” and ”report” templates. jupyter nbconvert –to latex –template report mynotebook.ipynb To generate PDF via latex, use the following command − jupyter nbconvert mynotebook.ipynb –to pdf Notebook can be exported to HTML slideshow. The conversion uses Reveal.js in the background. To serve the slides by an HTTP server, add –postserve on the command-line. To make slides that does not require an internet connection, just place the Reveal.js library in the same directory where your_talk.slides.html is located. jupyter nbconvert myslides.ipynb –to slides –post serve The markdown option converts notebook to simple markdown output. Markdown cells are unaffected, and code cells indented 4 spaces. –to markdown You can use rst option to convert notebook to Basic reStructuredText output. It is useful as a starting point for embedding notebooks in Sphinx docs. –to rst This is the simplest way to get a Python (or other language, depending on the kernel) script out of a notebook. –to script Print Page Previous Next Advertisements ”;
Cell Magic Functions
Jupyter Notebook – Cell Magic Functions ”; Previous Next In this chapter, let us understand cell magic functions and their functionalities. %%html This cell magic function renders contents of code cell as html script. %%js or %%javascript You can embed javascript code in Jupyter notebook cell with the help of this cell magic command. %%writefile Contents of code cell are written to a file using this command. Print Page Previous Next Advertisements ”;
Jupyter Notebook – User Interface ”; Previous Next In the user interface of Jupyter, just beside the logo in the header, the file name is displayed. You can find the menu bar below the header. Each menu contains many options that will be discussed later. A row of icons forming toolbar helps user to perform often required operations The notebook has two modes − Command mode and Edit mode. Notebook enters edit mode when a cell is clicked. Notice the pencil symbol just besides name of kernel. Kernel indicator symbol is displayed just to the right of kernel name. Note that a hollow circle means kernel is idle and solid circle means it is busy. File Menu The following are the options available in the File menu − Sr.No. File menu & Description 1 New notebook choose the kernel to start new notebook 2 Open Takes user to dashboard to choose notebook to open 3 Save as save current notebook and start new kernel 4 Rename rename current notebook 5 Save saves current notebook and stores current checkpoint 6 Revert reverts state of notebook to earlier checkpoint 7 Download export notebook in one of various file formats The file formats that are available are shown below − Edit Menu Edit menu consists of buttons to perform cut, copy and paste cells, delete selected cell, split and merge cells, move cells up and down, find and replace within notebook, cut/copy attachments and insert image. View Menu Buttons in this menu help us to hide/display header, toolbar and cell numbers. Insert Menu This menu gives you options for inserting cell before or after the current cell. Cell Menu The options in this menu let user run all or specific cells in the notebook. You can also set the cell type to code type, markdown or raw nbconvert type. Kernel Menu From this menu you can start, interrupt, restart or shutdown the kernel. You can also start a new kernel. Widgets Menu From this menu you can save, clear, download or embed widget state. Help menu Various predefined keyboard shortcuts are displayed from this menu. You can also edit the shortcuts as per your convenience. Print Page Previous Next Advertisements ”;
QtConsole – Inline Graphics
Jupyter QtConsole – Inline Graphics ”; Previous Next Another important enhancement offered by QtConsole is the ability to display inline graphics, especially plots. The feature works well with Matplotlib as well as other plotting libraries. Print Page Previous Next Advertisements ”;
Jupyter Notebook – Editing
Jupyter Notebook – Editing ”; Previous Next While the menu bar and toolbar lets you perform various operations on notebook, it is desirable to be able to use keyboard shortcuts to perform them quickly. Jupyter Notebooks have two different keyboard input modes − Command Mode − Binds the keyboard to notebook level actions. Indicated by a grey cell border with a blue left margin. Edit Mode − When you are typing in a cell. Indicated by a green cell border. Command Mode (press Esc to enable) F find and replace 1 change cell to heading 1 Ctrl-Shift-F open the command palette 2 change cell to heading 2 Ctrl-Shift-P open the command palette 3 change cell to heading 3 Enter enter edit mode 4 change cell to heading 4 P open the command palette 5 change cell to heading 5 Shift-Enter run cell, select below 6 change cell to heading 6 Ctrl-Enter run selected cells A insert cell above Alt-Enter run cell and insert below B insert cell below Y change cell to code X cut selected cells M change cell to markdown C copy selected cells R change cell to raw V paste cells below K select cell above Z undo cell deletion Up select cell above D,D delete selected cells Down select cell below Shift-M merge selected cells, or current cell with cell below if only one cell is selected J select cell below Shift-V paste cells above Shift-K extend selected cells above L toggle line numbers Shift-Up extend selected cells above O toggle output of selected cells Shift-Down extend selected cells below Shift-O toggle output scrolling of selected cells Shift-J extend selected cells below I,I interrupt the kernel Ctrl-S Save and Checkpoint 0,0 restart the kernel (with dialog) S Save and Checkpoint Esc close the pager Shift-L toggles line numbers in all cells, and persist the setting Q close the pager Shift-Space scroll notebook up Space scroll notebook down Edit Mode (press Enter to enable) Tab code completion or indent Ctrl-Home go to cell start Shift-Tab tooltip Ctrl-Up go to cell start Ctrl-] indent Ctrl-End go to cell end Ctrl-[ dedent Ctrl-Down go to cell end Ctrl-A select all Ctrl-Left go one word left Ctrl-Z undo Ctrl-Right go one word right Ctrl-/ comment Ctrl-M enter command mode Ctrl-D delete whole line Ctrl-Shift-F open the command palette Ctrl-U undo selection Ctrl-Shift-P open the command palette Insert toggle overwrite flag Esc enter command mode Ctrl-Backspace delete word before Ctrl-Y redo Ctrl-Delete delete word after Alt-U redo selection Shift-Enter run cell, select below Ctrl-Shift-Minus split cell at cursor Ctrl-Enter run selected cells Down move cursor down Alt-Enter run cell and insert below Up move cursor up Ctrl-S Save and Checkpoint Print Page Previous Next Advertisements ”;