Plot 从下拉列表中选择图形类型

Plot 从下拉列表中选择图形类型,plot,graph,data-visualization,Plot,Graph,Data Visualization,假设我有一些数据。我的要求是,我应该能够选择我想要的图形类型。例如,如果我有一个1和0的数组,我希望能够选择是将1和0的数量显示为条形图,还是在饼图中显示为百分比。是否有一些库具有此功能?如果没有,我有什么办法可以这样做吗?我想我已经找到了你想要的答案。我在大学里也做过同样的项目,我使用了python中的plotly库,它可以让你制作你想要的东西 import plotly.graph_objects as go import pandas as pd # load dataset df =

假设我有一些数据。我的要求是,我应该能够选择我想要的图形类型。例如,如果我有一个1和0的数组,我希望能够选择是将1和0的数量显示为条形图,还是在饼图中显示为百分比。是否有一些库具有此功能?如果没有,我有什么办法可以这样做吗?

我想我已经找到了你想要的答案。我在大学里也做过同样的项目,我使用了python中的plotly库,它可以让你制作你想要的东西

import plotly.graph_objects as go

import pandas as pd

# load dataset
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/volcano.csv")

# create figure
fig = go.Figure()

# Add surface trace
fig.add_trace(go.Surface(z=df.values.tolist(), colorscale="Viridis"))

# Update plot sizing
fig.update_layout(
    width=800,
    height=900,
    autosize=False,
    margin=dict(t=0, b=0, l=0, r=0),
    template="plotly_white",
)

# Update 3D scene options
fig.update_scenes(
    aspectratio=dict(x=1, y=1, z=0.7),
    aspectmode="manual"
)

# Add dropdown
fig.update_layout(
    updatemenus=[
        dict(
            buttons=list([
                dict(
                    args=["type", "surface"],
                    label="3D Surface",
                    method="restyle"
                ),
                dict(
                    args=["type", "heatmap"],
                    label="Heatmap",
                    method="restyle"
                )
            ]),
            direction="down",
            pad={"r": 10, "t": 10},
            showactive=True,
            x=0.1,
            xanchor="left",
            y=1.1,
            yanchor="top"
        ),
    ]
)

# Add annotation
fig.update_layout(
    annotations=[
        dict(text="Trace type:", showarrow=False,
        x=0, y=1.085, yref="paper", align="left")
    ]
)

fig.show()
下面是示例代码

它将按此链接所示工作


我想我找到了你想要的答案。我在大学里也做过同样的项目,我使用了python中的plotly库,它可以让你制作你想要的东西

import plotly.graph_objects as go

import pandas as pd

# load dataset
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/volcano.csv")

# create figure
fig = go.Figure()

# Add surface trace
fig.add_trace(go.Surface(z=df.values.tolist(), colorscale="Viridis"))

# Update plot sizing
fig.update_layout(
    width=800,
    height=900,
    autosize=False,
    margin=dict(t=0, b=0, l=0, r=0),
    template="plotly_white",
)

# Update 3D scene options
fig.update_scenes(
    aspectratio=dict(x=1, y=1, z=0.7),
    aspectmode="manual"
)

# Add dropdown
fig.update_layout(
    updatemenus=[
        dict(
            buttons=list([
                dict(
                    args=["type", "surface"],
                    label="3D Surface",
                    method="restyle"
                ),
                dict(
                    args=["type", "heatmap"],
                    label="Heatmap",
                    method="restyle"
                )
            ]),
            direction="down",
            pad={"r": 10, "t": 10},
            showactive=True,
            x=0.1,
            xanchor="left",
            y=1.1,
            yanchor="top"
        ),
    ]
)

# Add annotation
fig.update_layout(
    annotations=[
        dict(text="Trace type:", showarrow=False,
        x=0, y=1.085, yref="paper", align="left")
    ]
)

fig.show()
下面是示例代码

它将按此链接所示工作


Hello@user\u 9,我认为这个问题真的很广泛。你有喜欢的语言吗?你打算把这些数据显示在网站上,还是作为一个应用程序?Hello@user_9如果我的回答对你有帮助的话,你能给我赏金吗Hello@user_9,我认为这个问题真的很广泛。你有喜欢的语言吗?你打算在网站上显示这些数据,还是作为应用程序显示?你好@user_9如果我的回答有帮助,你能给我奖金吗