Plotter

Describes different plotting classes.

ecgan.visualization.plotter.matplotlib_prep(size, subplots=1, y_lim=None)[source]

Return a figure and an axis for a matplotlib plot with a given size.

Parameters
  • size (Tuple[int, int]) -- Target (width, height) of the plot.

  • subplots (int) -- amount of subplots of the figure.

  • y_lim (Optional[Tuple]) -- Visual y limits of the plot.

Return type

Tuple[Figure, Axes]

Returns

The processed figure and axes.

class ecgan.visualization.plotter.BasePlotter[source]

Bases: object

Base class for plotting classes. Creates its plots by simple call to plt.plot.

create_plot(data, color='blue', size=(256, 256), y_lim=None, label=None)[source]

Generate a plot from given data (default: 2D time series).

How the plot is created is subject to the given class implementation. The plot is returned as a mpl Figure.

Parameters
  • data (ndarray) -- A list of data points representing a 2D time series.

  • color (str) -- The color in which to draw the plot.

  • size (Tuple[int, int]) -- The size the plot image is resized to. Resizing is done via cubic interpolation.

  • y_lim (Optional[Tuple[float, float]]) -- Limit the y-axis of the plot to the floating tuple.

  • label (Optional[int]) -- Optional label which can be drawn into the plot.

Return type

Figure

Returns

The generated images.

get_sampling_grid(sample_data, max_num_series=16, row_width=4, color='blue', scale_per_batch=False, label=None, x_axis=True, y_axis=True, fig_size=None)[source]

Get sampled time series data image grid.

Parameters
  • sample_data (Union[Tensor, ndarray]) -- The data that shall be visualized with shape (amount_of_series, measurements, channels).

  • max_num_series (int) -- Maximum amount of samples visualized.

  • row_width (int) -- Row width.

  • color (str) -- Sets the colour of the plots.

  • scale_per_batch (bool) -- Set the y-limit for each plot to min/max of the batch (per channel).

  • label (Union[Tensor, ndarray, None]) -- Optional labels parameter, which is written to the plots.

  • x_axis (bool) -- Flag indicating whether the x-axis should be visible.

  • y_axis (bool) -- Flag indicating whether the y-axis should be visible.

  • fig_size (Optional[Tuple[float, float]]) -- Optional size for the figure in inches.

Return type

Figure

Returns

Figure of the image grid.

save_sampling_grid(sample_data, file_location, color='blue', max_num_series=16, scale_per_batch=False, row_width=4, label=None)[source]

Save sampled time series data to an image grid.

Parameters
  • sample_data (Union[Tensor, ndarray]) -- The data that shall be visualized with shape (amount_of_series, 1, measurements).

  • color (str) -- Color of the plot.

  • file_location (str) -- Path to file on local system. Should be a UNIQUE identifier.

  • max_num_series (int) -- Maximum amount of samples visualized.

  • row_width (int) -- Width of a row.

  • scale_per_batch -- Set the y-limit for each plot to min/max of the batch (per channel).

  • label (Union[Tensor, ndarray, None]) -- Optional labels parameter, which is written to the plots.

Return type

None

static create_histogram(data, title, x_label='', y_label='', bins=50, color='g')[source]

Create a histogram of given data.

Return type

Figure

static save_plot(plot, file_location)[source]

Save a plot (encoded as np.ndarray) to file_location.

Return type

None

static create_error_plot(data_lined, data_dashed, heatmap_data=None, x_axis=None, data_range=None, color_lined='blue', color_dashed='red', color_map='plasma', x_label='', y_label='', title='')[source]

Create a plot with two graphs visualizing the difference of the two samples and a heatmap.

Parameters
  • data_lined (Union[ndarray, Tensor]) -- The sample data that is depicted as a solid line.

  • data_dashed (Union[ndarray, Tensor]) -- The sample data that is depicted as a dashed line.

  • heatmap_data (Optional[ndarray]) -- Optional data for the drawing of the heatmap. The default simply computes the absolute value of (data_dashed - data_lined)

  • x_axis (Optional[ndarray]) -- Sampling of the x-axis. Default assumes range(1, len_of_samples).

  • data_range (Optional[Tuple[float, float]]) -- Range of the heatmap. Dynamic by default, requires (min,max) otherwise.

  • color_lined (str) -- Color of the lined plot.

  • color_dashed (str) -- Color of the dashed plot.

  • color_map (str) -- Color map for the heatmap.

  • x_label (str) -- Label of the x-axis.

  • y_label (str) -- Label of the y-axis.

  • title (str) -- Title for the plot.

