Skip to content

Commit

Permalink
plot of FdataBasis more general
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarbajo committed Feb 12, 2018
1 parent b55c35d commit 302eccc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fda/FDataBasis.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,12 @@ def evaluate(self, eval_points, derivative=0):

return res_matrix

def plot(self, derivative=0, **kwargs):
def plot(self, ax=None, derivative=0, **kwargs):
"""Plots the FDataBasis object or its derivatives.
Args:
ax (axis object, optional): axis over with the graphs are plotted.
Defaults to matplotlib current axis.
derivative (int, optional): Order of the derivative. Defaults to 0.
**kwargs: keyword arguments to be passed to the
matplotlib.pyplot.plot function.
Expand All @@ -657,6 +659,8 @@ def plot(self, derivative=0, **kwargs):
List of lines that were added to the plot.
"""
if ax is None:
ax = matplotlib.pyplot.gca()
npoints = max(501, 10 * self.nbasis)
# List of points where the basis are evaluated
eval_points = numpy.linspace(self.domain_range[0],
Expand All @@ -665,7 +669,7 @@ def plot(self, derivative=0, **kwargs):
# Basis evaluated in the previous list of points
mat = self.evaluate(eval_points, derivative)
# Plot
return matplotlib.pyplot.plot(eval_points, mat.T, **kwargs)
return ax.plot(eval_points, mat.T, **kwargs)

def mean(self):
""" Computes the mean of all the samples in a FDataBasis object.
Expand Down

0 comments on commit 302eccc

Please sign in to comment.