File size: 562 Bytes
9ad1c41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import plotly.express as px

def create_plot(df, chart_type, x_col, y_col):
    if chart_type == "Bar Chart":
        fig = px.bar(df, x=x_col, y=y_col)
    elif chart_type == "Line Chart":
        fig = px.line(df, x=x_col, y=y_col)
    elif chart_type == "Scatter Plot":
        fig = px.scatter(df, x=x_col, y=y_col)
    elif chart_type == "Pie Chart":
        fig = px.pie(df, names=x_col, values=y_col)
    elif chart_type == "Box Plot":
        fig = px.box(df, x=x_col, y=y_col)
    else:
        raise ValueError("Invalid chart type")
    return fig