Related
I'm creating plots in a loop in Jupyter notebook. Is it possible to auto generate markdown heading within a loop before every figure so that the headings can show up in jupyter toc or vscode outline for easy navigation?
import matplotlib.pyplot as plt
import numpy as np
for i in range(1,5):
#add markdown heading here
plt.figure()
x = np.arange(10)*i
y = np.sin(x)
plt.plot(x, y)
You can change the cell type of any cell in Jupyter Notebook using the Toolbar. The default cell type is Code. To use the Keyboard Shortcuts, hit the esc key. After that, you can change a cell to Markdown by hitting the m key, or you can change a cell to Code by hitting the y key
see this image for reference
When I export a notebook to PDF in jupyter lab i cannot hide the code cells in the output.
(Like 'View > Collapse All Code')
Is there a built in functionality to hide code in the output PDF?
For example by using the cell Metadata?
This worked for me:
jupyter nbconvert path/to/your/ipynb --to=pdf --TemplateExporter.exclude_input=True
I have an image on disk and want to display it in a markdown cell in an R Jupyter Notebook. How can I go about this?
I know with Python this as simple as importing the Image class from display.
IRdisplay has functions to rich display "stuff", which includes images:
library("IRdisplay")
display_png(file="plot.png)
In a markdown cell as you usually would in a Jupyter Python notebook:
<img src="../relative/path/to/img.png">
or
![image](../relative/path/to/img.png)
Here is code for the Jupyter R Kernel Notebook User to select choose an image file (.PNG) from the file system, strip off the full pathname, and then insert the image into the cell below this code.
image_chosen = choose.files(
default = "",
caption = "Select The Image File (in PNG format) to Insert",
multi = TRUE, filters = Filters,
index = nrow(Filters)
)
chosen_image_name = basename(image_chosen)
#chosen_image_name # uncomment this line to show the location of the image.
IRdisplay::display_png(file = chosen_image_name) # This line inserts the image.
Then use the standard Jupyter Notebook extension "Hide Input" to hide this codecell, and the "Freeze" NBextension to freeze the codecell so the image stays frozen and the notebook does not try to select and insert a new image everytime the notebook code runs.
How can I export Jupyter notebooks to LaTeX? I can convert to PDF through LaTeX using the inbuilt menus but I'm unsure how to step in at the intermediate step and extract the actual LaTeX file.
You have to do this from the command line rather than the web interface with the following command:
jupyter nbconvert /path/to/mynotebook.ipynb --to latex
Anaconda Navigator provides JupyterLab. Use this to open jupyter notebook.
Under File menu you can find an item "Export Notebook As...".
This provides format such as Asciidoc, HTML, latex, pdf, Markdown, etc.
You can choose your desired format.
How is this done? I'd like to have the link be in a markdown cell.
For visual learners:
[blue_text](url_here)
In case it is not a markdown cell, that is with what I went:
from IPython.core.display import display, HTML
display(HTML("""text"""))
Just another tip, using magic expression.
%%html
Showing Text
Improved. Thanks to the comment of calocedrus.
Here is the code I use in my python notebook when I want to insert a link to a webpage inside a markdown cell (in a python notebook).
[Clickable_visible_hyperlink](Hidden_landing_URL)
--note Here is the clickable hyperlink, you can change the value
This might help too, if you're looking to display a link programmatically.
from IPython.display import display, Markdown
display(Markdown("[google](https://www.google.com)"))
I also tried
display(HTML("""<a href="https://www.google.com>google</a>"""))
But somehow I was getting the object printed out, instead of the rendered version.
For programming in R, do the following when using Jupyter Notebook or Jupyter Lab - (using the R kernel). These steps will display a web link and an image in a Notebook markdown cell. The following shows a real-life example of some study notes using Jupyter Lab and R.
First open a markdown cell in Jupyter - can be a new markdown cell or an existing markdown cell. Then copy and paste the actual web address into a markdown cell. This will provide an active link to that website from the Notebook.
Step 2, from that website, copy the image that you want to view in the Notebook. This image should be in a standard image format (.png, .jpg, etc ). Paste this image into the same folder on the computer where the Jupyter notebook file is located. Note: if the image is later deemed too large or small, then resize using any graphics software available - and then save the changed image into this same folder. Note: it is important to know the name of this image file.
Next, paste the name of the image file between the quotation marks in the following code: . If this file in not within your existing jupyter notebook working directory, then a path to the image file will need to be placed inside the quotation marks.
Step 3, also included is an example of the line of code (also used in Notebook markdown cell) to create colored text in markdown cells. In this line of code, the double ## character results in the second largest font being used in Jupyter. Smaller text using more of these characters - with #### being the smallest. One # results in the largest font output.
Last, be sure to close and run the markdown cell to view the output. The code for the markdown cell follows, and further below shows the output from the Notebook.
Code in Markdown cell:
"https://www.tensorflow.org/images/colab_logo_32px.png" # link to website
<img src="tidyflow.png" /> # The image file (This path is the same folder as Notebook file)
## <font color = cyan> Some Colored Text in Notebook Markdown Cell </font> # colored text
Output: