Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to use plotly in python

import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
fig.show()
Comment

plotly create plot

# If you prefer to run the code online instead of on your computer click:
# https://github.com/Coding-with-Adam/Dash-by-Plotly#execute-code-in-browser

from dash import Dash, dcc, Output, Input  # pip install dash
import dash_bootstrap_components as dbc    # pip install dash-bootstrap-components
import plotly.express as px # used for the graphs

# incorporate data into app
df = px.data.medals_long()

# Build your components
app = Dash(__name__, external_stylesheets=[dbc.themes.SOLAR])
mytitle = dcc.Markdown(children='# Amount of medals per country')
mygraph = dcc.Graph(figure={})
dropdown = dcc.Dropdown(options=['Bar Plot', 'Scatter Plot'],
                        value='Bar Plot',  # initial value displayed when page first loads
                        clearable=False)

# Customize your own Layout
app.layout = dbc.Container([mytitle, mygraph, dropdown])

# Callback allows components to interact
@app.callback(
    Output(mygraph, component_property='figure'),
    Input(dropdown, component_property='value')
)
def update_graph(dropdown_input):  # function arguments come from the component property of the Input
    if dropdown_input == 'Bar Plot':
        fig = px.bar(data_frame=df, x="nation", y="count", color="medal")

    elif dropdown_input == 'Scatter Plot':
        fig = px.scatter(data_frame=df, x="count", y="nation", color="medal",
                         symbol="medal")

    return fig  # returned objects are assigned to the component property of the Output


# Run app
if __name__=='__main__':
    app.run_server(port=8053, debug=True)
Comment

PREVIOUS NEXT
Code Example
Python :: python prevent print output 
Python :: i = 1 while i <= 100: print(i * *") i = i + 1 
Python :: create an array filled with 0 
Python :: aws django bucket setting 
Python :: ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters 
Python :: us states and capitals dictionary 
Python :: mistborn series 
Python :: python convert datetime to float 
Python :: python - extract min and max values per each column name 
Python :: how to omit days pandas datetime 
Python :: convert all columns to float pandas 
Python :: maximun row and columns in python 
Python :: list addition within a list comprehension 
Python :: python check if string contains number 
Python :: request.args.get check if defined 
Python :: flask run development mode 
Python :: remove list from list python 
Python :: how to use return python 
Python :: how to parse http request in python 
Python :: 4D Array To DF 
Python :: como poner estado a un bot en discord 
Python :: import excel 
Python :: python vars keyword 
Python :: Python NumPy stack Function Example with 2d array 
Python :: relative frequency histogram python 
Python :: Maximize Difference 
Python :: # Python string capitalization 
Python :: python language server 
Python :: tkinter convert Entry to string 
Python :: parse xml in python 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =