class PieChart: def __init__(self): self.Backend = Backend() self.database = Database() self.sorted_data = {} def send_data(self): self.database.createTable() for key, value in self.Backend.parse().items(): self.database.insert(key, value) def get_data(self): database = Database() data = database.get_all() for key, value in data: self.sorted_data[key] = value return self.sorted_data def pie_chart(self, data): count = 0 percentage = [] country = [] explode = (0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0) for cntry, pnt in data.items(): if count < 10 and cntry != "European Union": percentage.append(pnt) country.append(cntry) count += 1 plt.pie( percentage, labels=country, wedgeprops={'edgecolor': 'white'}, # autopct=lambda percentage: f'{percentage:.2f}%', autopct='%1.1f%%', shadow=True, explode=explode ) plt.title("Top 10 Country by C02 Emission In 2017") plt.axis('equal') plt.show()
from AnnualTemperature import AnnualTemperature from DataBase import Database from Frontend import Frontend if __name__ == "__main__": at = AnnualTemperature() data = at.openfile('Temperature.html') dt = Database() dt.createTable() for items in data: if len(items) > 0 and int(items[0]) > 1959 and int(items[0]) < 1991: dt.insert(items[0], items[2]) frontend = Frontend() data = dt.get_all() x = [] y = [] for row in data: x.append(row[0]) y.append(row[1]) frontend.selectgraph(x, y) dt.delete_all_rows()