Created
September 30, 2020 22:02
-
-
Save janbenetka/4246bb5dca82c4dd79729372a8363fd4 to your computer and use it in GitHub Desktop.
[Plotly Unacast Template] #plotly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!pip install plotly==4.8 | |
# Quick way to install hind font | |
!npm install -g google-font-installer | |
!gfi install hind -v 300 | |
import plotly.graph_objs as go | |
import plotly.io as pio | |
pd.options.plotting.backend = "plotly" | |
pio.templates['unacast'] = go.layout.Template({ | |
'data': {'scatter': [{'marker': {'size': 20, 'symbol': 'hexagon'}, 'type': 'scatter'}]}, | |
'layout': {'autosize': True, | |
'colorscale': {'diverging': [[0, '#8e0152'], [0.1, '#c51b7d'], | |
[0.2, '#de77ae'], [0.3, '#f1b6da'], | |
[0.4, '#fde0ef'], [0.5, '#f7f7f7'], | |
[0.6, '#e6f5d0'], [0.7, '#b8e186'], | |
[0.8, '#7fbc41'], [0.9, '#4d9221'], [1, | |
'#276419']], | |
'sequential': [[0.0, '#0d0887'], | |
[0.1111111111111111, '#46039f'], | |
[0.2222222222222222, '#7201a8'], | |
[0.3333333333333333, '#9c179e'], | |
[0.4444444444444444, '#bd3786'], | |
[0.5555555555555556, '#d8576b'], | |
[0.6666666666666666, '#ed7953'], | |
[0.7777777777777778, '#fb9f3a'], | |
[0.8888888888888888, '#fdca26'], [1.0, | |
'#f0f921']], | |
'sequentialminus': [[0.0, '#0d0887'], | |
[0.1111111111111111, '#46039f'], | |
[0.2222222222222222, '#7201a8'], | |
[0.3333333333333333, '#9c179e'], | |
[0.4444444444444444, '#bd3786'], | |
[0.5555555555555556, '#d8576b'], | |
[0.6666666666666666, '#ed7953'], | |
[0.7777777777777778, '#fb9f3a'], | |
[0.8888888888888888, '#fdca26'], | |
[1.0, '#f0f921']]}, | |
'colorway': ['#FF8000', '#1A4D60', '#00B39B', '#34768F', '#C42240', | |
'#C42240', '#404040'], | |
'font': {'color': '#1C1C1C', 'family': 'Hind'}, | |
'hoverlabel': {'align': 'left'}, | |
'height': 600, | |
'width': 1400, | |
'images': [{'sizex': 0.3, | |
'sizey': 0.3, | |
'source': ('https://proptechzone.com/wp-content/uploads/2019/10/unacast-3b04492b-4fe9-4b70-9dc7-43fb22aa6d5c-1.png'), | |
#'source': "https://global-uploads.webflow.com/5dc3e2af6a906d9cc232e1bc/5dc3e2af6a906dceb532e551_unacast-symbol-uc_orange-rgb.png", | |
'x': 1.0, | |
'xanchor': 'center', | |
'xref': 'paper', | |
'y': -0.22, | |
'yanchor': 'bottom', | |
'yref': 'paper', | |
'name': 'uc-logo'}], | |
'margin': {'b': 60, 'l': 60, 'r': 60, 't': 60}, | |
'paper_bgcolor': '#FFFFFF', | |
'plot_bgcolor': '#F5F6F7', | |
'title': {'font': {'size': 25}}, | |
'xaxis': {'automargin': True, | |
'gridcolor': 'white', | |
'linecolor': 'white', | |
'showgrid': True, | |
'tickcolor': 'rgb(51,51,51)', | |
'ticks': 'outside', | |
'title': {'standoff': 15}, | |
'zerolinecolor': 'white'}, | |
'yaxis': {'automargin': True, | |
'gridcolor': 'white', | |
'linecolor': 'white', | |
'showgrid': True, | |
'tickcolor': 'rgb(51,51,51)', | |
'ticks': 'outside', | |
'title': {'standoff': 15}, | |
'zerolinecolor': 'white'}} | |
}) | |
def plot_trend(df, date_col, value_col, name="", color="black", title="", | |
width=1000, height=400, template="unacast"): | |
""" | |
Plot a single temporal trend. | |
""" | |
df.sort_values(by=date_col, inplace=True) | |
fig = go.Figure() | |
fig.add_trace(go.Scatter( | |
x = df[date_col], | |
y = df[value_col], | |
name = name, | |
line_color = color)) | |
# Use date string to set xaxis range | |
fig.update_layout( | |
title_text = title, | |
width=width, | |
height=height, | |
template="unacast" | |
) | |
fig.show() | |
def plot_trends(df, category_col, date_col, value_col, name="", colors=["black"], title="", | |
width=1000, height=400, yaxis_type="linear"): | |
""" | |
Plot a series of temporal trends. | |
""" | |
df.sort_values(by=date_col, inplace=True) | |
fig = go.Figure() | |
ix = 0 | |
for cat, cat_df in df.groupby(category_col): | |
#color = dict(enumerate(colors)).get(ix, "black") | |
fig.add_trace(go.Scatter( | |
x = cat_df[date_col], | |
y = cat_df[value_col], | |
name = cat)) | |
ix += 1 | |
# Use date string to set xaxis range | |
fig.update_layout( | |
title_text = title, | |
width=width, | |
height=height, | |
yaxis_type=yaxis_type, | |
template="unacast" | |
) | |
if(yaxis_type == "log"): | |
fig.update_layout(xaxis_type="log", yaxis_type="log") | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment