Module functions.graphy.create_maps

Classes

class gfs_Maps (info: dict, variables: list, map_scope: Map_Scope_Enum, map_level: Map_LOD_Enum, breaks: list = None, exclusion_filter=[], subplot_columns: int = 3, language: str = 'de', disable_hover_info: bool = False, background_map_color: str = '#999', projection: str = 'mercator', show_mean: bool = False, show_count: bool = False, show_total: bool = False, show_legend: bool = True, legend_labels_rename: dict[str, str] = None, left_labels_rename: dict[str, str] = None, break_labels_rename: dict[str, str] = None, legend_break: list = None, order_by: dict = None, special_variables: list[int] = [96, 97, 98, 99999996, 99999997, 99999998], standard_arguments: dict = None, title_custom_text: str = 'auto', subtitle_custom_text: str = 'auto', tag_custom_text: str = 'auto', legend_title_custom_text: str = 'auto', title_position: int = 1, subtitle_position: int = 2, color_theme: str = 'auto', color_type: str = 'single_hue', color_direction: str = 'backward', color_custom: list[str] = None, legend_position: str = 'right', legend_labels_size: float = 14, weight: str = 'auto', select_variable_levels: list[int] = None, tag_position: int = 3, left_labels_wrap: int = 50, colorbar_length: float = 0.7, colorbar_x: float = 0.9, colorbar_y: float = 0.5, tag_add_before: str = '', tag_add_after: str = '', subtitle_add_before: str = '', subtitle_add_after: str = '', left_labels_remove_before: str = '', left_labels_remove_after: str = '', title_remove_before: str = '', title_remove_after: str = '', label_size: int = 16, select_min_count: int = 0, save_figure: bool = True, df: pandas.core.frame.DataFrame = 'auto', meta: pyreadstat._readstat_parser.metadata_container = 'auto')

Creates a map chart

Args

info : dict
A dictionary with info about the presentation. Has info like number of slides, presentation name and the presentation object itself ~ usually info
variables : list
A list of variables. If multiple are added, function doesn't accept any breaks. ~ ['AW2'] /['AW1_1', 'AW1_2', …]
map_scope : Map_Scope_Enum
defines a preset for the scope of the map eg. EU with all its countries etc.
map_level : Map_LOD_Enum
defines level of detail for the map. eg. metropolitan areas, country or others
breaks : list, optional
A list of breaks. ~ ['alter_break', 'sex_break']. Defaults to None.
exclusion_filter : list
a list of string objects representing NUTS_ID's to exlude in the maps, example: ["CH025", "CH022", "CH024"], see: https://ec.europa.eu/eurostat/web/nuts/nuts-maps for the available ID's
subplot_columns : int
count of subplotcolumns to use if there are multiple maps
language : str
language to label the shapes, must be present in translation json
disable_hover_info : bool
disables hover info on shapes
background_map_color : str
hex color code to set the background color of map shapes, default is "#999"
projection : str
projection type as a string or None ('equirectangular', 'mercator', 'orthographic', 'natural earth', 'kavrayskiy7', 'miller', 'robinson', 'eckert4', 'azimuthal equal area', 'azimuthal equidistant', 'conic equal area', 'conic conformal', 'conic equidistant', 'gnomonic', 'stereographic', 'mollweide', 'hammer', 'transverse mercator', 'albers usa', 'winkel tripel', 'aitoff' and 'sinusoidal')
show_mean : bool, optional
Turns uses the mean of the variable as x-value and changes scale type from percentage to mean. ~ True. Defaults to False.
show_count : bool, optional
Turns counts in variable labels on and off. ~ True. Defaults to False.
show_total : bool, optional
Turns total bar on and off. ~ False. Defaults to True.
show_legend : bool, optional
Turns legend on and off. ~ False. Defaults to True.
legend_labels_rename : dict[str, str], optional
Renames the labels of the different legend levels. ~ {'old_name', 'new_name'}. Defaults to None.
left_labels_rename : dict[str, str], optional
Renames the labels of the different break levels. ~ {'old_name', 'new_name'}. Defaults to None.
break_labels_rename : dict[str, str], optional
Renames the breaks. ~ {'old_name': 'new_name'}. Defaults to None.
legend_break : list, optional
A list of breaks. This is used to create the legend break if either "mean" == True or "select_variable_levels" has exactly one item ~ ['alter_break'] / [['alter_break']]. Defaults to None.
order_by : dict, optional
A dictionary. Orders the plot by any variable in the x data frame. ~ {'mean': 'asc'} / {1: 'desc'}. Defaults to None.
special_variables : list[int], optional
A list variable levels that will be treated differently. They will appear gray in the graph and have not effect on the mean calculation. ~ [16, 99999997]. Defaults to [96, 97, 98, 99999996, 99999997, 99999998].
standard_arguments : dict, optional
Adds some standard arguments that normally don't need to be changed. Defaults to None.
title_custom_text : str, optional
Creates custom title text, if automatic text isn't desired. Defaults to 'auto'.
subtitle_custom_text : str, optional
Creates custom subtitle text, if automatic text isn't desired. Defaults to 'auto'.
tag_custom_text : str, optional
Creates custom tag text, if automatic text isn't desired. Defaults to 'auto'. legend_title_custom_text (str, optional): Creates a custom legend title, if title is desired. Defaults to 'auto'.
legend_title_custom_text : str, optional
Creates a custom legend title, if title is desired. Defaults to 'auto'.
title_position : int, optional
Sets the position of the title text. ~ 0 = don't show, 1, 2, 3 are possible positions on plot. Defaults to 1.
subtitle_position : int, optional
Sets the position of the subtitle text. ~ 0 = don't show, 1, 2, 3 are possible positions on plot. Defaults to 2.
color_theme : str, optional
Sets color theme for graph. ~ 'test', 'gfs'. Defaults to 'auto'.
color_type : str, optional
Sets color value type. ~ 'diverging', 'single_hue'. Defaults to 'groups'.
color_direction : str, optional
Sets direction of color pattern. ~ 'backward'. Defaults to 'forward'.
color_custom : list[str], optional
Uses custom colors ~ ['#131366', '#454578']. Defaults to None. value_labels_show_min (float, optional): Sets threshold showing labels by %. Use 0 to show all labels and 100 to show none. Use numbers between for a mix. Defaults to 0.
legend_position : str, optional
Sets the position of the legend. ~ 'bottom'. Defaults to 'right'.
legend_labels_size : float, optional
Sets the size of legend. Defaults to 14.
weight : str, optional
Turns weight on if weight variable name is added. ~ "gewicht". Defaults to 'auto'.
select_variable_levels : list[int], optional
A list variable levels used to select and order variables. ~ [2, 1, 99999997]. Defaults to None.
tag_add_before : str, optional
Adds text before the tag text. ~ "Meine Zusatzinfo, ', " adds this string before tag. Defaults to ''.
tag_add_after : str, optional
Adds text after the tag text. ~ "Meine Zusatzinfo, ', " adds this string after tag. Defaults to ''.
tag_position : int, optional
Sets the position of the tag text. ~ 0 = don't show, 1, 2, 3 are possible positions on plot. Defaults to 3.
left_labels_wrap : int, optional
Wraps the variable labels. Defaults to 50.
colorbar_length : float, optional
scales the colorbar length. Defaults to 0.7.
colorbar_x : float, optional
changes the x coordinate of the colorbar. Defaults to 0.9.
colorbar_y : float, optional
changes the y coordinate of the colorbar. Defaults to 0.5.
subtitle_add_before : str, optional
Adds text before the tag text. ~ "Filter: F3 = 'Ja', " adds this string before tag. Defaults to ''.
subtitle_add_after : str, optional
Adds text after the tag text. ~ "Filter: F3 = 'Ja', " adds this string after tag. Defaults to ''.
left_labels_remove_before : str, optional
Removes the label text before the given string. ~ "? " deletes everything up until and including the question mark. Defaults to ''.
left_labels_remove_after : str, optional
Removes the label text after the given string. ~ ". Bitte" deletes everything after and including the punctuation mark. Defaults to ''.
title_remove_before : str, optional
Removes the label text before the given string. ~ "? " deletes everything up until and including the question mark. Defaults to ''.
title_remove_after : str, optional
Removes the label text after the given string. ~ ". Bitte" deletes everything after and including the punctuation mark that. Defaults to ''.
label_size : float, optional
Sets the size of labels. Defaults to 16.
select_min_count : int, optional
Selects all bars with higher count than given. ~ 10 means that only bars with more than 10 observations will be selected. Defaults to 0.

