-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlayout_functions.py
72 lines (68 loc) · 2.42 KB
/
layout_functions.py
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
import numpy as np
import pandas as pd
from pickle_functions import unpicklify
import plotly.graph_objects as go
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
import dash_table as dt
from dash.dependencies import Input, Output, State
#from app_functions import *
from pickle_functions import unpicklify
from process_functions import write_log
def list_item(opening, data, ending):
'''
input:
info data about a statistic for a country
a string describing it
a string of eventual text after data
output:
if the data is valid returns an item, otherwise nothing
'''
if pd.isna(data) or data == 'None' or data == 0:
return
else:
return dbc.ListGroupItemText(f'{opening}{data}{ending}')
def draw_singleCountry_Scatter(df, dropdown, plotName):
'''
Function to generate and plot a scatterplot for the selected countries
'''
#print(df.index)
fig = go.Figure()
#countries = df.columns
#dates = df.loc[df['Region'] == selected_region,'date']
for country in dropdown:
#x = [x for x in range(len(df[country]))]
fig.add_trace(go.Scatter(x = list(df.index), y = list(df[country]),
mode='lines+markers',
name=country,
line=dict(width=3), marker = dict(size = 3, line = dict(width = 1,color = 'DarkSlateGrey')), hoverinfo = "text",
hovertext = [f"{country}: {df.iloc[indice][country]} <br>Year: {df.index[indice]}" for indice in range(len(df))]))
fig.update_layout(title = plotName)
fig.update_layout(
hovermode='closest',
legend=dict(
x = 0,
y=-0.3,
orientation = 'h',
traceorder="normal",
font=dict(
family="sans-serif",
size=12,
),
borderwidth=0,
#x=0,
#y=-0.4,
#orientation="h"
),
plot_bgcolor = 'white',
paper_bgcolor = 'white',
xaxis = dict(
tickangle = -45
),
margin=dict(l=0, r=0, t=65, b=0),
)
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgrey')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgrey')
fig.update_yaxes(zeroline=True, zerolinewidth=2, zerolinecolor='black')
return fig