File size: 1,390 Bytes
ba96324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import plotly.express as px

def plot_to_html(df: pd.DataFrame, x: str, y: str, labels: dict, color_based_on: str, y_label: str = "", x_label: str = "", title: str = "", filepath: str = "plot") -> str:
    # Create a bar plot with a greyscale color theme
    fig = px.bar(
        df,
        x=x,
        y=y,
        title=title,
        labels=labels,
        color=color_based_on,
        color_continuous_scale=px.colors.sequential.Jet
    )

    # Update layout for appearance
    fig.update_layout(
        xaxis_title=x_label,
        yaxis_title=y_label,  # Adding the y_label explicitly
        template="plotly_white",  # Light background for greyscale contrast
        title_x=0.5,  # Center the title
    )

    fig.write_image(f"{filepath}.png")
    return f"{filepath}.png"

def plot_pie_chart(df: pd.DataFrame, names: str, values: str, labels: dict, title: str = "", filepath: str = "plot") -> str:
    # Create a pie chart
    fig = px.pie(
        df,
        names=names,
        values=values,
        title=title,
        labels=labels,
        color_discrete_sequence=px.colors.sequential.Jet
    )

    # Update layout for appearance
    fig.update_layout(
        template="plotly_white",  # Light background for greyscale contrast
        title_x=0.5  # Center the title
    )

    fig.write_image(f"{filepath}.png")
    return f"{filepath}.png"