Module functions.graphy
gfs-graphy
These are graphical interfaces for various plots inside the technology stack of gfs-zürich.
Available Plot Types
- Barchart
- Linechart
- Maps
- Piechart
- Stacked Barchart
- Wordcloud
Break label Formatting
Multi Line Breaks (Break Line)
To break labels onto multiple lines, <br>
can be used.
Plot Example without break line (<br>
):
create_barchart(
info, ["F1_1"],
break_labels_rename={'Quartalsbreak': 'Langer Break Name ohne Umbruch'}
)
Plot Example with break line (<br>
):
create_barchart(
info, ["F1_1"],
break_labels_rename={'Quartalsbreak': 'Langer Break Name<br>mit Umbruch',}
)
Cursive (Italic)
To set labels to print in italic, <i>
can be used.
Plot Example with break line (<i>
):
create_barchart(
info, ["F1_1"],
break_labels_rename={'Quartalsbreak': '<i>Kursiv / Italic Break name',}
)
Others
label | usage |
---|---|
X<sup>2</sup> |
X2 |
X<sub>2</sub> |
X2 |
Standardarguments for Plots
use the standardarguments in the gfs plots by supplying it in the "standard_arguments" parameter. Example:
create_barchart(
info, ["F1_1"], standard_arguments={"tick_values": [0, 20, 40, 60, 80, 100]}
)
Name | example | description | plots |
---|---|---|---|
plot_width | 980 | defines plot width | barchart, stacked_barchart, piechart |
plot_height | 500 | defines plot height | barchart, stacked_barchart, piechart |
tick_values | [0, 20, 40, 60, 80, 100] | defines x axis tick values | barchart, stacked_barchart |
round_value_labels | 0 | round the value label to the integer you supply | barchart |
round_mean | 1 | round the value label to the integer you supply | stacked_barchart |
axis_suffix | "%" | add or remove suffix to the x axis labels | barchart |
x_min | 2 | Changes min value of x axis | barchart |
x_max | 120 | Changes max value of x axis | barchart |
title_text_size | 20 | changes size of PowerPoint slide title | all |
paper_background_color | "#FFFFFF" | changes background color of plot paper | all |
plot_background_color | "#FFFFFF" | changes background color of plot | all |
grid_color | "#D7D7D7" | changes color of plot grid | all |
label_color | "rgb(67, 67, 67)" | changes label color | all |
sharpness | 2.5 | changes sharpness of .png | all |
font_family | "Arial" | changes font family in plots | all |
1000_separator | "'" | Adds a custom separator like 1'264 in some places (not fully implemented) | all |
font_width | 1.2 | If a different font than "Leelawadee UI" is used, this correction factor can improve automatic label width | all |
Sub-modules
functions.graphy.create_maps
functions.graphy.main_data
functions.graphy.main_functions
functions.graphy.main_graph
functions.graphy.main_helper
functions.graphy.main_presentation
functions.graphy.main_wrangling
functions.graphy.map_helper
Functions
def add_combined_graphs_slide(info: dict, figures: list, title_text: str, subtitle_text: str, tag_text: str, group_images: bool = True, share_y_labels: bool = True) ‑> None
-
combines a list of plotly figures onto a grid and saves it as a powerpoint slied
Args
info
:dict
- The presentation object
figures
:list
- list of plotly figures, make sure to use single instances of them, in doubt make a deepcopy
title_text
:str
- title_text
subtitle_text
:str
- subtitle_text
tag_text
:str
- tag_text
group_images
:bool
, optional- determines whether images are grouped in the slide. Defaults to True.
share_y_labels
:bool
, optional- determines whether images share the y axis labels row-wise. Defaults to True.
Raises
ValueError
- if an invalid number of figures is entered, only 2 to 9 figures are valid
def add_table_slide(info: dict, title_text: str, table: pandas.core.frame.DataFrame, table_width: float = 22.5, table_height: float = 5.0, table_top_distance: float = 4.5, table_left_distance: float = 1.5, column_titles: Optional[None] = None, column_alignments: Optional[None] = None, column_widths: Optional[None] = None, bold_cells: Optional[None] = None, font_size: int = 14, row_heights: Optional[None] = None, cells_with_custom_color: Optional[None] = None, show_table_background_color: bool = True, title_font_size: int = 20, table_font_name: str = 'Leelawadee UI', cells_with_hyperlinks: Optional[None] = None) ‑> None
-
Adds a table slide to the presentation
Args
info
:dict
- The presentation object
title_text
:str
- The title of the slide
table
:pd.DataFrame
- The table that should be added to the slide
table_width
:float
, optional- The width of the table. Defaults to 22.5.
table_height
:float
, optional- The height of the table. Defaults to 5.0.
column_alignments
:Union[None, list[str]]
, optional- The alignment of the columns. Defaults to None. If None, all columns will be aligned left. If a list is passed, it should contain the alignment for each column in the table. The alignment can be 1 (left), 2 (center), or 3 (right).
column_titles
:Union[None, list[str]]
, optional- The titles of the columns. Defaults to None. If None, the table will not have column titles. If a list is passed, it should contain the title for each column in the table.
column_widths
:Union[None, list[int]]
, optional- The width of the columns. Defaults to None. If None, all columns will have the same width. If a list is passed, it should contain the width for each column in the table. The values should be integers and only the relative width is important.
bold_cells
:Union[None, list[tuple[int, int]]]
, optional- The cells that should be bold. Defaults to None. If None, no cells will be bold. If a list is passed, it should contain the row and column index of the cells that should be bold.
font_size
:int
, optional- The font size of the text in the table. Defaults to 14.
row_heights
:Union[None, list[float]]
, optional- The height of the rows. Defaults to None. If None, all rows will have the automatic height. If a list is passed, it should contain the height for each row in the table.
cells_with_custom_color
:Union[None, dict]
, optional- The cells that should have a custom color. Defaults to None. If None, no cells will have a custom color. If a dictionary is passed, it should contain the row and column index of the cells as keys and the color as values. The color should be a string with the hex code of the color.
show_table_background_color
:bool
, optional- Determines if the table background color should be shown. Defaults to True.
title_font_size
:int
, optional- The font size of the title. Defaults to 20.
table_font_name
:str
, optional- The name of the font used in the whole table.
cells_with_hyperlinks
:Union[None, dict]
, optional- The cells that should have a hyperlink. Defaults to None. If None, no cells will have a hyperlink. If a dictionary is passed, it should contain the row and column index of the cells as keys and the hyperlink as values. The hyperlink should be a string with the address of the hyperlink.
def add_text_slide(info: dict, text: Union[list[dict], list[str]], my_title: str = 'gfs-zürich, Markt- & Sozialforschung', vertical_alignment: str = 'top') ‑> None
-
Adds a text slide to the presentation
Args
info
:dict
- The presentation object
text
:Union[list[dict], list[str]]
- The text that should be added to the slide. If a list of dictionaries is passed, each dictionary should contain a "text" key with the text that should be added to the slide. Additionally, the dictionary can contain a "size" key with the font size of the text, a "bold" key with a boolean value that determines if the text should be bold, a "hyperlink" key that adds a link as the value, a "alignment" key that changes the text alignment (left, center, right) and a "color" key with the color of the text. If a list of strings is passed, each string will be added to the slide as a paragraph.
my_title
:str
, optional- The title of the slide. Defaults to 'gfs-zürich, Markt- & Sozialforschung'.
vertical_alignment
:str
, optional- The vertical alignment of the text. Defaults to 'top'.
def create_barchart(info: dict, variables: list, breaks: Optional[list] = None, legend_break: Optional[list] = None, barchart_mean: bool = False, break_labels_rename: Optional[dict[str, str]] = None, left_labels_rename: Optional[dict[str, str]] = None, legend_labels_rename: Optional[dict[str, str]] = None, left_labels_wrap: int = 50, left_labels_width: int = 999, show_mean: bool = False, 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, tag_position: int = 3, legend_position: str = 'right', return_data: bool = False, color_theme: str = 'auto', color_type: str = 'groups', color_direction: str = 'forward', color_custom: Optional[None] = None, value_labels_show_min: float = 0, value_labels_add_after: Optional[list[list[str]]] = None, value_labels_transform: function = <function <lambda>>, weight: str = 'auto', order_by: Optional[None] = None, title_remove_before: str = '', title_remove_after: str = '', title_add_end: str = '', 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 = '', bar_gap: float = 999, bar_width: float = 999, bar_min_size: float = 0, break_distance: float = 999, label_size: float = 16, value_labels_size: float = 999, legend_labels_size: float = 14, show_legend: bool = True, show_total_legend: bool = True, show_total: bool = True, show_count: bool = False, show_index: bool = False, show_count_legend: bool = False, show_index_legend: bool = False, show_all_bars: bool = False, show_legend_title: Optional[bool] = None, select_variable_levels: Optional[None] = None, select_variables: Optional[None] = None, select_min_count: int = 0, special_variables: list[int] = [96, 97, 98, 99999996, 99999997, 99999998], standard_arguments: Optional[None] = None, save_figure: bool = True, return_figure: bool = False, df: Union[pandas.core.frame.DataFrame, str] = 'auto', meta: pyreadstat._readstat_parser.metadata_container = 'auto') ‑> Optional[tuple]
-
Creates a barchart
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', …]
breaks
:list
, optional- A list of breaks. ~ ['alter_break', 'sex_break']. 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.
barchart_mean
:bool
, optional- Toggles barchart type mean, where mean value of variable is shown. Defaults to False.
break_labels_rename
:dict[str, str]
, optional- Renames the breaks. ~ {'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.
legend_labels_rename
:dict[str, str]
, optional- Renames the labels of the different legend levels. ~ {'old_name', 'new_name'}. Defaults to None.
left_labels_wrap
:int
, optional- Wraps the variable labels. Defaults to 50.
left_labels_width
:int
, optional- Changes the space allocated to the y-label. Defaults to 999 (which means automatic).
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.
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'.
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.
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.
legend_position
:str
, optional- Sets the position of the legend. ~ 'bottom'. Defaults to 'right'.
return_data
:bool
, optional- Returns the data frame, that is used to construct the graph, so it can be viewed. The data frame will be printed out if the parameter is True. This doesn't affect the graph in any way. Defaults to False.
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.
value_labels_add_after
:list[list[str]]
, optional- Adds text after the value labels ~ [['text', 'text'], ['text', 'text']]. Defaults to None.
weight
:str
, optional- Turns weight on if weight variable name is added. ~ "gewicht". Defaults to 'auto'.
order_by
:dict
, optional- A dictionary. Orders the plot by any variable in the x data frame. ~ {'mean': 'asc'} / {1: 'desc'}. Defaults to None.
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 ''.
title_add_end
:str
, optional- Appends given sting to the label text. Defaults to ''.
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 ''.
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 ''.
bar_gap
:int
, optional- Sets the gap between the bars within a group. Defaults to 0.15.
bar_width
:float
, optional- Sets the width of the bars. Defaults to 0.7.
bar_min_size
:float
, optional- Sets the minimum size of the show bars. Only affects plot if
show_all_bars
is set to "False". Defaults to 0. break_distance
:float
, optional- Sets the distance between the breaks. Defaults to 0.5
label_size
:float
, optional- Sets the size of labels. Defaults to 16.
value_labels_size
:float
, optional- Sets the size of value labels. Defaults to 999.
value_labels_transform
:LambdaType
, optional- Changes the size of the value_labels values with a transformation. lambda n: -n + 2 changes n to the negative value of n and adds 2. Defaults to lambda n: n.
legend_labels_size
:float
, optional- Sets the size of legend. Defaults to 14.
show_legend
:bool
, optional- Turns legend on and off. ~ False. Defaults to True.
show_total_legend
:bool
, optional- Turns Total in legend on and off. ~ False. Defaults to True.
show_total
:bool
, optional- Turns total bar on and off. ~ False. Defaults to True.
show_count
:bool
, optional- Turns counts in variable labels on and off. ~ True. Defaults to False.
show_index
:bool
, optional- Turns index in variable labels on and off. ~ True. Defaults to False.
show_count_legend
:bool
, optional- Turns counts in legend labels on and off. ~ True. Defaults to False.
show_index_legend
:bool
, optional- Turns index in legend labels on and off. ~ True. Defaults to False.
show_all_bars
:bool
, optional- Turns counts bars with zero observations on and off. ~ True. Defaults to False.
show_legend_title
:bool
, optional- Toggles legend title. ~ True / False. Defaults to None, which means automatic.
select_variable_levels
:list[int]
, optional- A list variable levels used to select and order variables. ~ [2, 1, 99999997]. Defaults to None.
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.
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.
save_figure
:dict
, optional- Turns figure export on and off. Defaults to True.
return_figure
:bool
, optional- Turns figure return on and off. Defaults to False.
df
:pd.DataFrame
, optional- The current data file ~ usually df. Defaults to 'auto'.
meta
:pyreadstat._readstat_parser.metadata_container
, optional- The current meta data file ~ usually meta. Defaults to 'auto'.
Returns
Optional[tuple]
- returns df and meta objects if return_data is True
def create_linechart(info: dict, variables: list, breaks: Optional[list] = None, legend_break: Optional[list] = None, linechart_mean: bool = False, break_labels_rename: Optional[dict[str, str]] = None, left_labels_rename: Optional[dict[str, str]] = None, legend_labels_rename: Optional[dict[str, str]] = None, left_labels_wrap: int = 50, left_labels_width: int = 999, show_mean: bool = False, 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, tag_position: int = 3, legend_position: str = 'right', return_data: bool = False, color_theme: str = 'auto', color_type: str = 'groups', color_direction: str = 'forward', color_custom: Optional[None] = None, value_labels_show_min: float = 0, value_labels_add_after: Optional[list[list[str]]] = None, weight: str = 'auto', order_by: Optional[None] = None, title_remove_before: str = '', title_remove_after: str = '', title_add_end: str = '', 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 = '', line_width: int = 999, line_marker_size: int = 999, break_distance: float = 999, label_size: float = 16, value_labels_size: float = 999, legend_labels_size: float = 14, show_legend: bool = True, show_total_legend: bool = True, show_total: bool = True, show_count: bool = False, show_index: bool = False, show_count_legend: bool = False, show_index_legend: bool = False, show_legend_title: Optional[bool] = None, select_variable_levels: Optional[None] = None, select_min_count: int = 0, break_x_axis: bool = False, special_variables: list[int] = [96, 97, 98, 99999996, 99999997, 99999998], standard_arguments: Optional[None] = None, save_figure: bool = True, return_figure: bool = False, df: Union[pandas.core.frame.DataFrame, str] = 'auto', meta: pyreadstat._readstat_parser.metadata_container = 'auto') ‑> Optional[tuple]
-
Creates a linechart
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', …]
breaks
:list
, optional- A list of breaks. ~ ['alter_break', 'sex_break']. 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.
linechart_mean
:bool
, optional- Toggles linechart type mean, where mean value of variable is shown. Defaults to False.
break_labels_rename
:dict[str, str]
, optional- Renames the breaks. ~ {'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.
legend_labels_rename
:dict[str, str]
, optional- Renames the labels of the different legend levels. ~ {'old_name', 'new_name'}. Defaults to None.
left_labels_wrap
:int
, optional- Wraps the variable labels. Defaults to 50.
left_labels_width
:int
, optional- Changes the space allocated to the y-label. Defaults to 999 (which means automatic).
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.
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'.
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.
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.
legend_position
:str
, optional- Sets the position of the legend. ~ 'bottom'. Defaults to 'right'.
return_data
:bool
, optional- Returns the data frame, that is used to construct the graph, so it can be viewed. The data frame will be printed out if the parameter is True. This doesn't affect the graph in any way. Defaults to False.
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.
value_labels_add_after
:list[list[str]]
, optional- Adds text after the value labels ~ [['text', 'text'], ['text', 'text']]. Defaults to None.
weight
:str
, optional- Turns weight on if weight variable name is added. ~ "gewicht". Defaults to 'auto'.
order_by
:dict
, optional- A dictionary. Orders the plot by any variable in the x data frame. ~ {'mean': 'asc'} / {1: 'desc'}. Defaults to None.
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 ''.
title_add_end
:str
, optional- Appends given sting to the label text. Defaults to ''.
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 ''.
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 ''.
bar_gap
:int
, optional- Sets the gap between the bars within a group. Defaults to 0.15.
bar_width
:float
, optional- Sets the width of the bars. Defaults to 0.7.
bar_min_size
:float
, optional- Sets the minimum size of the show bars. Only affects plot if
show_all_bars
is set to "False". Defaults to 0. break_distance
:float
, optional- Sets the distance between the breaks. Defaults to 0.5
label_size
:float
, optional- Sets the size of labels. Defaults to 16.
value_labels_size
:float
, optional- Sets the size of value labels. Defaults to 999.
legend_labels_size
:float
, optional- Sets the size of legend. Defaults to 14.
show_legend
:bool
, optional- Turns legend on and off. ~ False. Defaults to True.
show_total_legend
:bool
, optional- Turns Total in legend on and off. ~ False. Defaults to True.
show_total
:bool
, optional- Turns total bar on and off. ~ False. Defaults to True.
show_count
:bool
, optional- Turns counts in variable labels on and off. ~ True. Defaults to False.
show_index
:bool
, optional- Turns index in variable labels on and off. ~ True. Defaults to False.
show_count_legend
:bool
, optional- Turns counts in legend labels on and off. ~ True. Defaults to False.
show_index_legend
:bool
, optional- Turns index in legend labels on and off. ~ True. Defaults to False.
show_all_bars
:bool
, optional- Turns counts bars with zero observations on and off. ~ True. Defaults to False.
show_legend_title
:bool
, optional- Toggles legend title. ~ True / False. Defaults to None, which means automatic.
select_variable_levels
:list[int]
, optional- A list variable levels used to select and order variables. ~ [2, 1, 99999997]. Defaults to None.
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.
break_x_axis
:bool
, optional- Moves the breaks to the x Axis and the left labels to the legend, if you have only one variable this happens per default, mostly used for time-series data. Defaults to False.
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.
save_figure
:dict
, optional- Turns figure export on and off. Defaults to True.
return_figure
:bool
, optional- Turns figure return on and off. Defaults to False.
df
:pd.DataFrame
, optional- The current data file ~ usually df. Defaults to 'auto'.
meta
:pyreadstat._readstat_parser.metadata_container
, optional- The current meta data file ~ usually meta. Defaults to 'auto'.
Returns
Optional[tuple]
- returns df and meta objects if return_data is True
def create_piechart(info: dict, variables: list, breaks: list = None, break_labels_rename: dict[str, str] = None, legend_labels_rename: dict[str, str] = None, legend_position: str = 'bottom', legend_title_custom_text: str = 'auto', title_custom_text: str = 'auto', subtitle_custom_text: str = 'auto', tag_custom_text: str = 'auto', title_position: int = 1, subtitle_position: int = 2, tag_position: int = 3, return_data: bool = False, color_theme: str = 'auto', color_type: str = 'groups', color_direction: str = 'forward', color_custom: list[str] = None, value_labels_color: int = 999, value_labels_show_min: float = 0.8, weight: str = 'auto', order_by: dict = None, title_remove_before: str = '', title_remove_after: str = '', tag_add_before: str = '', tag_add_after: str = '', subtitle_add_before: str = '', subtitle_add_after: str = '', value_labels_size: float = 16, legend_labels_size: float = 12, hole_size: float = 0.4, show_legend: bool = True, show_legend_title: Optional[bool] = None, show_count: bool = False, show_decimals: bool = False, select_variable_levels: list[int] = None, special_variables: list[int] = [96, 97, 98, 99999996, 99999997, 99999998], standard_arguments: dict = None, save_figure: bool = True, return_figure: bool = False, df: pandas.core.frame.DataFrame = 'auto', meta: pyreadstat._readstat_parser.metadata_container = 'auto')
-
Creates a piechart or donutchart, depends on hole size parameter
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', …]
breaks
:list
, optional- A list of breaks. ~ ['alter_break', 'sex_break']. Defaults to None.
break_labels_rename
:dict[str, str]
, optional- Renames the breaks. ~ {'old_name': 'new_name'}. Defaults to None.
legend_labels_rename
:dict[str, str]
, optional- Renames the labels of the different legend levels. ~ {'old_name', 'new_name'}. Defaults to None.
legend_position
:str
, optional- Sets the position of the legend. ~ 'bottom'. Defaults to 'right'. legend_title_custom_text (str, optional): Creates a custom legend title, if title is desired. Defaults to 'auto'.
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'.
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.
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.
return_data
:bool
, optional- Returns the data frame, that is used to construct the graph, so it can be viewed. The data frame will be printed out if the parameter is True. This doesn't affect the graph in any way. Defaults to False.
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_color
:int
, optional- Sets threshold for black or white label color. Use 0 for all black labels and 255 for all white. Use numbers between for a mix. Defaults to 999.
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.
weight
:str
, optional- Turns weight on if weight variable name is added. ~ "gewicht". Defaults to 'auto'.
order_by
:dict
, optional- A dictionary. Orders the plot by any variable in the x data frame. ~ {'mean': 'asc'} / {1: 'desc'}. Defaults to None.
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 ''.
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 ''.
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 ''.
value_labels_size
:float
, optional- Sets the size of value labels. Defaults to 999.
legend_labels_size
:float
, optional- Sets the size of legend. Defaults to 12.
hole_size
:float
, optional- defines the hole size in a donut chart. Defaults to 0.4.
show_legend
:bool
, optional- Turns legend on and off. ~ False. Defaults to True. show_legend_title (bool, optional): Toggles legend title. ~ True / False. Defaults to None, which means automatic.
show_count
:bool
, optional- Turns counts in variable labels on and off. ~ True. Defaults to False.
show_decimals
:bool
, optional- rounds the decimals of the labels to 1 if set to true. Defaults to False.
select_variable_levels
:list[int]
, optional- A list variable levels used to select and order variables. ~ [2, 1, 99999997]. 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.
save_figure
:dict
, optional- Turns figure export on and off. Defaults to True.
return_figure
:bool
, optional- Turns figure return on and off. Defaults to False.
df
:pd.DataFrame
, optional- The current data file ~ usually df. Defaults to 'auto'.
meta
:pyreadstat._readstat_parser.metadata_container
, optional- The current meta data file ~ usually meta. Defaults to 'auto'.
Returns
Optional[tuple]
- returns df and meta objects if return_data is True
def create_stacked_barchart(info: dict, variables: list, breaks: list = None, break_labels_rename: dict[str, str] = None, left_labels_rename: dict[str, str] = None, legend_labels_rename: dict[str, str] = None, left_labels_wrap: int = 50, left_labels_width: int = 999, show_mean: bool = False, title_custom_text: str = 'auto', subtitle_custom_text: str = 'auto', tag_custom_text: str = 'auto', title_position: int = 1, subtitle_position: int = 2, tag_position: int = 3, return_data: bool = False, color_theme: str = 'auto', color_type: str = 'diverging', color_direction: str = 'forward', color_custom: list[str] = None, value_labels_color: int = 999, value_labels_show_min: float = 0.8, weight: str = 'auto', order_by: dict = None, title_remove_before: str = '', title_remove_after: str = '', 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 = '', value_labels_add_after: str = '', bar_width: float = 999, break_distance: float = 999, label_size: float = 16, value_labels_size: float = 16, legend_labels_size: float = 14, show_legend: bool = True, show_total: bool = True, show_count: bool = False, show_index: bool = False, mean_name: str = 'MW', mean_transform: function = <function <lambda>>, mean_custom: list[str] = None, select_variable_levels: list[int] = None, select_variables: list[int] = None, select_min_count: int = 0, special_variables: list[int] = [96, 97, 98, 99999996, 99999997, 99999998], standard_arguments: dict = None, save_figure: bool = True, return_figure: bool = False, df: pandas.core.frame.DataFrame = 'auto', meta: pyreadstat._readstat_parser.metadata_container = 'auto')
-
Creates a stacked barchart
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
df
:pd.DataFrame
- The current data file ~ usually df
meta
:pyreadstat._readstat_parser.metadata_container
- The current meta data file ~ usually meta
variables
:list[str]
- A list of variables. If multiple are added, function doesn't accept any breaks. ~ ['AW2'] / ['AW1_1', 'AW1_2', …]
breaks
:list[str]
, optional- A list of breaks. ~ ['alter_break', 'sex_break']. Defaults to [].
break_labels_rename
:dict[str, str]
, optional- Renames the breaks. ~ {'old_name': 'new_name'}. Defaults to {}.
left_labels_rename
:dict[str, str]
, optional- Renames the labels of the different break levels. ~ {'old_name', 'new_name'}. Defaults to {}.
legend_labels_rename
:dict[str, str]
, optional- Renames the labels of the variable in legend. ~ {'old_name', 'new_name'}. Defaults to {}.
left_labels_wrap
:int
, optional- Wraps the variable labels. Defaults to 50.
left_labels_width
:int
, optional- Changes the space allocated to the y-label. Defaults to 999 (which means automatic).
show_mean
:bool
, optional- Turns the mean annotations on. ~ True. Defaults to False.
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".
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.
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.
return_data
:bool
, optional- Returns the data frame, that is used to construct the graph, so it can be viewed. The data frame will be printed out if the parameter is True. This doesn't affect the graph in any way. Defaults to False.
color_theme
:str
, optional- Sets color theme for graph. ~ 'test', 'gfs'. Defaults to 'standard'.
color_type
:str
, optional- Sets color value type. ~ 'groups', 'single_hue'. Defaults to 'diverging'.
color_direction
:str
, optional- Sets direction of color pattern. ~ 'backward'. Defaults to 'forward'.
value_labels_color
:int
, optional- Sets threshold for black or white label color. Use 0 for all black labels and 255 for all white. Use numbers between for a mix. Defaults to 130.
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.8.
weight
:str
, optional- Turns weight on if weight variable name is added. ~ "gewicht". Defaults to ''.
order_by
:dict
, optional- A dictionary. Orders the plot by any variable in the x data frame. ~ {'mean': 'asc'} / {1: 'desc'}. 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 ''.
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 ''.
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 that. Defaults to ''.
value_labels_add_after
:str
, optional- Adds text to value labels. Is useful to add a % sign for example. Defaults to ''.
bar_width
:float
, optional- Sets the width of the bars. Defaults to 0.8.
break_distance
:float
, optional- Sets the distance between the breaks. Defaults to 0.5.
label_size
:float
, optional- Sets the size of labels. Defaults to 16.
value_labels_size
:float
, optional- Sets the size of value labels. Defaults to 16.
legend_labels_size
:float
, optional- Sets the size of legend. Defaults to 12.
show_legend
:bool
, optional- Turns legend on and off. ~ False. Defaults to True.
show_total
:bool
, optional- Turns total bar on and off. ~ False. Defaults to True.
show_count
:bool
, optional- Turns counts in variable labels on and off. ~ True. Defaults to False.
show_index
:bool
, optional- Turns index in variable labels on and off. ~ True. Defaults to False.
mean_name
:str
, optional- Changes name written above the mean values. Defaults to 'MW'.
mean_transform
:LambdaType
, optional- Changes the size of the mean values with a transformation. lambda n: -n + 2 changes n to the negative value of n and adds 2. Defaults to lambda n: n.
select_variable_levels
:list[int]
, optional- A list variable levels used to select and order variables. ~ [2, 1, 99999997]. Defaults to [].
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.
save_figure
:bool
, optional- Turns figure export on and off. ~ False. Defaults to True.
return_figure
:bool
, optional- Turns figure return on and off. ~ False. Defaults to True.
Returns
_type_
- If return_data is on it returns the plot data, so it can be viewed.
def create_wordcloud(info: dict, variables: list[str], language_column: str, translate_to: int = 564, transform: str = 'no', font_name: str = 'arial', title_custom_text: str = 'auto', subtitle_custom_text: str = 'auto', tag_custom_text: str = 'auto', title_position: int = 1, subtitle_position: int = 2, tag_position: int = 3, return_data: bool = False, color_theme: str = 'auto', color_custom: str = 'auto', title_remove_before: str = '', title_remove_after: str = '', tag_add_before: str = '', tag_add_after: str = '', subtitle_add_before: str = '', subtitle_add_after: str = '', remove_words: Optional[None] = None, min_font_size: int = 0, min_count: int = 1, max_words: int = 200, translation_file_path: str = None, standard_arguments: dict = None, save_figure: bool = True, df: pandas.core.frame.DataFrame = 'auto', meta: pyreadstat._readstat_parser.metadata_container = 'auto') ‑> Optional[tuple]
-
generates a wordcloud plot, also translates open answers into a language
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', …]
language_column
:str
- The column that contains the language information.
translate_to
:int
, optional- language code to translate to, matches nebu language code. Defaults to 564.
transform
:str
, optional- How to transform the words. ~ 'upper', 'lower', 'no'. Defaults to 'no'.
font_name
:str
, optional- font to use. Defaults to 'arial'.
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'.
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.
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.
return_data
:bool
, optional- Returns the data frame, that is used to construct the graph, so it can be viewed. The data frame will be printed out if the parameter is True. This doesn't affect the graph in any way. Defaults to False.
color_theme
:str
, optional- Sets color theme for graph. ~ 'test', 'gfs'. Defaults to 'auto'.
color_custom
:str
, optional- Uses custom colors ~ ['#131366', '#454578']. Defaults to None.
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 ''.
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 ''.
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 ''.
remove_words
:Optional[list[str]]
, optional- Words to remove in the wordcloud. Defaults to None.
min_font_size
:int
, optional- minimal font size to be displayed. Defaults to 0.
min_count
:int
, optional- minimum count of word frequency to be displayed. Defaults to 1.
max_words
:int
, optional- max word count to be displayed. Defaults to 200.
translation_file_path
:str
, optional- path to file to already translated texts. Defaults to None.
standard_arguments
:dict
, optional- Adds some standard arguments that normally don't need to be changed. Defaults to None.
save_figure
:bool
, optional- Turns figure export on and off. Defaults to True.
df
:pd.DataFrame
, optional- The current data file ~ usually df. Defaults to 'auto'.
meta
:pyreadstat._readstat_parser.metadata_container
, optional- The current meta data file ~ usually meta. Defaults to 'auto'.
Raises
errors
- description
Returns
Optional[tuple]
- description
def get_answer_list(df, column: str) ‑> list
-
Get a list of answers from a column in a data frame.
Args
df
:pd.DataFrame
- The data frame.
column
:str
- The column name.
Returns
list
- A list of answers.
def get_word_frequencies(german_answers: list[str], transform: str, remove_words: Optional[None] = None, min_count: int = 1) ‑> dict
-
Get word frequencies from a list of german answers.
Args
german_answers
:list
- A list of german answers.
transform
:str
- How to transform the words. ~ 'upper', 'lower', 'no'
remove_words
:list
, optional- A list of words to remove. Defaults to None.
min_count
:int
, optional- The minimum count of a word to be included. Defaults to 1.
def print_word_frequencies(df, column, min_count)
-
Prints word frequencies for a given column.
Args
df
:pd.DataFrame
- The data frame.
column
:str
- The column name.
min_count
:int
- The minimum count of a word to be included.
def save_presentation(info: dict) ‑> None
-
Saves the presentation
Args
info
:dict
- The presentation object
def start_presentation(name: str, df: pandas.core.frame.DataFrame, meta: pyreadstat._readstat_parser.metadata_container, output_path: str = './output/', template_path: str = './templates/', template_custom: str = 'auto', color_theme: str = 'standard', language: str = 'de', value_labels_color: int = 130, weight: str = '', line_width_linechart: int = 4, line_marker_size_linechart: int = 8, bar_width_barchart: float = 0.7, bar_width_stacked_barchart: float = 0.8, bar_gap_barchart: float = 0.15, break_distance: float = 0.5, count_name: str = 'N', logo_side: str = 'right', project_leader: str = None, project_people: list[str] = None, export_svg: bool = False, standard_arguments: dict = None, show_page_number: bool = False, use_wide_screen: bool = False) ‑> dict
-
Creates a new presentation
Args
name
:str
- Changes the name of the presentation
df
:pd.DataFrame
- The current data file ~ usually df
meta
:pyreadstat._readstat_parser.metadata_container
- The current meta data file ~ usually meta
output_path
:str
, optional- Changes path and name of the output files. Defaults to "./output/".
template_path
:str
, optional- Sets path of pptx-template file. Defaults to './templates/'.
template_custom
:str
, optional- Choose a custom template. Defaults to 'auto'.
color_theme
:str
, optional- Sets color theme for graph. ~ 'test', 'gfs'. Defaults to 'standard'.
language
:str
, optional- Sets language for texts like subtitle and tag. ~ 'fr', 'en', 'it'. Defaults to 'de'.
value_labels_color
:int
, optional- Sets threshold for black or white label color. Use 0 for all black labels and 255 for all white. Use numbers between for a mix. Defaults to 130.
weight
:str
, optional- Turns weight on if weight variable name is added. ~ "gewicht". Defaults to ''.
bar_width_barchart
:float
, optional- Sets the width of the barchart bars. Defaults to 0.7.
bar_width_stacked_barchart
:float
, optional- Sets the width of the stacked barchart bars. Defaults to 0.8.
bar_gap_barchart
:float
, optional- Sets the gap between the bars within a group. Defaults to 0.15.
break_distance
:float
, optional- Sets the distance between the breaks. Defaults to 0.5.
count_name
:str
, optional- Changes the name of the count. ~ if "K" is passed in, counts look like "K = 42". Defaults to 'N'.
logo_side
:str
, optional- Changes the position of the logo on the presentation slides. ~ 'left'. Defaults to 'right'.
project_leader
:str
- The first name of the project leader. Can be "Andreas" for example. Defaults to None.
project_people
:list[str]
, optional- A list of the names of the people working on the project. For example ["Andreas", "Nadia"]. Defaults to None.
export_svg
:bool
, optional- Exports graphs as .svg files if True. Defaults to False.
standard_arguments
:dict
, optional- Adds some standard arguments that normally don't need to be changed. Defaults to {}.
show_page_number
:bool
, optional- Turns page number on PowerPoint on and off ~ True. Defaults to False.
use_wide_screen
:bool
, optional- Turns slides into 16:9 widescreen format ~ True. Defaults to False.
Returns
dict
- Returns a dictionary with presentation info, the presentation object and some info about the plot theme.
def translate_column(info: dict, open_question_column: str, language_column: str, translate_to: int, df: pandas.core.frame.DataFrame, translation_file_path: str) ‑> None
-
Translates a column to a different language. Saves the translations to a JSON-file.
Args
info
:dict
- A dictionary with info about the presentation.
open_question_column
:str
- The column that should be translated.
language_column
:str
- The column that contains the language information.
translate_to
:int
- The language code to translate to.
df
:pd.DataFrame
- The data frame that contains the columns.
translation_file_path
:str
- file path to take the saved translations from.
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