File size: 3,019 Bytes
573a558
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import plotly.graph_objects as go


def generate_three_features_parcats_plot(dataFrame: pd.DataFrame, true_column: str, true_column_label: str, 
                                       n_landscapes_column: str, n_landscapes_label: str, family_column: str, 
                                       family_label: str, title: str, color_dict: dict[int, str], 
                                       height: float = 1200, width: float = 2400) -> go.Figure:
    
    '''
    Returns a parallel categories plots of a plants' subset (e.g. bordering/transition plants) 
    regarding the number of landscapes it is present and the plant families which consist it.

    Parameters:
    ------------------------------------------------------------------------------------------------------------
    dataFrame: Name of a pandas DataFrame(two-dimensional, size-mutable, potentially heterogeneous tabular data)

    true_column: Name of the dataFrame's column, of which the True values will be explored 
    true_column_label: Label for the true_column dimension

    n_landscapes_column: Name of the dataFrame's column referring to the number of landscapes, where the 
    plants are present
    n_landscapes_label: Label for the number of landscapes dimension

    family_column: Name of the dataFrame's column referring to the plant families
    family_label: Label for the plant families dimension

    title: Title of the parallel categories plot
    color_dict: Custom dictionary for the feature, containing the colors for each landscape
      
    height: Height of the plot; default is 1200
    width: Width of the plot; default is 2400
    ------------------------------------------------------------------------------------------------------------
    '''

    # Filter the data
    df2 = dataFrame[dataFrame[true_column] == True]

    # Create dimensions
    n_present_landscapes_dim = go.parcats.Dimension(
        values = df2[n_landscapes_column],
        categoryorder = "category ascending", label = n_landscapes_label)

    bordering_dim = go.parcats.Dimension(
        values = df2[true_column], label = true_column_label)

    family_dim = go.parcats.Dimension(
        values = df2[family_column], label = family_label)

    # Create Parcats trace with assigned colors
    parcats_trace = go.Parcats(
        dimensions = [bordering_dim, n_present_landscapes_dim, family_dim],
        line = {"color" : df2[n_landscapes_column].map(color_dict)},
        hoveron = "category", hoverinfo = "count+probability",
        labelfont = {"size" : 20, "family" : "Times"},
        tickfont = {"size" : 18, "family" : "Times"},
        arrangement = "freeform")

    # Create layout
    layout = go.Layout(
        height = height, 
        width = width, 
        title = dict(text = title, font = dict(family = "Times New Roman", size = 28)),  
        margin = dict(l = 100, r = 150, b = 100, t = 100))

    # Create figure
    fig = go.Figure(data = [parcats_trace], layout = layout)

    return fig