Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Pandas
  • Seaborn
  • Matplotlib
  • Altair
  • Bokeh
  • Data Analysis
  • R
  • Machine Learning Math
  • Machin Learning
  • Deep Learning
  • Deep Learning Projects
  • NLP
  • Computer vision
  • Data science
  • Deep learning interview question
  • Machin Learning Interview question
Open In App
Next Article:
How to make Dropdown Menus in Plotly?
Next article icon

How to make Dropdown Menus in Plotly?

Last Updated : 22 Sep, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library. 

Creating Dropdown Menus

A drop-down menu is a part of the menu-button which is displayed on a screen all the time. Every menu button is associated with a Menu widget that can display the choices for that menu button when clicked on it. In plotly, there are 4 possible methods to modify the charts by using updatemenu method.

  • restyle: modify data or data attributes
  • relayout: modify layout attributes
  • update: modify data and layout attributes
  • animate: start or pause an animation

Example 1: Restyle Dropdown

The data and data attributes of the graph can be modified.

Python3
import plotly.graph_objects as px import numpy as np   # creating random data through randomint # function of numpy.random np.random.seed(42)  random_x = np.random.randint(1, 101, 100) random_y = np.random.randint(1, 101, 100)  plot = px.Figure(data=[px.Scatter(     x=random_x,     y=random_y,     mode='markers',) ])  # Add dropdown plot.update_layout(     updatemenus=[         dict(             buttons=list([                 dict(                     args=["type", "scatter"],                     label="Scatter Plot",                     method="restyle"                 ),                 dict(                     args=["type", "bar"],                     label="Bar Chart",                     method="restyle"                 )             ]),             direction="down",         ),     ] )  plot.show() 

Output:

Example 2:

Python3
import plotly.graph_objects as px import numpy   # creating random data through randomint # function of numpy.random np.random.seed(42)  random_x = np.random.randint(1, 101, 100) random_y = np.random.randint(1, 101, 100)  x = ['A', 'B', 'C', 'D']  plot = px.Figure(data=[go.Bar(     name='Data 1',     x=x,     y=[100, 200, 500, 673] ),     go.Bar(     name='Data 2',     x=x,     y=[56, 123, 982, 213] ) ])   # Add dropdown plot.update_layout(     updatemenus=[         dict(             active=0,             buttons=list([                 dict(label="Both",                      method="update",                      args=[{"visible": [True, True]},                            {"title": "Both"}]),                 dict(label="Data 1",                      method="update",                      args=[{"visible": [True, False]},                            {"title": "Data 1",                             }]),                 dict(label="Data 2",                      method="update",                      args=[{"visible": [False, True]},                            {"title": "Data 2",                             }]),             ]),         )     ])  plot.show() 

Output:
 


 


Next Article
How to make Dropdown Menus in Plotly?

N

nishantsundriyal98
Improve
Article Tags :
  • Python
  • Python-Plotly
Practice Tags :
  • python

Similar Reads

    How to make Custom Buttons in Plotly?
    A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization libra
    2 min read
    Dropdown Menus in Tkinter
    Dropdown menus are a fundamental part of graphical user interfaces (GUIs), allowing users to select from a predefined list of options in an efficient and organized manner. They enhance user experience by minimizing input errors, saving screen space and providing a structured way to interact with app
    4 min read
    How to make sliders in Plotly?
    A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization libra
    1 min read
    Python | Dropdown list in kivy
    Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications. ???????? Kivy Tutorial - Learn Kivy with Examples. Dropdown list
    3 min read
    How to make Range Slider and Selector in Plotly?
    A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization libra
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences