示例#1
0
 def __init__(self, engine):
     self.engine = engine
     self.year_range = Plot.get_year_range(self.engine, 'year',
                                           'live_births')
     self.years_xlabels = np.arange(self.year_range['min'],
                                    self.year_range['max'] + 1).tolist()
     self.data = self.query_data()
示例#2
0
 def plot_line_graph(self):
     line_chart = pygal.Line(show_legend=False,
                             x_label_rotation=270,
                             style=style)
     line_chart.title = 'Live Births'
     line_chart.x_labels = self.years_xlabels
     line_chart.add('Live Births', self.data)
     line_chart.render_to_file(Plot.generate_plot_name('live_birth_line'))
示例#3
0
 def plot_bar_graph(self):
     bar_graph = pygal.Bar(show_legend=False,
                           x_label_rotation=270,
                           style=style)
     bar_graph.title = 'Live Births'
     print(self.years_xlabels)
     bar_graph.x_labels = self.years_xlabels
     bar_graph.add('Live Births', self.data)
     bar_graph.render_to_file(Plot.generate_plot_name('live_birth_bar'))
示例#4
0
 def plot_line_graph(self, flats):
     data = self.query_trend_data(flats)
     line_graph = pygal.Line(style=style, x_label_rotation=270)
     line_graph.x_labels = self.quarters
     line_graph.title = 'Trend of resale prices (All time)'
     for flat in flats:
         line_graph.add(flat, data[flat])
     line_graph.render_to_file(
         Plot.generate_plot_name('resale_price_trend'))
示例#5
0
 def plot_bar_graph(self):
     data = self.query_distribution_data()
     bar_graph = pygal.Bar(show_legend=False,
                           x_label_rotation=270,
                           style=style,
                           truncate_label=max(map(len, list(data.keys()))))
     bar_graph.title = 'Live Births By Mother\'s Occupation'
     bar_graph.x_labels = [key for key in data.keys()]
     bar_graph.add('Live Births', [val for val in data.values()])
     bar_graph.render_to_file(Plot.generate_plot_name('occupation_bar'))
示例#6
0
 def plot_line_graph(self):
     data = self.query_collection_data()
     line_graph = pygal.Line(x_label_rotation=270, style=style)
     line_graph.title = 'Live births by Working and Non-Working women'
     line_graph.add('Working', [dist['working'] for dist in data.values()])
     line_graph.add('Non-Working',
                    [dist['non_working'] for dist in data.values()])
     line_graph.x_labels = [str(key) for key in data.keys()]
     line_graph.render_to_file(
         Plot.generate_plot_name('working_non_working_live_births'))
示例#7
0
	def plot_right_scatter(self):
		scatter_plot = pygal.XY(
			stroke=False,
			style=style,
			show_legend=False,
			x_title='Live Birth Rate',
			y_title='Primary Enrolment')
		scatter_plot.title = 'Correlation between Primary Enrolment and Live Birth Rate'
		scatter_plot.add('Correlation', self.query_data('right'))
		scatter_plot.render_to_file(Plot.generate_plot_name('correlation_enrolment_live_birth_right'))
示例#8
0
	def plot_line_graph(self):
		data = self.query_data()
		line_graph = pygal.Line(
			show_legend=False,
			style=style,
			x_label_rotation=270,
			show_minor_x_labels=False)
		line_graph.title = 'Job Vacancy Rate'
		line_graph.x_labels = [key for key in data.keys()]
		line_graph.x_labels_major = [key for key in data.keys() if key[key.rfind('-') + 1:] == 'Q1']
		line_graph.add('Job Vacancy', [d for d in data.values()])
		line_graph.render_to_file(Plot.generate_plot_name('job_vacancy_rate'))
示例#9
0
    def plot_box_plot(self, flats, quarter):
        data = self.query_distribution_data(flats, quarter)

        box_plot = pygal.Box(box_mode="stdev", style=style)
        box_plot.title = f'Distribution of median resale prices in the Q{quarter} (All Time)'
        box_plot.x_labels = flats
        for flat in flats:
            box_plot.add(flat, data[flat])

        box_plot.render_to_file(
            Plot.generate_plot_name(
                f'resale_price_distribution_box_Q{quarter}_all_time'))
示例#10
0
    def plot_histogram(self, flat_type, year):
        interval = 50000

        data = self.query_price_data(flat_type, year)
        print(data)

        filtered = self.filter(data, interval)
        histogram = pygal.Histogram(show_legend=False,
                                    style=style,
                                    x_label_rotation=270)
        histogram.title = f'Distribution of resale price - {flat_type} in {year}'
        histogram.x_labels = [int(key) for key in filtered.keys()]
        histogram.add(
            f'{flat_type}',
            self.create_values(self.filter(data, interval), interval))
        histogram.render_to_file(
            Plot.generate_plot_name(
                f'resale_price_distribution_{flat_type}_{year}'))