#!/usr/bin/python # -*- coding: UTF-8 -*- #Uncomment next line to run in goolge colab #!pip install geopandas import numpy as np import geopandas as gpd import pandas as pd import matplotlib.pyplot as plt import copy import urllib import os np. set_printoptions(suppress=True) fp_geodata="https://titlon.uit.no/hht/data/continents.zip" #This module creates a set of image files that can be used together with #a slider tool in a web page to create a graphical representation of population #developement the last 2000 years. See the source code of the web page to see #how to use it in a web page def main(): #creating the plot fig,ax=plt.subplots() #creating the world: world=world_map() #defining the years that will be plotted: rng=[0, 200, 400, 600, 800, 1000, 1100, 1200, 1300, 1400, 1450, 1500, 1550, 1600, 1650, 1700, 1750, 1800, 1825, 1850, 1875, 1900, 1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990, 2000, 2010, 2020, 2030] #making directory for image files: try: os.mkdir("./img") except: pass#just continue if it all ready exist #iterating over years: k=0 for year in rng: w=world.world_calc(year) #calculating the world for a given year. w is a geopandas map object plt.cla() #clears the plot for a new one plt.axis('off') #do not plot the axes, they make it look less like a map plt.axis([-150, 200, -110, 110]) #fix the axis so that the size is constant #plot the map and save it as a jpg image. This will #throw an exception each time, but the figure will be saved fine: w.plot('CONTINENT',ax=ax,aspect=0.9) fig.savefig(f'./img/fig{k}.jpg',dpi=200,bbox_inches='tight') k+=1 create_html_file(rng) def create_html_file(rng): """This function creates a html-file with a slider that select the image for the desired year""" n=len(rng) s=f"
\r\n" #iterating to create a html-tag for each image: for k in range(len(rng)):#paste the result of this into the html code s+=f"
\r\n" #building the html-code from a string and two files: html=s+f"\r\n