Class PlayPlot
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
callbackPlayPlotMetricsComputes the points of a transition, one per plot.
horizonTimestepsintHow many recent steps each plot shows (
deque(maxlen=...)); 0 keeps none.plotNamesIReadOnlyList<string>The plots' titles, one plot each.
subplotsPlayPlot.PlotSubplotsThe figure's maker, matplotlib's
plt.subplots(nrows); null uses Subplots(EnvViewerFactory?) withGymnasium.HumanViewerFactory.
Exceptions
- ArgumentNullException
Thrown when
callbackorplotNamesis 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
CurPlot
The scatter shown on each axes, null before the first point (cur_plot).
public IReadOnlyList<IPlotArtist?> CurPlot { get; }
Property Value
Data
The last HorizonTimesteps points of each plot (data).
public IReadOnlyList<Deque<double>> Data { get; }
Property Value
DataCallback
The points of each transition (data_callback).
public PlayPlotMetrics DataCallback { get; }
Property Value
Fig
The figure (fig).
public IPlotFigure Fig { get; }
Property Value
HorizonTimesteps
How many recent steps each plot shows (horizon_timesteps).
public int HorizonTimesteps { get; }
Property Value
PlotNames
The plots' titles (plot_names).
public IReadOnlyList<string> PlotNames { get; }
Property Value
T
The number of transitions plotted (t).
public int T { get; }
Property Value
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
obsTobjectThe observation before the action.
obsTp1objectThe observation after the action.
actionobjectThe action.
rewdoubleThe reward.
terminatedboolWhether the episode ended in a terminal state.
truncatedboolWhether the episode was cut short.
infoInfoThe 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, orlonger), after appending the points it could pair, as Python'szip(strict=True)does; and by the default figure when the plots' lengths then disagree (x and y must be the same size).