Skip to content

Instantly share code, notes, and snippets.

@ven-kyoshiro
Created September 5, 2018 12:08
Show Gist options
  • Save ven-kyoshiro/331c9239d1e69ee7963e3f6b2564e42e to your computer and use it in GitHub Desktop.
Save ven-kyoshiro/331c9239d1e69ee7963e3f6b2564e42e to your computer and use it in GitHub Desktop.
openai gym's render cannot work with matplotlib
import matplotlib
# matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
import gym
import numpy as np
def main():
env = gym.make('CartPole-v0')
env.reset()
_ = env.render(mode='rgb_array')
left = np.array([1, 2, 3, 4, 5])
height = np.array([100, 300, 200, 500, 400])
plt.plot(left, height)
if __name__ == '__main__':
main()
@ven-kyoshiro
Copy link
Author

This is the answer !!!!!!!!!!

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import gym
import numpy as np

def main():
    env = gym.make('CartPole-v0')
    env.reset()
    _ = env.render(mode='rgb_array')
    env.close()
    left = np.array([1, 2, 3, 4, 5])
    height = np.array([100, 300, 200, 500, 400])
    plt.plot(left, height)

if __name__ == '__main__':
    main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment