Spaces:
Sleeping

File size: 4,090 Bytes
a289188
8625b3d
a289188
 
 
 
8625b3d
a289188
 
 
 
 
8625b3d
a289188
 
 
 
 
 
 
 
 
 
 
 
8625b3d
a289188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8625b3d
a289188
 
 
 
 
 
 
8625b3d
a289188
 
 
 
 
 
 
 
 
 
8625b3d
a289188
 
 
8625b3d
 
 
 
a289188
 
 
 
 
 
8625b3d
 
a289188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
{% extends "base.html" %}
{% block title %}Visualization Gallery - Data Science Lab{% endblock %}

{% block content %}
<div class="page-header">
    <h1>πŸ“Š Visualization Gallery</h1>
    <p class="breadcrumb">Home / Visualization β€” Interactive charts from datasets</p>
</div>

<div class="concept-section">
    <div class="concept-header"><h3>πŸ“– Data Visualization Principles</h3></div>
    <div class="concept-body">
        <p>Good visualizations tell stories. In Data-driven governance, charts and dashboards inform policy decisions on housing, transport, and urban planning.</p>
        <h4>Key Principles</h4>
        <ul>
            <li><strong>Choose the right chart type:</strong> Bar for comparison, line for trends, scatter for relationships, heatmap for correlations</li>
            <li><strong>Label clearly:</strong> Title, axis labels, legends, units</li>
            <li><strong>Avoid clutter:</strong> Remove unnecessary gridlines, decorations, and 3D effects</li>
            <li><strong>Use color purposefully:</strong> Consistent palette, colorblind-friendly, meaningful encoding</li>
        </ul>
    </div>
</div>

{% if charts.transport %}
<div class="chart-container">
    <h3 style="margin-bottom: 12px;">πŸš‡ Transit Station Usage</h3>
    <div id="chart-transport"></div>
</div>
{% endif %}

{% if charts.population %}
<div class="chart-container">
    <h3 style="margin-bottom: 12px;">πŸ‘₯ Population Distribution</h3>
    <div id="chart-population"></div>
</div>
{% endif %}

{% if charts.energy %}
<div class="chart-container">
    <h3 style="margin-bottom: 12px;">⚑ Energy Consumption Trends</h3>
    <div id="chart-energy"></div>
</div>
{% endif %}

{% if charts.schools %}
<div class="chart-container">
    <h3 style="margin-bottom: 12px;">🏫 School Enrollment</h3>
    <div id="chart-schools"></div>
</div>
{% endif %}

{% if charts.hdb_bubble %}
<div class="chart-container">
    <h3 style="margin-bottom: 12px;">🏘️ Price vs Area (Bubble Chart)</h3>
    <div id="chart-hdb-bubble"></div>
</div>
{% endif %}

<div class="card">
    <div class="card-header"><h3>πŸ“₯ Download Data</h3></div>
    <div style="display: flex; gap: 12px; flex-wrap: wrap;">
        <a href="/download/hdb" class="btn btn-primary">πŸ“„ Housing Data (CSV)</a>
        <a href="/download/transport" class="btn btn-primary">πŸ“„ Transport Data (CSV)</a>
        <a href="/download/population" class="btn btn-primary">πŸ“„ Population Data (CSV)</a>
        <a href="/download/energy" class="btn btn-primary">πŸ“„ Energy Data (CSV)</a>
    </div>
</div>

<div class="code-block"><span class="lang-label">Python</span><pre>import plotly.express as px
import pandas as pd

# Creating interactive charts with Plotly
df = pd.read_csv('data/housing_data.csv')

# Bar chart: Average price by town
fig = px.bar(
    df.groupby('town')['price'].mean().reset_index(),
    x='town', y='price',
    title='Average Housing Data Price by Town',
    labels={'price': 'Average Price (SGD)'}
)
fig.update_layout(xaxis_tickangle=-45)
fig.show()

# Scatter plot with trendline
fig2 = px.scatter(
    df, x='area', y='price',
    color='property_type', trendline='ols',
    title='Floor Area vs Price with Trendline'
)
fig2.show()</pre></div>

<div class="exercise-box">
    <h5>πŸ§ͺ Try It Yourself</h5>
    <p>1. Create a box plot of resale prices by flat type.</p>
    <p>2. Make a line chart showing monthly average prices over time.</p>
    <p>3. Design a heatmap showing price per sqm by town and flat type.</p>
</div>
{% endblock %}

{% block scripts %}
<script>
{% if charts.transport %}renderPlotly('chart-transport', '{{ charts.transport|safe }}');{% endif %}
{% if charts.population %}renderPlotly('chart-population', '{{ charts.population|safe }}');{% endif %}
{% if charts.energy %}renderPlotly('chart-energy', '{{ charts.energy|safe }}');{% endif %}
{% if charts.schools %}renderPlotly('chart-schools', '{{ charts.schools|safe }}');{% endif %}
{% if charts.hdb_bubble %}renderPlotly('chart-hdb-bubble', '{{ charts.hdb_bubble|safe }}');{% endif %}
</script>
{% endblock %}