File size: 2,544 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
import pandas as pd
import plotly.graph_objects as go


def generate_two_features_parcats_plot(dataFrame: pd.DataFrame, n_landscapes_column: str, n_landscapes_label: str, 
                          family_column: str, family_label: str, title: str, color_dict: dict[str, str], 
                          height: float = 1600, width: float = 2800) -> go.Figure:
    
    '''
    Returns a parallel categories plot of plants under one landscape, regarding their growth cycle and two 
    binary features (e.g. edibility, toxicity).

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

    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 1600
    width: Width of the plot; default is 2800
    ------------------------------------------------------------------------------------------------------------
    '''
    
    # Create dimensions
    n_present_landscapes_dim = go.parcats.Dimension(
        values = dataFrame[n_landscapes_column],
        categoryorder = "category ascending", label = n_landscapes_label)

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

    # Create Parcats trace with assigned colors
    parcats_trace = go.Parcats(
        dimensions = [n_present_landscapes_dim, family_dim],
        line = {"color" : dataFrame[family_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