Skip to content

Commit

Permalink
Add some Python scripts for plotting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bergolho committed May 25, 2020
1 parent 0df33e9 commit 6e3a683
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 8 deletions.
20 changes: 20 additions & 0 deletions Python/Exponential/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import numpy as np
from matplotlib import pyplot as plt

A = 100
B = -0.2
C = 0

def f (x):
return A*np.exp(B*x) + C

def main ():
x = np.linspace(0,50,200)
y = f(x)

plt.grid()
plt.plot(x,y)
plt.show()

if __name__ == "__main__":
main()
99 changes: 99 additions & 0 deletions Python/Subfigure/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import sys
import numpy as np
import matplotlib.pyplot as plt

def f1 (x):
return x

def f2 (x):
return x*x

def f3 (x):
return np.exp(x)

def f4 (x):
return np.sqrt(x)

def main ():
x1 = np.linspace(0,5,100)
y1 = f1(x1)

x2 = np.linspace(-2,2,100)
y2 = f2(x2)

x3 = np.linspace(0,5,100)
y3 = f3(x3)

x4 = np.linspace(0,5,100)
y4 = f4(x4)

figure, axes = plt.subplots(nrows=2,ncols=2)
ax = axes[0][0]
ax.plot(x1,y1)
ax.set_title("Linear function")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.grid()

ax = axes[0][1]
ax.plot(x2,y2)
ax.set_title("Quadratic function")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.grid()

ax = axes[1][0]
ax.plot(x3,y3)
ax.set_title("Exponetial function")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.grid()

ax = axes[1][1]
ax.plot(x4,y4)
ax.set_title("Non-linear function")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.grid()

# Set a padding between the figures
figure.tight_layout(pad=3.0)

#plt.show(figure)
plt.savefig("subfigures.pdf")


if __name__ == "__main__":
main()

'''
# Alternative way ...
plt.subplot(221)
plt.title("Linear function")
plt.xlabel("x")
plt.ylabel("y")
plt.grid()
plt.plot(x1,y1)
plt.subplot(222)
plt.title("Quadratic function")
plt.xlabel("x")
plt.ylabel("y")
plt.grid()
plt.plot(x2,y2)
plt.subplot(223)
plt.title("Exponetial function")
plt.xlabel("x")
plt.ylabel("y")
plt.grid()
plt.plot(x3,y3)
plt.subplot(224)
plt.title("Non-linear function")
plt.xlabel("x")
plt.ylabel("y")
plt.grid()
plt.plot(x4,y4)
'''
Binary file added Python/Subfigure/subfigures.pdf
Binary file not shown.
8 changes: 0 additions & 8 deletions Python/main.py

This file was deleted.

0 comments on commit 6e3a683

Please sign in to comment.