Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry57 authored Oct 27, 2024
1 parent f74a6a9 commit 43f6516
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
49 changes: 49 additions & 0 deletions GENetLib/plot_fd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import numpy as np
import matplotlib.pyplot as plt

from GENetLib.eval_basis_fd import eval_fd


'''Plot functional objects'''

def plot_fd(x, y = None, xlab = None, ylab = None):

fdobj = x
coef = fdobj['coefs']
coefd = coef.shape
ndim = len(coefd)
nbasis = coefd[0]
nx = np.max([501, 10 * nbasis + 1])
nrep = coefd[1]
basisobj = fdobj['basis']
rangex = basisobj['rangeval']
if y == None:
y = nx
if y >= 1:
y = list(np.linspace(rangex[0], rangex[1], num=int(y)))
else:
raise ValueError("'y' is a single number less than one.")
xlim = rangex
fdmat = eval_fd(y, fdobj, 0)
rangey = [np.min(fdmat), np.max(fdmat)]
ylim = rangey
if ndim < 2:
plt.figure()
plt.plot(y, fdmat)
plt.axhline(0, linestyle='--', color='black')
plt.xlim(xlim)
plt.ylim(ylim)
plt.xlabel(xlab)
plt.ylabel(ylab)
plt.show()
elif ndim == 2:
plt.figure()
for irep in range(nrep):
plt.plot(y, fdmat[:, irep])
plt.axhline(0, linestyle='--', color='black')
plt.xlim(xlim)
plt.ylim(ylim)
plt.xlabel(xlab)
plt.ylabel(ylab)
plt.show()

13 changes: 13 additions & 0 deletions GENetLib/plot_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from GENetLib.plot_fd import plot_fd


'''Plot functional objects regardless of whether y inputs or not'''

def plot_func(x, y = None, xlab = None, ylab = None):

tofunc = x
if y == None:
plot_fd(tofunc, xlab, ylab)
else:
plot_fd(tofunc, y, xlab, ylab)

0 comments on commit 43f6516

Please sign in to comment.