Methods

def clip_coordinates(self, unclipped_shapes: Map_Scope_Enum)

clips coordinates of background to a preset for the scope of the map and returns the background shape

Args

scope : Map_Scope_Enum
Enum to define the preset (EU or CH)
def create_map_figure(self, foreground_shapes: geopandas.geodataframe.GeoDataFrame, clipped_foreground_shapes: geopandas.geodataframe.GeoDataFrame)

creates map figures and combines background and foreground shapes with each other

Args

foreground_shapes (:gpd.GeoDataFrame):geopandas Dataframe with the foreground shapes data clipped_foreground_shapes (:gpd.GeoDataFrame):geopandas Dataframe with the clipped foreground shapes data

Returns

go.Figure
plotly Figure with map objects
def create_maps(self) ‑> Optional[tuple]

Creates a map chart Returns: Optional[tuple]: returns df and meta objects if return_data is True

def create_maps_df(self) ‑> pandas.core.frame.DataFrame

creates dataframe for a map graphic

Returns: pd.DataFrame: returns pandas dataframe for map

def get_foreground_shapes(self, resolution='03') ‑> geopandas.geodataframe.GeoDataFrame

gets foreground shape for the maps

Args

resolution : str
resolution size of the standard "NUTS" shapefiles - possible values are 03,10,20, default is 03

Returns: gpd.GeoDataFrame: returns filtered geopandas dataframe by level and scope

def get_translations(self) ‑> str

gets translation json for maps and map objects for the map scope Returns: str: json string with all map objects

def init_shape_file(self, resolution, file=None) ‑> geopandas.geodataframe.GeoDataFrame

reads shapefile from the file system and loads it into a geopandas dataframe

Args

resolution : str
resolution size of the standard "NUTS" shapefiles - possible values are 03,10,20
file : str
file path to your own shapefile if you need it

Returns: gpd.GeoDataFrame: returns geopandas dataframe

def shape_clipping(self, foreground_shapes: geopandas.geodataframe.GeoDataFrame, exclusion_filter: list) ‑> geopandas.geodataframe.GeoDataFrame

removes shapes with a list of NUTS ID objects

Args

foreground_shapes : gpd.GeoDataFrame
shapes to be used in the map plot

exclusion_filter (list(str)): list of NUTS ID objects to remove Returns: gpd.GeoDataFrame: returns clipped geopandas dataframe