Commit 567e86a1 authored by Aitor Perez's avatar Aitor Perez

Matplotlib

parent edf8db6c
# Slide : Basic variables types and operations
# Slide: Basic variables types and operations
# To run this block : ctrl + enter or
# Integer
......@@ -22,7 +22,7 @@ r = s + t # r = 'saluttoi'
p = True
q = (n != 1)*p + (n == 1)*(x < 10)*(y >= 0) # q = True = 1
# %% Slide : Lists
# %% Slide: Lists
# Lists
l = [1, 2, 5, 6]
......@@ -38,7 +38,7 @@ nl = [['vive', 'la'], ['saucisse', 2], 'Toulouse']
l1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
l2 = [3 * n + 1 for n in l1 if n % 2 == 0]
# l2 = [7, 13, 19, 25, 31]
# %% Slide : Dictionaries
# %% Slide: Dictionaries
# Dictionaries
d = {'first': 1,
......@@ -51,7 +51,7 @@ d = {'first': 1,
# d['third']['B'] = True
# %% Slide : Conditional structures
# %% Slide: Conditional structures
# If clause
if 1 == 2:
......@@ -74,7 +74,7 @@ while i < 10:
break # Allows to escape from the while loop
# %% Slide : Function definition
# %% Slide: Function definition
def add(a, b = 1):
return a + b
......@@ -88,7 +88,7 @@ def add(a, b = 1):
# Possibility of having a variable number of parameters
# %% Slide : File IO
# %% Slide: File IO
infile = open("infile.dat", "r")
# Opens the file for reading
......@@ -115,7 +115,7 @@ outfile.close()
# Close file to release memory
# %% Slide : Numpy
# %% Slide: Numpy
import numpy as np
# Import the package
......@@ -166,6 +166,38 @@ A / C # Elementwise division
np.dot(A, B) # Matrix product
# And lots of other built-in functions!
# %% Slide: Matplotlib
import numpy as np
import matplotlib.pyplot as plt
# Import the packages
x = np.arange(0, 3 * np.pi, 0.1)
sinx = np.sin(x)
cosx = np.cos(x)
# We generate the data we want to visualize
plt.plot(x, sinx) # Draws the points (x, sinx)
plt.plot(x, cosx) # Draws the points (x, cosx)
plt.xlabel('x axis label') # Adds a label to the x-axis
plt.ylabel('y axis label') # Adds a label to the y-axis
plt.title('Sine and Cosine') # Adds a title
plt.legend(['sin(x)', 'cos(x)']) # Adds a legend
plt.show() # Actually shows the plot
# We can also display several plots at once:
plt.subplot(2, 1, 1) # 2x1 grid, select the first as active
plt.plot(x, sinx)
plt.title('Sine')
plt.subplot(2, 1, 2) # 2x1 grid, select the second as active
plt.plot(x, cosx)
plt.title('Cosine')
plt.show()
# %% Old Slide : Function definition
......
......@@ -21,7 +21,7 @@ Contains *.tex*, *.pdf*, etc ... files for the presentation of the PhD seminar.
- [x] File I/O : reading and writing a file (from simple text, and examples of more complex tools ...) (AP)
- [x] Using Numpy to manipulate arrays (AP)
- [x] Overview of Scipy functionalities (AP)
- [ ] Data visualization with Matplotlib (AP)
- [x] Data visualization with Matplotlib (AP)
- [ ] Symbolic computation with Sympy (AP)
[MarkDown documentation](https://docs.gitlab.com/ee/user/markdown.html) - General synthax for *.md* files
......
No preview for this file type
......@@ -283,8 +283,16 @@
\end{frame}
\begin{frame}{Matplotlib}
XXX TODO
\begin{frame}{Matplotlib I}
\includegraphics[width=0.8\linewidth]{code-matplotlib1}
\centering \includegraphics[width=0.4\linewidth]{plot1}
\end{frame}
\begin{frame}{Matplotlib II}
\includegraphics[width=0.9\linewidth]{code-matplotlib2}
\centering \includegraphics[width=0.4\linewidth]{plot2}
\end{frame}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment