1

Say I have certain data. My requirement is that, I should be able to select the type of graphs I want. For example, if I have an array of 1s and 0s, I want to be able to select whether I the no. of 1s and 0s are displayed as a bar graph, or as a percentage in a pie chart. Is there some library that has this capability? If not, is there some way I can go about doing this?

2
  • 1
    Hello @user_9, I think that the question is really very broad. Do you have a language of preference? Are you going to display these data in a website, or as an app?
    – Gabriele
    Commented May 26, 2021 at 11:57
  • Hello @user_9 if my answer helped you could you please give me the bounty Commented May 31, 2021 at 9:03

1 Answer 1

3
+50

I think I have the answer you are looking for. I had same project for my college I used plotly library in python which will allow you to make the thing you want.

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()

here is the example code

and it will work as shown in this link.

this is the output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.