fork download
  1. import os.path
  2. # from PIL import Image
  3. # from pylab import *
  4. import matplotlib.pyplot as plt
  5. import matplotlib.image as mpimg
  6. import numpy as np
  7.  
  8.  
  9. cities_list = []
  10.  
  11. def create_record(city_data):
  12. city_data = [x.strip() for x in city_data.split(',')]
  13. record = {'city_name':city_data[0],'number_of_goblins':int(city_data[1]),'number_of_trolls':int(city_data[2]),'number_of_ogres':int(city_data[3]),'city_x':int(city_data[4]),'city_y':int(city_data[5])}
  14. cities_list.append(record)
  15.  
  16. def calculate_city_threat_level(record):
  17. goblins = record['number_of_goblins']
  18. trolls = record['number_of_trolls']
  19. ogres = record['number_of_ogres']
  20. city_threat_points = 3*goblins + 6*trolls + 9*ogres
  21. city_threat_level = 5*((city_threat_points/float(100))+1)
  22. return city_threat_level
  23.  
  24. def setup():
  25. # input from file "invasion_data.txt"
  26. fname = "invasion_data.txt"
  27.  
  28. # read all names in the file
  29. with open(fname) as f:
  30. content = f.readlines()
  31.  
  32. # remove newline character '\n' at the end of each line to create a list of city data
  33. records = [x.strip() for x in content]
  34.  
  35. map(create_record, records)
  36.  
  37.  
  38. # read image to array
  39. img=mpimg.imread('fantasy_map.png')
  40.  
  41.  
  42. # plot the image
  43. imgplot = plt.imshow(img)
  44.  
  45. # some points
  46. x = [100,100,400,400]
  47. y = [200,500,200,500]
  48.  
  49. # # plot the points with red star-markers
  50. # plot(x,y,'r*')
  51.  
  52. # # line plot connecting the first two points
  53. # plot(x[:2],y[:2])
  54.  
  55. # # add title and show the plot
  56. # title('Plotting: "empire.jpg"')
  57. # show()
  58.  
  59.  
Runtime error #stdin #stdout #stderr 0.37s 273344KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 39, in <module>
  File "/usr/lib/python2.7/dist-packages/matplotlib/image.py", line 1246, in imread
    with open(fname, 'rb') as fd:
IOError: [Errno 2] No such file or directory: 'fantasy_map.png'