Skip to content

Commit b954a52

Browse files
committed
Cleanup doc
1 parent b933f9a commit b954a52

File tree

1 file changed

+56
-71
lines changed

1 file changed

+56
-71
lines changed

docs/guide/plotting.rst

Lines changed: 56 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,37 @@
44
Plotting
55
========
66

7+
78
Stable Baselines3 provides utilities for plotting training results to monitor and visualize your agent's learning progress.
9+
The plotting functionality is provided by the ``results_plotter`` module, which can load monitor files created during training and generate various plots.
810

911
.. note::
1012

11-
For paper-ready plotting, we recommend using the
13+
For plotting, we recommend using the
1214
`RL Baselines3 Zoo plotting scripts <https://rl-baselines3-zoo.readthedocs.io/en/master/guide/plot.html>`_
1315
which provide plotting capabilities with confidence intervals, and publication-ready visualizations.
1416

1517

1618
Recommended Approach: RL Baselines3 Zoo Plotting
1719
================================================
1820

19-
Installation and Usage
20-
----------------------
21+
To have good plotting capabilities, including:
22+
23+
- Comparing results across different environments
24+
- Publication-ready plots with confidence intervals
25+
- Evaluation plots with error bars
26+
27+
We recommend using the plotting scripts from `RL Baselines3 Zoo <https://github.com/DLR-RM/rl-baselines3-zoo>`_:
28+
29+
- `plot_train.py <https://github.com/DLR-RM/rl-baselines3-zoo/blob/master/rl_zoo3/plots/plot_train.py>`_: For training plots
30+
- `all_plots.py <https://github.com/DLR-RM/rl-baselines3-zoo/blob/master/rl_zoo3/plots/all_plots.py>`_: For evaluation plots, to post-process the result
31+
- `plot_from_file.py <https://github.com/DLR-RM/rl-baselines3-zoo/blob/master/rl_zoo3/plots/plot_from_file.py>`_: For more advanced plotting from post-processed results
32+
33+
These scripts provide additional features not available in the basic SB3 plotting utilities.
34+
35+
36+
Installation
37+
------------
2138

2239
First, install RL Baselines3 Zoo:
2340

@@ -26,7 +43,7 @@ First, install RL Baselines3 Zoo:
2643
pip install rl_zoo3[plots]
2744
2845
Basic Training Plot Examples
29-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46+
----------------------------
3047

3148
.. code-block:: bash
3249
@@ -38,29 +55,51 @@ Basic Training Plot Examples
3855
3956
4057
Evaluation and Comparison Plots
41-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58+
-------------------------------
4259

4360
.. code-block:: bash
4461
45-
# Generate evaluation plots and save post-processed results in `logs/demo_plots.pkl` in order to use `plot_from_file`
62+
# Generate evaluation plots and save post-processed results
63+
# in `logs/demo_plots.pkl` in order to use `plot_from_file`
4664
python -m rl_zoo3.plots.all_plots --algo ppo sac -e Pendulum-v1 -f logs/ -o logs/demo_plots
4765
48-
# More advanced plotting (with confidence intervals)
66+
# More advanced plotting from post-processed results (with confidence intervals)
4967
python -m rl_zoo3.plots.plot_from_file -i logs/demo_plots.pkl --rliable --ci-size 0.95
5068
5169
5270
For more examples, please read the
5371
`RL Baselines3 Zoo plotting guide <https://rl-baselines3-zoo.readthedocs.io/en/master/guide/plot.html>`_.
5472

5573

74+
Real-Time Monitoring
75+
====================
76+
77+
For real-time monitoring during training, consider using the plotting functions within callbacks
78+
(see the `Callbacks guide <callbacks.html>`_) or integrating with tools like `Tensorboard <tensorboard.html>`_ or Weights & Biases
79+
(see the `Integrations guide <integrations.html>`_).
80+
81+
Monitor File Format
82+
===================
83+
84+
The ``Monitor`` wrapper saves training data in CSV format with the following columns:
85+
86+
- ``r``: Episode reward
87+
- ``l``: Episode length (number of steps)
88+
- ``t``: Timestamp (wall-clock time when episode ended)
89+
90+
Additional columns may be present if you log custom metrics in the environment"s info dict.
91+
92+
.. note::
93+
94+
The plotting functions automatically handle multiple monitor files from the same directory,
95+
which occurs when using vectorized environments. The episodes are loaded and sorted by timestamp
96+
to maintain proper chronological order.
97+
5698
Basic SB3 Plotting (Simple Use Cases)
5799
======================================
58100

