从下拉列表中选择图形类型
Choosing graph types from dropdown
说我有一定的数据。我的要求是,我应该能够 select 我想要的图表类型。例如,如果我有一个 1 和 0 的数组,我希望能够 select 无论我是否。 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()
这里是示例代码
它会如此工作 link。
说我有一定的数据。我的要求是,我应该能够 select 我想要的图表类型。例如,如果我有一个 1 和 0 的数组,我希望能够 select 无论我是否。 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()
这里是示例代码
它会如此工作 link。