Table of Contents

Class PlayPlot

Namespace
Gym.Utils
Assembly
Gym.Rendering.dll

Live plots of metrics while playing (Gymnasium's PlayPlot): pass Callback(object?, object?, object?, double, bool, bool, Info) to Run(IEnv, bool?, double?, double?, PlayCallback?, object?, BigInteger?, object?, bool, EnvViewerFactory?, PygameContext?), and each step adds the points of DataCallback to one scatter plot per name, showing the last HorizonTimesteps steps.

public class PlayPlot
Inheritance
PlayPlot
Inherited Members
Extension Methods

Remarks

Gymnasium draws with matplotlib; Gym.NET draws through IPlotFigure, matplotlib's calls as PlayPlot makes them (subplots, set_title, scatter, remove, set_xlim, pause), so the plotted data is Gymnasium's call for call. The default figure (PlotFigure) is a plain window from the viewer factory: matplotlib's layout and blue markers, without text (the window's title names the plots). Pass subplots to draw elsewhere: the viewer packages ship ScottPlot figures with titles, ticks, labels and live updates (DR-39), AvaloniaPlotFigure.Subplots() of Gym.NET.Rendering.Avalonia and WinFormPlotFigure.Subplots() of Gym.NET.Rendering.WinForm; this package takes no chart dependency.

Not thread-safe: call Callback(object?, object?, object?, double, bool, bool, Info) from one thread, as play does.

Reference: gymnasium/utils/play.py.

Constructors

PlayPlot(PlayPlotMetrics, int, IReadOnlyList<string>, PlotSubplots?)

Creates the figure, one axes per name with its title, and an empty series per plot.

public PlayPlot(PlayPlotMetrics callback, int horizonTimesteps, IReadOnlyList<string> plotNames, PlayPlot.PlotSubplots? subplots = null)

Parameters

callback PlayPlotMetrics

Computes the points of a transition, one per plot.

horizonTimesteps int

How many recent steps each plot shows (deque(maxlen=...)); 0 keeps none.

plotNames IReadOnlyList<string>

The plots' titles, one plot each.

subplots PlayPlot.PlotSubplots

The figure's maker, matplotlib's plt.subplots(nrows); null uses Subplots(EnvViewerFactory?) with Gymnasium.HumanViewerFactory.

Exceptions

ArgumentNullException

Thrown when callback or plotNames is null.

DependencyNotInstalled

Thrown by the default figure when no viewer factory is set, where Gymnasium raises it when matplotlib is missing.

ValueError

Thrown for no plot names by the default figure (matplotlib's Number of rows must be a positive integer, not 0), and for a negative horizon (maxlen must be non-negative).

Properties

Ax

One axes per plot, top to bottom (ax; always a list, where Gymnasium wraps a single axes in one).

public IReadOnlyList<IPlotAxes> Ax { get; }

Property Value

IReadOnlyList<IPlotAxes>

CurPlot

The scatter shown on each axes, null before the first point (cur_plot).

public IReadOnlyList<IPlotArtist?> CurPlot { get; }

Property Value

IReadOnlyList<IPlotArtist>

Data

The last HorizonTimesteps points of each plot (data).

public IReadOnlyList<Deque<double>> Data { get; }

Property Value

IReadOnlyList<Deque<double>>

DataCallback

The points of each transition (data_callback).

public PlayPlotMetrics DataCallback { get; }

Property Value

PlayPlotMetrics

Fig

The figure (fig).

public IPlotFigure Fig { get; }

Property Value

IPlotFigure

HorizonTimesteps

How many recent steps each plot shows (horizon_timesteps).

public int HorizonTimesteps { get; }

Property Value

int

PlotNames

The plots' titles (plot_names).

public IReadOnlyList<string> PlotNames { get; }

Property Value

IReadOnlyList<string>

T

The number of transitions plotted (t).

public int T { get; }

Property Value

int

Methods

Callback(object?, object?, object?, double, bool, bool, Info)

Plots a transition (callback): appends DataCallback's points, then redraws every plot over the steps [max(0, t - horizon), t) and lets the figure show it (plt.pause(0.000001)). Pass it as Run(IEnv, bool?, double?, double?, PlayCallback?, object?, BigInteger?, object?, bool, EnvViewerFactory?, PygameContext?)'s callback.

public void Callback(object? obsT, object? obsTp1, object? action, double rew, bool terminated, bool truncated, Info info)

Parameters

obsT object

The observation before the action.

obsTp1 object

The observation after the action.

action object

The action.

rew double

The reward.

terminated bool

Whether the episode ended in a terminal state.

truncated bool

Whether the episode was cut short.

info Info

The step's info.

Exceptions

ValueError

Thrown when the callback returns more or fewer points than there are plots (zip() argument 2 is shorter than argument 1, or longer), after appending the points it could pair, as Python's zip(strict=True) does; and by the default figure when the plots' lengths then disagree (x and y must be the same size).