Return type

Figure

Returns

Heatmap Figure.

class ecgan.visualization.plotter.FourierPlotter[source]

Bases: ecgan.visualization.plotter.BasePlotter

Plotter implementation to plot data in the Fourier-domain as a frequency-histogram.

get_sampling_grid(sample_data, max_num_series=16, row_width=4, color='blue', scale_per_batch=False, label=None, x_axis=True, y_axis=True, fig_size=None)[source]

Get sampled time series data image grid.

Parameters
  • sample_data (Union[Tensor, ndarray]) -- The data that shall be visualized. The tensor is assumed to be of shape (batch_size, seq_length, 2 * num_of_channels), where each two channels form the real and imaginary parts of the Fourier coefficients.

  • max_num_series (int) -- Maximum amount of samples visualized.

  • row_width (int) -- Amount of columns if grid shall not be symmetric.

  • color (str) -- Sets the colour of the plots.

  • scale_per_batch (bool) -- Set the y-limit for each plot to min/max of the batch (per channel).

  • label (Union[Tensor, ndarray, None]) -- Optional labels parameter, which is written to the plots.

  • x_axis (bool) -- Flag indicating whether the x-axis should be visible.

  • y_axis (bool) -- Flag indicating whether the y-axis should be visible.

  • fig_size (Optional[Tuple[float, float]]) -- Optional size for the figure in inches.

Return type

Figure

Returns

Image grid as Figure.

create_plot(data, color='blue', size=(256, 256), y_lim=None, label=None)[source]

Create a plot of the data using the settings of the plotting class.

Return type

Figure

class ecgan.visualization.plotter.ScatterPlotter[source]

Bases: ecgan.visualization.plotter.BasePlotter

Plotter specialized on scatter plots for large datasets.

static truncate_colormap(cmap, min_val=0.0, max_val=1.0, n_cmap=100)[source]

Truncate a given matplotlib colormap to a specific range.

Parameters
  • cmap (Colormap) -- matplotlib colormap object.

  • min_val (float) -- Minimum bound of colormap.

  • max_val (float) -- Maximum bound of colormap.

  • n_cmap (int) -- Number of samples from original cmap.

Return type

LinearSegmentedColormap

Returns

New colormap object

static plot_scatter(data, target, fig_title, classes, dpi=300, alpha=1, cmap='plasma')[source]

Visualizes the resulting low dimensional (2D or 3D) embedding.

Parameters
  • data (ndarray) -- Low dimensional embedding, either 2D or 3D plots, i.e. shape (n_samples, 2) or (n_samples, 3).

  • target (Union[List[int], object]) -- Target values used for visualization encoded as integers.

  • fig_title (Optional[str]) -- Description of the model saved. Should include the name of the embedding.

  • classes (Optional[List[str]]) -- Class names according to the encoding in target.

  • dpi (int) -- DPI of the resulting figure.

  • alpha (float) -- Alpha blending value. Is between 0 (transparent) and 1 (opaque).

  • cmap (str) -- Colormap.

Return type

Figure

Returns

Figure containing the scatter plot.

static plot_interpolation_path(data, labels, trace, classes, fig_size=(10, 7.5), cmap='plasma', cmap_range=(0.0, 1.0), path_color='r', scatter_alpha=1.0)[source]

Plot a trace between points in a scatter plot.

Return type

Figure

class ecgan.visualization.plotter.PlotterFactory[source]

Bases: object

Used to retrieve instance of desired plotter.

static choose_class(plotter_type)[source]

Choose the correct class based on the provided plotter name.

static from_config(train_cfg)[source]

Generate a plotter from a config dictionary.

Return type

BasePlotter

ecgan.visualization.plotter.visualize_reconstruction(series, plotter, max_intermediate_samples=10)[source]

Visualize a fixed amount of series for a variable amount of input series.

Total steps=max_intermediate_samples+original sample+final sample.

Parameters
  • series (Tensor) -- Tensor of series that shall be reconstructed.

  • plotter (BasePlotter) -- The plotter to use for the visualization.

  • max_intermediate_samples (int) -- Maximum amount of interpolation steps.

Return type

Figure

Returns

A mpl Figure containing a sequence of series.