How can I get this code to work on c9?

python

#1

I’m using code from a book that’s meant to display a very simple visualization using the matplotlib python 2D plotting library, and I’ve tried modifying it to work on c9 with no success so far. Here’s where I’m at now:

import os
import matplotlib
# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')
import matplotlib.pyplot as plt

squares = [1, 4, 9, 16, 25]
plt.plot(squares)
#plt.show()

#Cloud9 env
if __name__ == '__main__':
    plt.show(host=os.getenv('IP', '0.0.0.0'),port=int(os.getenv('PORT', 8080)), debug=True)

…which gives this message in the Run panel:

Your code is running at https://node-01-vdesr.c9users.io.
Important: use os.getenv(PORT, 8080) as the port and os.getenv(IP, 0.0.0.0) as the host 
in your scripts!

Process exited with code: 0

Nothing shows in the URL though. Here’s the original code (much shorter) that I started with:

import matplotlib.pyplot as plt

squares = [1, 4, 9, 16, 25]
plt.plot(squares)
plt.show()