Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"metadata": {
"name": "",
"signature": "sha256:bfb449ef2b39f66d75879e049a1f0d9796b61e32908ed1c1f3bd00ec7dcf56ee"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Basic display objects"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Try using the basic display classes in a notebook:\n",
"\n",
"* Find an image on the internet and display it in a notebook using the `Image` class. You can either save the image in the notebook's directory or load it by its URL.\n",
"* Use the `HTML` class and the `%%html` cell magic to display a snippet of HTML.\n",
"* Use the `JavaScript` class and the `%%javascript` cell magic to run a snippet of JavaScript.\n",
"* Try displaying these objects by both returning them from an expression and by passing them to `display`."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.display import Image"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"i = Image(url='http://fc08.deviantart.net/fs71/f/2010/010/1/d/Python_logo_by_BlueX_pl.png')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"i"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<img src=\"http://fc08.deviantart.net/fs71/f/2010/010/1/d/Python_logo_by_BlueX_pl.png\"/>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 10,
"text": [
"<IPython.core.display.Image at 0x10a6607d0>"
]
}
],
"prompt_number": 10
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"SoundCloud"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Go to [SoundCloud](http://soundcloud.com) and search for a sound clip you want to embed in your notebook. To find the HTML code to embed the sound, click on the \"Share\" link and copy the \"Embed\" URL. Paste it into a cell using the `%%html` magic."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%html \n",
"<iframe width=\"100%\" height=\"450\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/141744808&amp;auto_play=false&amp;hide_related=false&amp;visual=true\"></iframe>"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<iframe width=\"100%\" height=\"450\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/141744808&amp;auto_play=false&amp;hide_related=false&amp;visual=true\"></iframe>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x10a660590>"
]
}
],
"prompt_number": 5
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Rich output on nbviewer"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Rich output is also supported on http://nbviewer.ipython.org. To test this create a new notebook that has different types of rich output:\n",
"\n",
"* HTML\n",
"* JPEG/PNG (use matplotlib)\n",
"* JavaScript\n",
"* LaTeX\n",
"\n",
"After creating this notebook, upload it to http://gist.github.com and then view the notebook on http://nbviewer.ipython.org."
]
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.