59-
The following sections document the basic plotting utilities included directly in Stable Baselines3.
60-
These are suitable for quick debugging and simple visualizations, but we recommend using RL Zoo3 for any serious analysis.
61-
62-
Simple Plotting Examples: Single Training Run
63-
---------------------------------------------
101+
Basic Plotting: Single Training Run
102+
-----------------------------------
64103

65104
The simplest way to plot training results is to use the ``plot_results`` function after training an agent.
66105
This function reads monitor files created by the ``Monitor`` wrapper and plots the episode rewards over time.
@@ -93,8 +132,8 @@ This function reads monitor files created by the ``Monitor`` wrapper and plots t
93132
plt.show()
94133
95134
96-
Simple Plotting Modes
97-
---------------------
135+
Different Plotting Modes
136+
------------------------
98137

99138
The plotting functions support three different x-axis modes:
100139

@@ -117,8 +156,8 @@ The plotting functions support three different x-axis modes:
117156
plt.show()
118157
119158
120-
Manual Data Processing with SB3 Utilities
121-
------------------------------------------
159+
Advanced Plotting with Manual Data Processing
160+
---------------------------------------------
122161

123162
For more control over the plotting, you can use the underlying functions to process the data manually:
124163

@@ -149,62 +188,8 @@ For more control over the plotting, you can use the underlying functions to proc
149188
x_smooth, y_smooth = window_func(x, y, 50, np.mean)
150189
plt.plot(x_smooth, y_smooth, linewidth=2)
151190
plt.xlabel("Timesteps")
152-
plt.ylabel("Average Episode Reward (50-episode window)")
191+
plt.ylabel("Average Episode Reward (50-episode window)"")
153192
plt.title("Smoothed Episode Rewards")
154193
155194
plt.tight_layout()
156195
plt.show()
157-
158-
159-
Monitor File Format
160-
-------------------
161-
162-
The ``Monitor`` wrapper saves training data in CSV format with the following columns:
163-
164-
- ``r``: Episode reward
165-
- ``l``: Episode length (number of steps)
166-
- ``t``: Timestamp (wall-clock time when episode ended)
167-
168-
Additional columns may be present if you log custom metrics in the environment's info dict.
169-
170-
.. note::
171-
172-
The plotting functions automatically handle multiple monitor files from the same directory,
173-
which occurs when using vectorized environments. The episodes are loaded and sorted by timestamp
174-
to maintain proper chronological order.
175-
176-
177-
Real-Time Monitoring and Integrations
178-
=====================================
179-
180-
For real-time monitoring during training, consider using the plotting functions within callbacks
181-
(see the `Callbacks guide <callbacks.html>`_) or integrating with external monitoring tools.
182-
183-
**Weights & Biases Integration**
184-
185-
You can log plots to Weights & Biases for remote monitoring:
186-
187-
.. code-block:: python
188-
189-
import wandb
190-
from stable_baselines3.common.monitor import load_results
191-
192-
# Log plots to W&B
193-
df = load_results(log_dir)
194-
wandb.log({"episode_reward": wandb.plot.line_series(
195-
xs=df.index,
196-
ys=[df['r']],
197-
keys=["reward"],
198-
title="Episode Rewards",
199-
xname="Episode"
200-
)})
201-
202-
**TensorBoard**
203-
204-
Training metrics are automatically logged to TensorBoard when you specify a ``tensorboard_log`` directory
205-
during model creation. The plotting utilities complement TensorBoard by providing publication-ready figures.
206-
207-
.. note::
208-
209-
For comprehensive real-time monitoring and advanced plotting, we recommend using the RL Baselines3 Zoo
210-
plotting tools alongside TensorBoard and Weights & Biases (see the `Integrations guide <integrations.html>`_).

0 commit comments

Comments
 (0)