Plot data points. Defined in :numref:`sec_calculus`
(X, Y=None, xlabel=None, ylabel=None, legend=[], xlim=None,
ylim=None, xscale='linear', yscale='linear',
fmts=('-', 'm--', 'g-.', 'r:'), figsize=(3.5, 2.5), axes=None)
| 60 | axes.grid() |
| 61 | |
| 62 | def plot(X, Y=None, xlabel=None, ylabel=None, legend=[], xlim=None, |
| 63 | ylim=None, xscale='linear', yscale='linear', |
| 64 | fmts=('-', 'm--', 'g-.', 'r:'), figsize=(3.5, 2.5), axes=None): |
| 65 | """Plot data points. |
| 66 | |
| 67 | Defined in :numref:`sec_calculus`""" |
| 68 | |
| 69 | def has_one_axis(X): # True if X (tensor or list) has 1 axis |
| 70 | return (hasattr(X, "ndim") and X.ndim == 1 or isinstance(X, list) |
| 71 | and not hasattr(X[0], "__len__")) |
| 72 | |
| 73 | if has_one_axis(X): X = [X] |
| 74 | if Y is None: |
| 75 | X, Y = [[]] * len(X), X |
| 76 | elif has_one_axis(Y): |
| 77 | Y = [Y] |
| 78 | if len(X) != len(Y): |
| 79 | X = X * len(Y) |
| 80 | |
| 81 | set_figsize(figsize) |
| 82 | if axes is None: |
| 83 | axes = d2l.plt.gca() |
| 84 | axes.cla() |
| 85 | for x, y, fmt in zip(X, Y, fmts): |
| 86 | axes.plot(x,y,fmt) if len(x) else axes.plot(y,fmt) |
| 87 | set_axes(axes, xlabel, ylabel, xlim, ylim, xscale, yscale, legend) |
| 88 | |
| 89 | def add_to_class(Class): |
| 90 | """Register functions as methods in created class. |
nothing calls this directly
no test coverage detected