Skip to content

Commit

Permalink
Implement family fonts ?
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbelgium authored Nov 29, 2024
1 parent 1b8b3f4 commit 2480e36
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions scripts/utils/interactive_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
ALL_HOURS = list(range(24))


def load_fonts():
conf = get_settings()
# Define font families based on language settings
if conf['DATABASE_LANG'] in ['ja', 'zh']:
font_family = 'Noto Sans JP'
elif conf['DATABASE_LANG'] == 'th':
font_family = 'Noto Sans Thai'
else:
font_family = 'Roboto Flex'

def normalize_logarithmic(arr):
"""Applies a logarithmic normalization to the array, mapping values between 0.5 and max(arr) to a normalized scale between 0 and 1."""
arr = arr.astype(float)
Expand All @@ -58,7 +68,7 @@ def add_annotations(text_array, text_colors, col, species_list, all_hours, annot
if current_text:
annotations.append(dict(
x=0, y=species, text=current_text, showarrow=False,
font=dict(color=current_color, size=10),
font=dict(family=font_family, color=current_color, size=10),
xref=f'x{col}', yref=f'y{col}', xanchor='center', yanchor='middle'
))
elif col == 3: # Multi-column heatmap
Expand All @@ -68,7 +78,7 @@ def add_annotations(text_array, text_colors, col, species_list, all_hours, annot
if current_text:
annotations.append(dict(
x=hour, y=species, text=current_text, showarrow=False,
font=dict(color=current_color, size=10),
font=dict(family=font_family, color=current_color, size=10),
xref='x3', yref='y3', xanchor='center', yanchor='middle'
))

Expand Down Expand Up @@ -163,32 +173,32 @@ def create_plotly_heatmap(df_birds, now):
title=dict(
text=f"<b>{main_title}</b><br><span style='font-size:12px;'>{subtitle}</span>",
x=0.5, y=0.97, xanchor='center', yanchor='top',
font=dict(size=20)
font=dict(family=font_family, size=20)
),
autosize=True,
height=max(600, len(species_list) * 25 + 100),
yaxis=dict(
autorange='reversed',
tickfont=dict(size=10),
tickfont=dict(family=font_family, size=10),
showticklabels=True,
ticklabelstandoff=15,
fixedrange=True
),
xaxis1=dict(
title='Max Confidence',
showticklabels=False,
title_font=dict(size=10),
title_font=dict(family=font_family, size=10),
fixedrange=True
),
xaxis2=dict(
title='Total Counts',
showticklabels=False,
title_font=dict(size=10),
title_font=dict(family=font_family, size=10),
fixedrange=True
),
xaxis3=dict(
title='Hour',
tickfont=dict(size=10),
tickfont=dict(family=font_family, size=10),
tickmode='linear',
dtick=1,
fixedrange=True
Expand All @@ -197,7 +207,7 @@ def create_plotly_heatmap(df_birds, now):
clickmode='event+select',
plot_bgcolor=PAPER_BGCOLOR,
paper_bgcolor=PAPER_BGCOLOR,
font=dict(size=10, color='#000000'), # Global font color set to black
font=dict(family=font_family, size=10, color='#000000'), # Global font color set to black
dragmode=False
)
fig.update_xaxes(showgrid=False, zeroline=False)
Expand Down

0 comments on commit 2480e36

Please sign in to comment.