Open In App

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 library. 

Simple Slider Control

In plotly, a slider is a Tkinter object with which a user can set the values by moving an indicator. A slider can be vertically and horizontally arranged. In plotly, the slider can be formed by using the Scale method(). 



Example 1:




import plotly.graph_objects as px
import plotly.express as go
import numpy as np
  
df = go.data.tips()
  
x = df['total_bill']
y = df['day']
  
plot = px.Figure(data=[px.Scatter(
    x=x,
    y=y,
    mode='lines',)
])
  
plot.update_layout(
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     step="day",
                     stepmode="backward"),
            ])
        ),
        rangeslider=dict(
            visible=True
        ),
    )
)
  
plot.show()

Output:



Example 2:




import plotly.express as px
  
df = px.data.tips()
  
fig = px.scatter(df, x="total_bill", y="tip"
                 animation_frame="day",
                 color="sex",)
  
fig["layout"].pop("updatemenus")
fig.show()

Output:
 

 


Article Tags :