Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sci_python
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SCW2017
sci_python
Commits
ecb3f8cc
Commit
ecb3f8cc
authored
Oct 05, 2017
by
Inigo Aldazabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split scipy and matplotlib notebooks
parent
666f47c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
256 additions
and
140 deletions
+256
-140
matplotlib-tutorial.ipynb
matplotlib-tutorial.ipynb
+256
-0
scipy-tutorial.ipynb
scipy-tutorial.ipynb
+0
-140
No files found.
matplotlib-tutorial.ipynb
0 → 100644
View file @
ecb3f8cc
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![Matplotlib](images/matplotlib_logo-s.png)\n",
"\n",
"# Matplotlib"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's take a quick look at the *matplotlib* essentials.\n",
"\n",
"First let's import the neccesary modules and tell the notebook to generate the figures inline:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `inline` is important for the notebook, so that plots are displayed\n",
"in the notebook and not in a new window.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can use (note that you have to use `show` explicitly if you don't use `%matplotlib inline`):\n",
"\n",
"```\n",
" plt.plot(x,y) # line plot\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"And now let's go with some examples."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic matplotlib visualization"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* **1D plotting**:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x = np.linspace(0, 4.*np.pi, 100)\n",
"y = np.sin(x)\n",
"plt.plot(x, y) # line plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.plot(x, y, 'o') # dot plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.plot(x, y)\n",
"plt.plot(x, y, 'o')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* **2D arrays** (such as images):\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"image = np.random.rand(30, 30)\n",
"plt.imshow(image, cmap=plt.cm.hot)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise: Simple visualizations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Plot some simple arrays / functions.\n",
"\n",
"* Try using the `gray` colormap.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1D plot"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A tangent between 0 and 4$\\pi$.\n",
"\n",
"$$y = \\tan(x), \\; x\\in[0., 4\\pi]$$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x = np.linspace( 0., 4.*np.pi, num=200 )\n",
"y = np.tan(x)\n",
"\n",
"plt.plot(x, y)\n",
"\n",
"plt.xlabel(r'$x$') #using LaTeX syntax\n",
"plt.ylabel(r'$\\tan(x)$')\n",
"plt.grid(True)\n",
"#plt.savefig('tan.png')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1D polar plot "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$\\theta(\\rho) = 2\\pi \\rho, \\; \\rho \\in [0, 2]$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"r = np.arange(0, 2., 0.01)\n",
"theta = 2 * np.pi * r\n",
"\n",
"plt.polar(theta, r, color='r', linewidth=3)\n",
"plt.grid(True)\n",
"\n",
"plt.title(\"A line plot on a polar axis\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the function \n",
"\n",
"$$y = \\frac{\\sin(x)}{x}, \\; x\\in[0.1, 6\\pi]$$\n",
"\n",
"and try to \n",
"\n",
"* set the figure *legend*\n",
"* change the *line style*\n",
"\n",
"hint: checkout the [matplotlib examples](http://matplotlib.org/examples/index.html)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load files/sol_sinc.py"
]
}
],
"metadata": {
"celltoolbar": "Raw Cell Format",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
scipy-tutorial.ipynb
View file @
ecb3f8cc
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![Matplotlib](images/matplotlib_logo-s.png)\n",
"\n",
"# Matplotlib"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's take a quick look at the matplotlib essentials.\n",
"\n",
"First let's import the neccesary modules:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"And now let's go with some examples."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1D plot"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A tangent between 0 and 4$\\pi$.\n",
"\n",
"$$y = \\tan(x), \\; x\\in[0., 4\\pi]$$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = np.linspace( 0., 4.*np.pi, num=200 )\n",
"y = np.tan(x)\n",
"\n",
"plt.plot(x, y)\n",
"\n",
"plt.xlabel(r'$x$') #using LaTeX syntax\n",
"plt.ylabel(r'$\\tan(x)$')\n",
"plt.grid(True)\n",
"#plt.savefig('tan.png')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1D polar plot "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$\\theta(\\rho) = 2\\pi \\rho, \\; \\rho \\in [0, 2]$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"r = np.arange(0, 2., 0.01)\n",
"theta = 2 * np.pi * r\n",
"\n",
"plt.polar(theta, r, color='r', linewidth=3)\n",
"plt.grid(True)\n",
"\n",
"plt.title(\"A line plot on a polar axis\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the function \n",
"\n",
"$$y = \\frac{\\sin(x)}{x}, \\; x\\in[0.1, 6\\pi]$$\n",
"\n",
"and try to \n",
"\n",
"* set the figure *legend*\n",
"* change the *line style*\n",
"\n",
"hint: checkout the [matplotlib examples](http://matplotlib.org/examples/index.html)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# %load files/sol_sinc.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment