Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to stream OpenAI Gym environment rendering within a Jupyter Notebook

Open jupyter with

$ xvfb-run -s "-screen 0 1400x900x24" jupyter notebook

In Jupyter

import matplotlib.pyplot as plt
%matplotlib inline

After each step

def show_state(env, step=0):
    plt.figure(3)
    plt.clf()
    plt.imshow(env.render(mode='rgb_array'))
    plt.title("%s. Step: %d" % (env._spec.id,step))
    
    plt.pause(0.001)  # pause for plots to update

    if is_ipython:
        display.clear_output(wait=True)
        display.display(plt.gcf())
@baek-jinoo

This comment has been minimized.

Copy link

baek-jinoo commented Jan 8, 2019

not doing display.display(plt.gcf()) made it much better to view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.