Skip to content

Commit

Permalink
Add plot method to TransformBase
Browse files Browse the repository at this point in the history
  • Loading branch information
schmoelder committed Mar 11, 2024
1 parent 1f55438 commit 4622ca8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CADETProcess/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def wrapper(
if ax is None:
fig, ax = setup_figure(style=style)

ax = func(*args, ax=ax, **kwargs)
func(*args, ax=ax, **kwargs)

if fig is not None:
fig.tight_layout()
Expand Down
33 changes: 32 additions & 1 deletion CADETProcess/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from abc import ABC, abstractmethod, abstractproperty

import numpy as np
import matplotlib.pyplot as plt

from CADETProcess import plotting


class TransformBase(ABC):
Expand Down Expand Up @@ -56,7 +59,7 @@ class TransformBase(ABC):
Notes
-----
- This is an abstract base class and cannot be instantiated directly.
- The `transform` method is not implemented in this class and must be implemented by a subclass.
- The `transform` method must be implemented by a subclass.
Examples
--------
Expand Down Expand Up @@ -229,6 +232,34 @@ def _untransform(self, x):
"""
pass

@plotting.create_and_save_figure
def plot(self, ax, use_log_scale=False):
"""
Plot the transformed space against the input space.
Parameters
----------
ax : matplotlib.axes.Axes
The axes object to plot on.
use_log_scale : bool, optional
If True, use a logarithmic scale for the x-axis.
"""
allow_extended_input = self.allow_extended_input
self.allow_extended_input = True

y = np.linspace(self.lb, self.ub)
x = self.untransform(y)

ax.plot(x, y)

ax.set_xlabel('Input Space')
ax.set_ylabel('Transformed Space')

if use_log_scale:
ax.set_xscale('log')

self.allow_extended_input = allow_extended_input

def __str__(self):
"""Return the class name as a string."""
return self.__class__.__name__
Expand Down

0 comments on commit 4622ca8

Please sign in to comment.