btgym.rendering package¶
btgym.rendering.renderer module¶
-
class
btgym.rendering.renderer.
BTgymRendering
(render_modes, **kwargs)[source]¶ Handles BTgym Environment rendering.
Note
Call initialize_pyplot() method before first render() call!
Plotting controls, can be passed as kwargs.
Parameters: - render_state_as_image=True, –
- render_state_channel=0, –
- render_size_human= (6, 3.5) –
- render_size_state= (7, 3.5) –
- render_size_episode= (12,8) –
- render_dpi=75, –
- render_plotstyle='seaborn', –
- render_cmap='PRGn', –
- timesteps', (render_xlabel='Relative) –
- render_ylabel='Value', –
- step (render_title='local) – {}, state observation min: {:.4f}, max: {:.4f}’,
- render_boxtext=dict(fontsize=12, – fontweight=’bold’, color=’w’, bbox={‘facecolor’: ‘k’, ‘alpha’: 0.3, ‘pad’: 3}, )
-
initialize_pyplot
()[source]¶ Call me before use! [Supposed to be done inside already running server process]
-
to_string
(dictionary, excluded=[])[source]¶ Converts given dictionary to more-or-less good looking text block string.
-
parse_response
(state, mode, reward, info, done)[source]¶ Converts environment response to plotting attributes: state, title, text.
-
render
(mode_list, cerebro=None, step_to_render=None, send_img=True)[source]¶ Renders given mode if possible, else just passes last already rendered image. Returns rgb image as numpy array.
- Logic:
- If cerebro arg is received:
- render entire episode, using built-in backtrader plotting feature, update stored episode image.
- If `step_to_render’ arg is received:
- if mode = ‘raw_state’:
- render current state observation in conventional ‘price’ format, update stored raw_state image;
- if mode = something_else’:
- visualise observation as ‘seen’ by agent, update stored ‘agent’ image.
Returns: mode image. Note
It can actually return several modes in a single dict. It prevented by Gym modes convention, but done internally at the end of the episode.
-
draw_plot
(data, figsize=(10, 6), title='', box_text='', xlabel='X', ylabel='Y', line_labels=None)[source]¶ Visualises environment state as 2d line plot. Retrurns image as rgb_array.
Parameters: - data – np.array of shape [num_values, num_lines]
- figsize – figure size (in.)
- title –
- box_text –
- xlabel –
- ylabel –
- line_labels – iterable holding line legends as str
Returns: rgb image as np.array of size [with, height, 3]